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

using namespace std;

typedef long long ll;
#define int ll

inline ll toInt(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 24;

inline ll f(ll lb, ll ub, int idx){
    lb--;

    return idx * ((ub - lb) - (ub / 3 - lb / 3) - (ub / 5 - lb / 5) + (ub / 15 - lb / 15)) + 4 * ((ub / 3 - lb / 3) + (ub / 5 - lb / 5));
}

signed main(void){
    for(ll s; cin >> s;){
        ll len = 0;
        int idx;
        ll lb, ub;
        ll min_val = 0;

        range(i, 1, 18){
            lb = min_val;
            ub = pow(10, i) - 1;

            if(s - f(lb + 1, ub, i) > len) len += f(lb + 1, ub, i);
            else{
                idx = i;
                break;
            }

            min_val = ub;
        }

        lb = min_val + 1, ub = lb * 10 - 1;
        ll mid, len_cur;


        while(lb < ub){
            mid = (lb + ub) / 2;

            len_cur = len + f(min_val + 1, mid, idx);

            if(len_cur < s) lb = mid + 1;
            else if(len_cur > s) ub = mid - 1;
            else lb = mid, ub = mid;
        }

        ll t = lb;
        len_cur = len + f(min_val + 1, lb, idx);

        if(!(lb % 3)) len_cur -= 4;
        if(!(lb % 5)) len_cur -= 4;
        if(lb % 3 && lb % 5) len_cur -= idx;

        ll w = s - len_cur;

        ll cur = lb;

        string res;

        while(res.size() <= 20 + w){
            if(cur % 3 == 0) res += "Fizz";
            if(cur % 5 == 0) res += "Buzz";
            if(cur % 3 && cur % 5) res += toString(cur);

            cur++;
        }
        rep(i, 20){
            cout << res[i + w - 1];
        }
        cout << endl;
    }

	return 0;
}

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

int n, m;
vector<vector<int>> g;
vector<bool> vis; // 探索のときの目印が必要

void dfs(int i) {
	if(vis[i]) return;
	vis[i] = true;
	// for(int j=0;j<g[i].size();j++){
	// 	dfs(g[i][j]);
	// }
	for(auto j : g[i]){
		dfs(j);
	}
}


int main() {
	cin >> n >> m;
	vector<int> a(m), b(m);
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	int cnt = 0;
	for(int i=0;i<m;i++){
		g.clear();  // 空にする
		g.resize(n); // サイズをnにする
		for(int j=0;j<m;j++){
			if(j==i) continue;
			g[a[j]].push_back(b[j]);
			g[b[j]].push_back(a[j]);
		}
		vis.clear();
		vis.resize(n, false);
		dfs(a[i]);
		if(vis[b[i]]==false) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int n;cin>>n;
    int i;
    int a[n],b[n],c[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    for (i=0;i<n;i++)
        cin>>b[i];
    for (i=0;i<n;i++)
        cin>>c[i];
    sort(a,a+n);
    sort(c,c+n);
    ll ans=0;
    for (i=0;i<n;i++) {
        ll d=lower_bound(a,a+n,b[i])-a;
        ll e=c+n-upper_bound(c,c+n,b[i]);
        ans+=d*e;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

const int MOD = 1e9+7; //998244353;
inline int add(int a, int b){ return (a+b)%MOD; }
inline int sub(int a, int b){ return ((a-b)%MOD + MOD)%MOD; }
inline int mul(int a, int b){ return ((ll)a*b)%MOD; }

vector<int> dp;

int f(int sum){
    if(sum < 0) return 0;
    if(sum==0) return 1;
    if(dp[sum] != -1) return dp[sum];

    dp[sum]=0;
    for(int i = 3; i <= 2000; ++i){
        dp[sum] = add(dp[sum], f(sum-i));
    }
    return dp[sum];
}

void solve(){
    int s;
    cin >> s;

    // dp = fill((s+2)/3+1, s+1, -1);
    dp = vector<int>(s+1, -1);
    // for(int i = 0; i <= s; ++i) cout << f(i) << " ";
    int ans = f(s);
    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(){
	int a,i,j,c;
	int k[1000000]={0};
	k[1]=k[0]=1;//0が素数
	for(i=2;i<1000000;i++){
	       if(k[i]==0){
		       for(j=i+i;j<1000000;j+=i){
			       k[j]=1;
		       }
	       }
	}
	while(scanf("%d",&a)!=EOF){
		c=0;
		for(i=0;i<=a;i++)if(k[i]==0)c++;
		printf("%d\n",c);
	}
	return 0;
}


Measured memory_bytes: 4512
import java.util.Scanner;
import java.lang.Math;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		double area = r * r * Math.PI;
		double len = 2 * r * Math.PI;
		System.out.println(String.format("%.6f" + " " + "%.6f",area,len));
		
	}

}



Measured memory_bytes: 28256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
using namespace std;
typedef long int li;
typedef long long int lli;

const int INF = 0xfffffff;

int main() {
	int a, b;
	cin >> a >> b;
	string s = "No";
	if (a % 2 == 1 && b % 2 == 1) s = "Yes";
	cout << s << endl;
}

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

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int T;

const int mod = 1e9 + 7;
const int N = 1e4 + 10;
const int K = 110;

LL n, d;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n >> d)
    {
        LL x, y;
        int ans = 0;
        for (int i = 1; i <= n; ++i)
        {
            cin >> x >> y;
            if (x * x + y * y <= d * d) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


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

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

	int m = 0;
	map<string, int> mp;
		
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		mp[s]++;
		m = max(m, mp[s]);
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr -> second == m) {
			cout << itr->first << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 25216
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
template <typename T>
void print(T x)
{
	std::cout << x << " ";
}
template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}
int main() {
	int n, Y;
	cin >> n >> Y;
	int x = -1;
	int y = -1;
	int z = -1;
	rep(i, n+1) { //i+j+k=n
		if (10000 * i > Y)break;
		rep(j, n-i+1) {
			if (10000 * i + 5000 * j > Y)break;
			int k = n - i - j;
			if(10000 * i + 5000 * j+1000*k==Y){
				x = i;
				y = j;
				z = k;
				break;
			}
		}
	}
	cout << x << " " << y << " " << z;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int sum = 0;
		for(int i = 1; i<=N; i++) {
			int a = sc.nextInt(), b = sc.nextInt();
			sum += (b-a+1);
		}
		
		System.out.println(sum);
	}

}


Measured memory_bytes: 25300
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 0, b = 0, c, d, n, k = 0, ans = 0;
string s, t;


int main()
{
	cin >> s;
	int o=0, i=0;
	rep(j, sz(s))
	{
		if (s[j] == '0')
			o++;
		else i++;
	}
	cout << 2*min(o, i) << endl;
	

	return 0;
}


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

int main(){
    
    int a,b,x,y;
    cin>>a>>b>>x>>y;
    if(a>b){
        cout<<b*x+(a-b)*y<<endl;
    }else{
        cout<<a*x<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int  search(int,int *,int);
int main(){
  int n,q;
  int s[100001],t[50000];

  scanf("%d",&n);
  int i;
  for (i=0;i<n;i++)
    scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
  int count = 0;
  for(i=0;i<q;i++)
    if(search(n,s,t[i])) count++;
  printf("%d\n",count);
  return 0;
}

int search(int n,int *s,int t){
  s[n] = t;
  int i=0;
  while(s[i]!=t)i++;
  return i!=n;
}
	       

Measured memory_bytes: 648
from collections import defaultdict
n=int(input())

s0=list(input())
answer_dic=defaultdict(int)
for s in s0:
  answer_dic[s]+=1

for i in range(n-1):
  si=list(input())
  tmp_dic=defaultdict(int)
  for s in si:
    tmp_dic[s]+=1
    
  for s in answer_dic:
    answer_dic[s]=min(answer_dic[s],tmp_dic[s])
#print(answer_dic)

answer_list=sorted(list(answer_dic.items()))
#print(answer_list)
answer_str=[]
for c,i in answer_list:
  for ii in range(i):
    answer_str.append(c)
    
print("".join(answer_str))

Measured memory_bytes: 3316
#include <iostream>
#include<vector>
using namespace std;
const int INFTY=1<<28;
const int MAX=1000;

int n,m;//number of vertex,edge
int d[MAX];
vector<pair<int,int>> V[MAX];//to,cost

bool bellman_ford(int s)//false is negative cycle
{
	for(int i=0;i<n;i++)d[i]=INFTY;
	d[s]=0;
	bool update=true;
	pair<int,int>p;
	int c=0;
	
	for(int k=0;update&&k<m;k++)
	{
		update=false;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<V[i].size();j++)
			{
				p=V[i][j];
				if(d[i]!=INFTY&&d[p.first]>d[i]+p.second)
				{
					d[p.first]=d[i]+p.second;
					update=true;
					if(k==m-1)return false;
				}
			}
		}
	}
	
	return true;
}

int main() {
	cin>>n;
	int r;cin>>m>>r;
	int a,b,c;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b>>c;
		V[a].push_back(make_pair(b,c));
	}
	bool flag=bellman_ford(r);
	if(flag)
	{
		for(int i=0;i<n;i++)
		{
			if(d[i]!=INFTY)cout<<d[i]<<endl;
			else cout<<"INF"<<endl;
		}
	}
	else cout<<"NEGATIVE CYCLE"<<endl;
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int  n;
int res[505][505];
void dfs(int start,int to,int index)
{
    if(to-start+1<=1)
        return;
    for(int i=start; i<to; i++)
        for(int j=i+1; j<=to; j++)
        {
            res[i][j]=index;
        }
    int mid=(start+to)>>1;
    dfs(start,mid,index+1),dfs(mid+1,to,index+1);
}
int main()
{
    cin>>n;
    dfs(1,n,1);

    for(int i=1; i<n; i++)
        for(int j=i+1; j<=n; j++)
            cout<<res[i][j]<<" ";
}


Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
  int i,j,k,minj,a[100],n,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  for(i=0;i<n;i++)
    {
      minj=i;
      for(j=i;j<n;j++)
	{
	  if(a[j]<a[minj]) minj=j;
	}
      if(i!=minj)
	{
	  k=a[i];
	  a[i]=a[minj];
	  a[minj]=k;
	  count++;
	}
    }
  for(i=0;i<n-1;i++) printf("%d ",a[i]);
  printf("%d\n%d\n",a[i],count);
  return 0;
}

Measured memory_bytes: 600
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

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

#define INF 1e18
#define MOD 1000000007
//#define DEBUG

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine e(seed);
std::mt19937 rng((int) seed);

int main() {
    ios_base::sync_with_stdio(false);

    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;
    for(int i = l ; i <= r; i++) {
        if(i%d==0) ans++;
    
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
// For actual content check from line 100
#define timeKyaHorhaH 1.0 * clock() / CLOCKS_PER_SEC

#define FORG(i,a,n) for(lld i=(lld)a;a<n?i<(lld)n:(lld)n<i;a<n?++i:--i) //for - general
#define FORZ(i,n) for(lld i=0;i<(lld)n;++i) //for - zero
#define FORGI(i,a,n,inc) for(lld i=(lld)a;a<n?i<(lld)n:(lld)n<i;a<n?i+=inc:i-=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<(lld)n;i+=inc) //for - zero incremental
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define MEM(a,val) memset(a,val,sizeof(a));
 
#define SORTall(m) sort(m.begin(),m.end());
#define all(m) m.begin(),m.end()
 
#define st first
#define nd second
#define pb push_back
#define DEC(x) fixed<<setprecision(x)
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
//DEBUGGER------------------------------------------------------------------------
// #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define DEBUGON
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point

#ifdef DEBUGON
	vector<string> vec_splitter(string s) 
	{
		for(char& c: s) c = c == ',' ?  ' ': c;
		stringstream ss; ss << s;
		vector<string> res;
		for(string z; ss >> z; res.push_back(z));
		return res;
	}

	void debug_out(vector<string> args, int idx) { cerr << endl; }
	template <typename Head, typename... Tail>
		void debug_out(vector<string> args, int idx, Head H, Tail... T) 
		{
			if(idx > 0) cerr << ", ";
			stringstream ss; ss << H;
			cerr << args[idx] << " = " << ss.str();
			debug_out(args, idx + 1, T...);
		}

	#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__);
	#define DEBUG(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__);	
#else
	#define debug(...) 320;
	#define DEBUG(...) 320;
#endif

lld power(lld b, lld e)
{
	assert(e>=0);
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	assert(e>=0);
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

int lognk(lld n, lld k) // logk(n)
{
	assert(n>=0 and k>=0 and k!=1);
	if(n==0)
		return -1;

	return lognk(n/k,k)+1;
}

const long double pi = acos(-1);
#define endl '\n'
#define mod 1000000007

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n,ans=0;
	cin>>n;

	ans=power(n,2)+power(n,3)+n;
	cout<<ans;
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	#ifdef PRIMES
 		sieve();
 	#endif

 	#ifdef CHOOSE
 		nCrModInit();
 	#endif

 	while(t--)
 		swagWaalaFunction();
	
	// cerr<<"\n"<<timeKyaHorhaH; 	
 	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cmath>

using namespace std;
typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M){
  ullong tmp = 1;

  if ( n > 0 ){
    tmp = power(x, n/2, M);
    if ( n%2 == 0 ) tmp = (tmp*tmp)%M;
    else tmp = (((tmp*tmp)%M)*x)%M;
  }
  return tmp;
}

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

  cout << power(m, n, 1000000007) << endl;

  return 0;
}


Measured memory_bytes: 1160
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int N = sc.nextInt();
	  long count = 0;
	  HashMap<String,Long> map = new HashMap<>();
	  for(int i=0; i<N; i++) {
		  String s = sc.next();
		  char[] c = s.toCharArray();
		  Arrays.sort(c);
		  String sorted = new String(c);
		  //文字列が初出のとき
		  if (!map.containsKey(sorted)) {
			   map.put(sorted, (long) 0);
		  } else {
			  long n = map.get(sorted) + 1;
			  count += n;
			  map.put(sorted, n);
		  }
  }
  out.println(count);	  
  }
}

Measured memory_bytes: 53796
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int P = 1e9 + 7 ; 
const int N = 2e5 + 5 ; 
int n, m, fac[N], inv[N], a[N], Ans ; 
int fpow( int x, int k ) {
	int ans = 1, base = x ; 
	while( k ) {
		if( k & 1 ) ans = ans * base % P ; 
		base = base * base % P, k >>= 1 ; 
	} return ans ; 
}
int C( int y, int x ) {
	if( y < x ) return 0 ; 
	return fac[y] * inv[x] % P * inv[y - x] % P ; 
}
signed main()
{
	n = gi(), m = gi() ; inv[0] = fac[0] = 1 ; 
	rep( i, 1, n ) fac[i] = fac[i - 1] * i % P ; 
	rep( i, 1, n ) inv[i] = fpow( fac[i], P - 2 ) ;
	rep( i, 1, n ) a[i] = gi() ; 
	sort( a + 1, a + n + 1 ) ; int x ;
	rep( i, 1, n ) {
		Ans = ( Ans + a[i] * C(i - 1, m - 1) % P ) % P ; 
	}
	rep( i, 1, n ) {
		Ans = ( Ans - a[i] * C(n - i, m - 1) % P + P ) % P ; 
	}
	printf("%I64d\n", Ans ) ;
	return 0 ;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
string s, t;
signed main() {
	int n;
	cin >> n >> s >> t;
	int cnt = n;
	for(int i=n-1;i>=0;i--){
		if (t.substr(0, i + 1) != s.substr(n-(i+1),i+1))cnt--;
		else {
			cout << n * 2 - cnt << endl;
			END;
		}

	}
	cout << n * 2 - cnt << endl;
	END;
}


Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


string solve(){
  int N;
  cin >> N;

  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i];

  int sum = 0;
  REP(i, N) sum += A[i];

  int k = sum/(N*(N+1)/2);
  if(sum%(N*(N+1)/2) != 0) return "NO";

  REP(i, N) B[i] = A[(i+1)%N]-A[i]-k;

  int cnt = 0;
  REP(i, N) while(B[i] < 0){
    B[i] += N;
    cnt++;
  }
  REP(i, N) if(B[i] != 0) return "NO";

  return (cnt == k)? "YES": "NO";
}


signed main() {
  cout << solve() << "\n";

  return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << 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; }
//Write From this Line

int main()
{
	int d;
	cin >> d;
	vector<int> c(26);
	rep(i,26) cin >> c[i]; 
	vector<vector<int>> s(d,vector<int>(26));
	rep(i,d) rep(j,26) cin >> s[i][j];

	vector<int> t(d);
	rep(i,d){
		cin >> t[i];
		t[i]--;//ゲームは0-indexed
	}
	// 最後に試合を行った日を保持する。
	vector<int> last_d(26,0);
	ll ans = 0;
	For(i,1,d+1){
		// i日目に試合t[i-1]を行う。
		int game = t[i-1];
		last_d[game] = i;
		ans += s[i-1][game];
		rep(j,26){
			ans -= c[j] * (i - last_d[j]);
		}
		cout << ans << endl;
	}
}


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

typedef long long ll;
typedef vector<long long> vecll;
typedef vector<string> vecstr;

#define rep0(i, n) for(ll i=0; i<(ll)(n); i++)
#define rep1(i, n) for(ll i=1; i<=(ll)(n); i++)
#define rep(i, a, b) for(ll i=(ll)a; i<=(ll)(b); i++)
#define rep0r(i, n) for(ll i=(ll)(n)-1; i>=0; i--)
#define rep1r(i, n) for(ll i=(ll)(n); i>0; i--)
#define repr(i, a, b) for(ll i=(ll)b; i>=(ll)(a); i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a * b / __gcd(a, b)
#define len(x) x.size()
#define Sort(x) sort(x.begin(), x.end())
#define rSort(x) sort(x.begin(), x.end(), greater<ll>())

const ll mod_const = 1000000007;

ll modpow(ll a, ll n, ll m) {
    ll result = 1;
    while(n > 0) {
        if(n&1) {
            result = result * a % m;
        }

    a = a * a % m;
    n >>= 1;
    }

    return result;
}

ll modinv(ll a, ll n) {
    if(a <= 1) {
        return 1;
    } else {
        return  n - modinv(n%a, n) * (n/a) % n;
    }
}

ll comb(ll n, ll r, ll m = mod_const) {
    vecll fac = {1, 1};
    vecll inv ={1, 1};
    vecll facinv = {1 , 1};

    rep(i, 2, n) {
        fac.push_back(fac[i-1] * i % m);
        inv.push_back(modinv(i, m));
        facinv.push_back(facinv[i-1] * inv[i] % m);
    }

    if (n<r || n<0 || r<0) {
        return 0;
    } else {
        return fac[n] * (facinv[r] * facinv[n-r] % m) % m;
    }
}
void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    bool takawin = false;

    while(true) {
        c -= b;
        if(c <= 0) {
            takawin = true;
            break;
        }

        a -= d;
        if(a <= 0) {
            break;
        }
    }

    if(takawin) {
        cout << "Yes" << endl;
    } else {
        cout <<"No" << endl;
    }

}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const int N = 2e5 + 5;
const ll mod = 1000000007;
using namespace std;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;
//	cin >> tc;

	while (tc--) {
		ll n, m, i;

		cin >> n >> m;
		std::vector<ll> h(n + 1);
		map<ll, ll> mp;


		for (i = 1; i <= n; i++) {
			cin >> h[i];
			mp[i] = 0;
		}


		for (i = 0; i < m; i++) {
			ll a, b;
			cin >> a >> b;

			mp[a] = max(mp[a], h[b]);
			mp[b] = max(mp[b], h[a]);

		}

		ll ans = 0;
		for (i = 1; i <= n; i++) {
			ans += (h[i] > mp[i]);
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 10272
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

int main(void)
{
    int n;
    vector<int> a;
    int x;
    int i, j = 1;

    cin >> n;

    rep(i, 0, n)
    {
        cin >> x;
        a.push_back(x);
    }

    rep(i, 0, n)
    {
        if (a[i] == j)
        {
            j++;
        }
    }

    if (n - j == n - 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n - j + 1 << endl;
    }
}

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

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

    bool is=0;
    while (n) {
        int r=n%10;
        if (r==7) {
            is=1;
        }

        n/=10;
    }

    if (is)     cout << "Yes";
    else        cout << "No";

    return 0;
}


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

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    int X,Y,Z;

    cin >> X>> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;

    return 0;
}

void process(){
    
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	vector<vector<int>> v(10);
	rep(i, n)v[s[i] - '0'].push_back(i);
	int res = 0;
	rep(i, 10)
	{
		if (v[i].size() == 0)continue;
		int pos = v[i][0];
		rep(j, 10)
		{
			auto it = upper_bound(all(v[j]), pos);
			if (it == v[j].end())continue;
			int npos = *it;
			rep(k, 10)
			{
				if (v[k].size() == 0)continue;
				if (v[k].back() <= npos)continue;
				++res;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    VI n = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cis(s);
    
    auto ans = (s == "AAA" || s == "BBB")?"No":"Yes";

    co(ans);
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if len(set([S[0], S[1], S[2]])) == 3:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main() {
    // cout << "Hello World" << endl;
    ll int n;
    cin >> n;

    vector<char> vec;
    while(n > 26) {
        // cout << "now:" << n << endl;
        int num = n%26;
        if(num==0)num=26;
        n = (n-num)/26;
        vec.push_back(num+96);
        // cout << (char)num+96 << " " << n << endl;
    } 
    vec.push_back(n+96);
    reverse(vec.begin(), vec.end());

    for(auto x : vec) cout << x;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
// using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

#define MAX 200000

vector<int> T[MAX];
vector<int> ans(MAX);
int n, q;

void dfs(int u, int p) {
  for (int i = 0; i < T[u].size(); i++) {
    if (T[u][i] == p) continue;
    ans[T[u][i]] += ans[u];
    dfs(T[u][i], u);
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  cin >> n >> q;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0, -1);
  rep(i, n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 24248
import sys
import math

N, K = map(int, sys.stdin.readline().split())

first = float(0)
if N >= K:
    first = float((N - K + 1)/N)

second = float(0)
if N >= K:
    for i in range(1, N+1):
        if i == K:
            break
        temp = float(math.log(K/i, 2))
        second += float(math.pow(1/2, math.ceil(temp)) * (1/N))
else:
    for i in range(1, N+1):
        temp = float(math.log(K/i, 2))
        second += float(math.pow(1/2, math.ceil(temp)) * (1/N))

ans = float(first + second)
print(ans)

Measured memory_bytes: 3064
import string

N = int(input())
S = input()
ans = 0

for i in range(1,N):
  l, r = S[:i], S[i:]
  cnt = 0
  for j in string.ascii_letters:
    if j in l and j in r:
      cnt+=1
  ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 3772
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    bool flag = true;
    if(S[0] != 'A') flag = false;
    if(count(S.begin()+2, S.end()-1, 'C') != 1) flag = false;
    for (auto c : S) {
        if (c != 'A' && c != 'C' && isupper(c)) flag = false;
    }
    if(flag) cout << "AC";
    else cout << "WA";
    cout << endl;
    return 0;
}




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

int main(){
	int N, M, lim;
	cin >> N >> M;
	lim = M/N;
	int num = 0;
	vector<int> yakusu(1000000);
	for(int i=0; i<sqrt(M); i++){
		if(M % (i+1) == 0){
			yakusu[num] = i+1;
			num++;
			yakusu[num] = M/(i+1);
			num++;
		}
	}
	int max = -1;
	for(int i=0; i<yakusu.size(); i++){
		if(yakusu[i] <= lim){
			if(max < yakusu[i]) max = yakusu[i];
		}
	}
	cout << max << endl;
}


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

int main()
{
    ll A[110][110]={},B[110][110]={},C[110][110]={},n,m,l;
    cin>>n>>m>>l;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>A[i][j];
        }
    }

    for(int i=1;i<=m;i++){
        for(int j=1;j<=l;j++){
            cin>>B[i][j];
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=l;j++){

            for(int k=1;k<=m;k++){

                C[i][j]+=A[i][k]*B[k][j];

            }
            cout<<C[i][j];
            if(j!=l){cout<<" ";}
            else{cout<<endl;}
        }
    }


    return 0;
}


Measured memory_bytes: 3384
n = int(input())
evens, odds = {}, {}
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        if v in evens:
            evens[v] += 1
        else:
            evens[v] = 1
    else:
        if v in odds:
            odds[v] += 1
        else:
            odds[v] = 1
evens = sorted(evens.items(), key=lambda x: x[1], reverse=True)
odds = sorted(odds.items(), key=lambda x: x[1], reverse=True)
if len(evens) == 1 and len(odds) == 1:
    if evens[0][0] == odds[0][0]:
        print(n // 2)
    else:
        print(0)
else:
    if evens[0][0] == odds[0][0]:
        if len(evens) == 1:
            print(n // 2 - odds[1][0])
        elif len(odds) == 1:
            print(n // 2 - evens[1][0])
        else:
            print(
                min(n // 2 - evens[0][1] + n // 2 - odds[1][1],
                    n // 2 - evens[1][1] + n // 2 - odds[0][1]))
    else:
        print(n // 2 - evens[0][1] + n // 2 - odds[0][1])


Measured memory_bytes: 17392
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[]c=sc.next().toCharArray();
        for(int i=0;i<c.length;i++)System.out.print((char)((c[i]-'A'+n)%26+'A'));
    }
}


Measured memory_bytes: 26580
#include <bits/stdc++.h>
#define INF 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll t[51][101];

ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&t[0][i]);
	}
	int now=0;
	while(1){
		int cnt=0;
		for(int i=0;i<n;i++){
			if(t[now][i*2]>0 && t[now][i*2+1]>0){
				t[now+1][i]=t[now][i*2]/gcd(t[now][i*2],t[now][i*2+1])*t[now][i*2+1];
			}else if(t[now][i*2]>0){
				t[now+1][i]=t[now][i*2];
			}
		}
		for(int i=0;i<n;i++){
			if(t[now+1][i]>0){
				cnt++;
			}
		}
		if(cnt==1){
			printf("%lld\n",t[now+1][0]);
			break;
		}
		now++;
	}
	return 0;
}

Measured memory_bytes: 256
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
ll n,m,k,ar[N],br[N];
string s,s1;
//Variables End
ll sub(ll a, ll b){return (a-b+MOD)%MOD;}
ll add(ll a, ll b){return (a+b)%MOD;}
ll mul(ll a, ll b){return (a*b)%MOD;}
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modExpo((x*x)%MOD,n/2);
    else                             //n is odd
        
        return (x*modExpo((x*x)%MOD,(n-1)/2))%MOD;

}
ll modInverse(ll n) 
{ 
    return modExpo(n,MOD-2); 
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		cin>>n>>k;
		vi in(n,0);
		vi fact(n+1,1);
		rep(i,1,n+1)fact[i]=mul(fact[i-1],i);
		set<ll> se;
		rep(i,0,n){cin>>in[i];se.insert(in[i]);}
		sort(all(in));
		ll ans1=0,ans2=0;
		for(auto i:se)
		{
			ll pos1=upper_bound(all(in),i)-in.begin();
			ll pos2=lower_bound(all(in),i)-in.begin();
			ll val1=0,val2=0;
			if(pos1>=k)val1=mul(fact[pos1],mul(modInverse(fact[pos1-k]),modInverse(fact[k])));
			if(pos2>=k)val2=mul(fact[pos2],mul(modInverse(fact[pos2-k]),modInverse(fact[k])));
			ans2=add(ans2,mul(i,sub(val1,val2)));
			ll temp=pos1;
			pos1=n-pos2;
			pos2=n-temp;
			val1=0,val2=0;
			if(pos1>=k)val1=mul(fact[pos1],mul(modInverse(fact[pos1-k]),modInverse(fact[k])));
			if(pos2>=k)val2=mul(fact[pos2],mul(modInverse(fact[pos2-k]),modInverse(fact[k])));
			ans1=add(ans1,mul(i,sub(val1,val2)));
		}

		cout<<sub(ans2,ans1)<<endl;

    }
    return 0;
        
}

Measured memory_bytes: 6144
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int m = a * b * (h / a) * (w / b);
	cout << h * w - m << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 1; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  int maxCount = 0;
  int ans = 1;
  rep (i, n + 1) {
    int tmp = i;
    int count = 0;
    while (tmp != 0 && tmp % 2 == 0) {
      tmp /= 2;
      count++;
    }
    if (maxCount < count) {
      maxCount = count;
      ans = i;
    }
  }
  P(ans);


  return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int N,M;
vector<pair<int,ll>> g[2010];
ll dist[2010];

int main(int argc, char const *argv[])
{
    scanf("%d %d",&N,&M);
    for (int i = 0; i < M; ++i)
    {
        int a,b;long long c;
        scanf("%d %d %lld",&a,&b,&c);
        a--,b--;
        g[a].emplace_back(b,-c);
        // g[b].emplace_back(a,-c);
    }

    bool negative = false;
    const long long INF = 1LL << 55;
    fill(dist,dist + N,INF);
    dist[0] = 0;

    for(int i = 0;i < 2*N;i++){
        for(int j = 0;j < N;j++){
            if(dist[j] >= INF/2)continue;
            else{
                for(auto &e : g[j]){
                    if(dist[e.first] > dist[j] + e.second){
                        if(i == N)dist[e.first] = -INF;
                        else dist[e.first] = dist[j] + e.second;
                    }
                }
            }
        }
    }
    if(dist[N-1] <= -INF/2){
        cout << "inf" << endl;
    }else{
        cout << -dist[N-1] << endl;
    }
//    cout << -dist[N-1] << endl;
    return 0;
}


Measured memory_bytes: 384
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N, K = map(int, input().split())
    S = list(input())
    gr = groupby(S)
    cnt = 0
    happy = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            happy += 1
    for key, group in gr:  # groupはイテレータ。list(group)でリスト化
        """ex.
        0: [0, 0, 0]
        1: [1, 1]
        0: [0, 0, 0]
        1: [1, 1]
        0: [0]
        1: [1]
        """
        cnt += 1
    cut = cnt-1
    while K > 0:
        if cut == 0:
            break
        elif cut >= 2:
            happy += 2
            cut -= 2
        else:
            happy += 1
            cut -= 1
        K -= 1

    print(happy)

resolve()

Measured memory_bytes: 49392
#include<stdio.h>
int main(){
  int n,x,y,i,count;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    x+=800;
    count++;
    if(count%15==0){
      y+=200;
    }
  }
  printf("%d\n",x-y);
}



Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String ans = "No";
    int n = sc.nextInt();
    int zoro = 0;
    for (int cnt = 0; cnt < n; cnt++) {
      int d1 = sc.nextInt();
      int d2 = sc.nextInt();
      if (d1 == d2) {
        zoro++;
        if (zoro == 3) {
          ans = "Yes";
        }
      } else {
        zoro = 0;
      }
    }
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 36032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	ci2(n,m);
	int sum=0;
	fo(i,m){
		int temp;
		ci(temp);
		sum+=temp;
	}
	if(sum>n){
		co(-1);
	}
	else{
		co((n-sum));
	}
	
}


Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long LL;

int main(){
    LL x, y, z;
    cin >> x >> y >> z;
    LL n = x + y + z;
    vector<LL> a(n), b(n), c(n);
    vector<pair<LL,LL>> a_b(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i] >> b[i] >> c[i];
        a_b[i] = pair<LL,LL>(a[i] - b[i], i);
    }
    sort(a_b.begin(), a_b.end());
    vector<LL> xz(n), yz(n);
    priority_queue<LL> q_xz, q_yz;
    LL total = 0;
    for(LL i = 0; i < n; ++i){
        total += b[a_b[i].second];
        q_yz.push(c[a_b[i].second] - b[a_b[i].second]);
        if(q_yz.size() > y){
            total += q_yz.top(); q_yz.pop();
        }
        yz[i] = total;
    }
    total = 0;
    for(LL i = n-1; i >= 0; --i){
        total += a[a_b[i].second];
        q_xz.push(c[a_b[i].second] - a[a_b[i].second]);
        if(q_xz.size() > x){
            total += q_xz.top(); q_xz.pop();
        }
        xz[i] = total;
    }

    LL best = 0;
    for(LL k = y; k <= y + z; ++k){
        best = max<LL>(best, yz[k-1] + xz[k]);
    }
    cout << best << endl;
    return 0;
}



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

int main() {
    int64_t x; cin >> x;

    int64_t n = 100;
    int ans = 0;
    while (n < x) {
        n += n / 100;
        ++ans;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3584