akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
double dist(tuple<double,double,double> a,tuple<double,double,double> b)
{
  double p,q,r,s,t,u;
  tie(p,q,r)=a;
  tie(s,t,u)=b;
  return (p-s)*(p-s)+(q-t)*(q-t)+(r-u)*(r-u);
}
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<tuple<double,double,double> > lab;
  REP(i,n){
    double l,a,b;
    cin >> l >> a >> b;
    lab.push_back(make_tuple(l,a,b));
  }
  vector<double> dp,answer;
  dp.assign((1<<n),0.0);
  answer.assign(n+2,0.0);
  REP(i,1<<n){
    REP(j,n){
      if(i&(1<<j)) continue;
      int ne=(i|(1<<j)),bits=0;
      REP(k,n) if(ne&(1<<k)) ++bits;
      dp[ne]=dp[i];
      REP(k,n){
	if(i&(1<<k))
	  dp[ne]+=dist(lab[j],lab[k]);
      }
      answer[bits]=max(answer[bits],dp[ne]);
    }
  }
  cout << fixed << setprecision(10) <<  answer[m] << endl;
  return 0;
}

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

using namespace std;

int inf=0x3f3f3f3f;
int n,k,q;
long long a[2010],t[2010],al[2010];

int work(int x)
{
    int s=0,num=0,j;
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]>=a[x])
        {
            if(s==0) s=i;
        }
         else if(s)
            {
                if(i-s>=k)
                {
                    for(j=s;j<i;j++)
                    {
                        t[j-s+1]=a[j];
                    }
                    sort(t+1,t+i-s+1);
                    for(j=1;j+k-1<=i-s;j++)
                    {
                        num++;
                        al[num]=t[j];
                    }
                }
                s=0;
            }
    }
    if(num<q) return inf;
    sort(al+1,al+num+1);
    return al[q]-a[x];
}



int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans=inf;
    for(int i=1;i<=n;i++) ans=min(ans,work(i));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool is_palindrome(string s)
{
	string t(s.rbegin(), s.rend());
	return s == t;
}
bool is_strong_palindrome(string s)
{
	int N = s.size();
	return is_palindrome(s) && is_palindrome(s.substr(0, (N-1)/2)) && is_palindrome(s.substr(((N+1)/2)));
}
int main()
{
	string s;
	cin >> s;
	if (is_strong_palindrome(s))
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 256
h = int(input())
w = int(input())
n = int(input())
count = 0
if(h >= w):
    for i in range(0,w+1,1):
        if((h*w) - (h*(w-i)) >= n):
            count = i
            break
else:
    for i in range(0,h+1,1):
        if((h*w) - (w*(h-i)) >= n):
            count = i
            break
print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int M,N,a,total;
cin>>N>>M;
total=0;
int A[N];
for(int i=0;i<N;++i){
    cin>>a;
    A[i]=a;
    total+=a;
}
int ans=0;
for(int i=0;i<N;++i){
    if(A[i]*4*M>=total){
        ans+=1;
    }
}
if(ans>=M){
    cout<<"Yes"<<"\n";
}
else{
    cout<<"No"<<"\n";
}
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//mod計算用のクラス
class ModInt{
public:
    long long int x;
    long long int mod;
	ModInt(){}
    ModInt(long long int _x, long long int _mod = 1000000007){
        this->x = _x % _mod;
        this->mod = _mod;
    }
	ModInt operator+(ModInt other){
		return ModInt(this->x + (other.x % this->mod),this->mod);
	}
	ModInt operator-(ModInt other){
		long long int res = this->x - (other.x % this->mod);
		if (res < 0) return ModInt(res + this->mod, this->mod);
		return ModInt(res);
	}
	ModInt operator*(ModInt other){
		return ModInt(this->x * (other.x % this->mod),this->mod);
	}
	ModInt operator/(ModInt other){
		return ModInt(*this * other.inv());
	}
	ModInt pow(long long int n){
		ModInt res(1, this->mod), a(this->x, this->mod);
		while (n){
			if (n & 1){
				res = res * a;
			}
			n >>= 1;
			a = a * a;
		}
		return res;
	}
	ModInt inv(){
		return ModInt(this->pow(this->mod - 2));
	}
	void disp(){
		cout << this->x << endl;
	}
};
ostream& operator<<(ostream& stream, const ModInt m){
	stream << to_string(m.x);
	return stream;
}

//mod nCrを返す関数.何回も計算するときはこっち.ModIntが必要.
class modcomb{
	public:
		vector<ModInt> fact;
		vector<ModInt> ifact;
		modcomb(){}
		modcomb(int n){
			this->fact.resize(n + 1, ModInt(1));
			this->ifact.resize(n + 1, ModInt(1));
			for (int i = 1; i <= n;i++)
				this->fact[i] = this->fact[i - 1] * i;
			this->ifact[n] = fact[n].inv();
			for (int i = n; i >= 1; --i)
				this->ifact[i - 1] = ifact[i] * i;
		}
		ModInt operator()(int n, int k){
			if (k < 0 || k > n)
				return 0;
			return this->fact[n] * this->ifact[k] * this->ifact[n - k];
		}
};
modcomb co(2000005);
ModInt g(int r,int c){
	return co(r + c + 2, r + 1) - 1;
}

int main()
{
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	r1--;
	c1--;

	

	ModInt ans;
	ans = g(r2,c2) - g(r1, c2) - g(r2,c1) + g(r1,c1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 62720
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<set>
#include<map>
#define LL long long
#define N 200005
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define INF 0x7fffffff
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
using namespace std;
int a[N],b[N];
struct Node{
	int v,id;
}p[N];
int cmp(Node a,Node b){
	return a.v < b.v;
}
int main(){
	int n;
	scanf("%d",&n);
	FOR(i,1,n){
		scanf("%d",&p[i].v);
		p[i].id = i;
	}
	sort(p + 1,p + n + 1,cmp);
	a[1] = 1;
	FOR(i,2,n) a[i] = a[i - 1] + 20002;
	FOR(i,1,n) b[i] = a[n + 1 - i];
	FOR(i,1,n) b[i] = b[i] + p[i].id;
	printf("%d",a[1]);
	FOR(i,2,n) printf(" %d",a[i]);
	printf("\n");
	printf("%d",b[1]);
	FOR(i,2,n) printf(" %d",b[i]); 
	printf("\n");
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string a, b;
	cin >> a >> b;
	int al = a.length(), bl = b.length();
	int dp[al+1][bl+1];
	for (int i = 0; i <= al; i++)
	{
		for (int j = 0; j <= bl; j++)
		{
			if ( i == 0 || j == 0)
			{
				dp[i][j] = 0;
			}
			else if ( a[i-1] == b[j-1])
			{
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	int mx = dp[al][bl];
	int cnt = 1;
	char ans[mx+1];
	ans[mx] = '\0';
	int i = al, j = bl;
	while( i > 0 && j > 0)
	{
		if ( a[i-1] == b[j-1])
		{
			ans[mx-1] = a[i-1];
			i --;
			j --;
			mx --;
		}
		else if ( dp[i][j-1] > dp[i-1][j])
		{
			j --;
		}
		else
		i --;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo

int a[N];

void solve() {
    int n, k; cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for(int i = k + 1; i <= n; ++i) {
        if (a[i] > a[i - k]) cout << "Yes\n";
        else cout << "No\n";
    }
}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("travel_restrictions_input.txt", "r", stdin);
//    freopen("A.out", "w", stdout);
//    int test; cin >> test;
//    for(int t = 1; t <= test; ++t) {
//        cout << "Case #" << t << ":" << endl;
        solve();
//    }
    return 0;
}



Measured memory_bytes: 4660
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, A);
  VAR(char, op);
  VAR(ll, B);
  print(op == '+' ? A + B : A - B);
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N+1);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    int inf = 1e9;
    vector<int> dist(N+1, inf);
    dist[1] = 0;
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (dist[nxt] <= dist[now]+1) continue;
            dist[nxt] = dist[now]+1;
            q.push(nxt);
        }
    }
    cout << "Yes\n";
    for (int i = 2; i <= N; i++) {
        for (int nxt : edge[i]) {
            if (dist[nxt] == dist[i]-1) {
                cout << nxt << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 10096
#include <stdio.h>
int main(int argc, char *argv[])
{
	int n,k,i,j,a[100],s=0;
	int min,t,m,v;
	while(scanf("%d%d",&n,&k)!=EOF)
	{for(i=0;i<n;i++)
	{scanf("%d",&a[i]);}
	for(i=0;i<n-1;i++)
	{
		min=a[i];
		m=i;
		for(j=i;j<n;j++)
		{
			if(a[j]<min)
			{min=a[j];
			m=j;}
		}t=a[m];a[m]=a[i];a[i]=t;
    }for(i=n-k;i<n;i++)
	{s+=a[i];
	}printf("%d\n",s);s=0;}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define inf (1LL << 60)
using namespace std;

long long n;
vector<long long> a, b, now, num;
vector<vector<int>> dp;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  for (auto& p : a) cin >> p;
  for (auto& p : b) cin >> p;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = (1LL << 51) - 2;
  for (int i = 50; i >= 0; --i) {
    dp.assign(51, vector<int>(51, 0));
    for (int j = 0; j <= 50; ++j) dp[j][j] = 1;
    for (int j = 1; j <= 50; ++j)
      if ((res >> j & 1) && i != j)
        for (int k = 0; k <= 50; ++k)
          for (int l = 0; l <= k; ++l) dp[k][l] |= dp[k % j][l];
    bool ch = 1;
    for (int j = 0; j < n; ++j)
      if (!dp[a[j]][b[j]]) ch = 0;
    if (ch && i) res -= 1LL << i;
    if (!ch && !i) return -1;
  }
  return res;
}


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

using namespace std;
//a mnogo kokaina znaci to da nisi miran
const int maxi =1e6+10;
#define pb push_back
#define pii pair<int,int>
const long long mo = 1e9+7;
int a[maxi];
string s;
int n;
vector<int> v[maxi];

int main()
{
    long long sum = 0;
    cin>>n;
    for (int i  =1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
        sum%=mo;
    }
    long long ans = 0;
    for (int i = 1;i<=n;i++)
    {
        ans+= (sum - a[i])*a[i];
        ans%=mo;
        if (ans<0) ans+=mo;
    }

    ans*=(mo+1)/2;
    ans%=mo;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 27864
while true
	h,w = gets.chomp.split(" ").map(&:to_i)
	break if h == 0 && w == 0
	h.times do |i|
		w.times do |j|
			if i == 0 or i == h - 1
				print "#"
			else
				if j == 0 or j == w - 1
					print "#"
				else
					print "."
				end
			end
		end
		print "\n"
	end
	print "\n"
end

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

using namespace std;
using ll = long long;

template<class T> ostream& operator<<(ostream& os, const vector<T> arr){ for(int i = 0; i < (int)arr.size(); i++)cout << arr[i] << (i == (int)arr.size() -1 ? "" : " "); return os;}

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    int cnt = 0;

    for(int i = 0; i < n - 1; i++) {
        int minj = i;
        for(int j = i + 1; j < n; j++) {
            if(a[j] < a[minj])minj = j;
        }
        if(i != minj)cnt++;
        swap(a[i], a[minj]);
    }
    cout << a << endl;
    cout << cnt << endl;
}


Measured memory_bytes: 3120
package main

import (
    "fmt"
)

func main() {
    var n, q int 
    fmt.Scan(&n, &q) 
    var s []byte
    fmt.Scan(&s)

    var cnt int 
    cs := make([]int, n)
    for i := range s { 
        if i > 0 && s[i] == 'C' && s[i-1] == 'A' {
            cnt++
        }   
        cs[i] = cnt 
    }   

    for i := 0; i < q; i++ {
        var l, r int 
        fmt.Scan(&l, &r) 
        fmt.Println(cs[r-1] - cs[l-1])
    }   
}


Measured memory_bytes: 7936
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  flag = true;

  int n, k; cin >> n >> k;

  for (int i = 0; i < n; ++i) {
    if (i == 0) num = k;
    else num *= (k - 1);
  }
  
  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define INFL (int)1e9
#define INFLL (ll)1e18
#define INFD numeric_limits<double>::infinity()
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define rnd(d) (ll)((double)d + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)x ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)a / (ll)b + ((ll)a % (ll)b == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
  int n; cin >> n;
  vll a(n + 2, 0); Loop1(i, n) cin >> a[i];
  ll ans = 0;
  Loop1(i, n + 1) {
    ans += abs(a[i] - a[i - 1]);
  }
  Loop1(i, n) {
    ll buf = 0;
    if (a[i - 1] <= a[i + 1] && a[i + 1] <= a[i]) {
      buf = 2 * (a[i] - a[i + 1]);
    }
    else if (a[i] <= a[i + 1] && a[i + 1] <= a[i - 1]) {
      buf  = 2 * (a[i + 1] - a[i]);
    }
    else if (a[i + 1] <= a[i - 1] && a[i - 1] <= a[i]) {
      buf = 2 * (a[i] - a[i - 1]);
    }
    else if (a[i] <= a[i - 1] && a[i - 1] <= a[i + 1]) {
      buf = 2 * (a[i - 1] - a[i]);
    }
    cout << ans - buf << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    double n; cin >> n;
    double ans = 0;

    vector<pair<double, double>> root(n);
    REP(i, n) cin >> root[i].first >> root[i].second;

    REP(i, n - 1){
        FOR(j, i + 1, n){
            ans += sqrt(pow(root[i].first - root[j].first, 2.0) + pow(root[i].second - root[j].second, 2.0));
        }
    }
    cout << fixed << setprecision(8) << (ans * 2) / n << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static int a, b;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    a = stdIn.nextInt();
    b = stdIn.nextInt();

    System.out.printf("%d %d %.5f\n", (a/b), (a%b), ((double)a/b));
  }
}

Measured memory_bytes: 26340
#include <iostream>

using namespace std;

int main() {

	int n, k;
	int a[100000];

	while(cin >> n >> k) {
		if(n==0&&k==0) {
			break;
		}
		for(int i=0; i<n; i++) {
			cin >> a[i];
		}
		int max=a[0];
		int t=0;
		for(int i=0; i<k; i++) {
			t+=a[i];
		}
		if(t>max) {
			max=t;
		}
		for(int i=k; i<n; i++) {
			t+=a[i];
			t-=a[i-k];
			if(t>max) {
				max=t;
			}
		}
		cout << max << endl;
	}

	return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
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; }
int main(){
int N;
cin>>N;
vector<int> h(N);
int m=0;
for(int i=0;i<N;i++){
    cin>>h.at(i);
    chmax(m,h.at(i));
}
int res=0,i=0;
   while(true){
       if(*max_element(h.begin(),h.end())==0) break;
       i=0;
       while(i<N){
           if(h.at(i)==0)i++;
           else{
           res++;
           while(i<N && h.at(i)>0){
               h.at(i)--;
               i++; 
           }
           }
       }
   }
cout<<res<<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))

tmp_sum = 0
sum_a_mod = []
for i in range(n):
    tmp_sum += a[i]

    sum_a_mod.append(tmp_sum % m)

import collections
c = collections.Counter(sum_a_mod)

counter = 0
for k in c.keys():
    v = c[k]
    if v >= 2:
        counter += int(v * (v - 1) / 2 )

    if k == 0:
        counter += v

print(counter)


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> cnt(N, K-Q);
  for ( int i = 0; i < Q; i++ ) {
    int a;
    cin >> a;
    a--;
    cnt[a]++;
  }

  for ( int i = 0; i < N; i++ ) {
    if ( cnt[i] >= 1 ) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, self.pow(b, self.m-2))

    def pow(self, x, y):
        if y == 0:
            return 1
        elif y == 1:
            return x % self.m
        elif y % 2 == 0:
            return self.pow(x, y//2)**2 % self.m
        else:
            return self.pow(x, y//2)**2 * x % self.m


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


@mt
def slv(N, M, K):
    m = Mod(10**9+7)
    b = Combination(N*M, 10**9+7)(N*M-2, K-2)

    MM = m.mul(M, M)
    NN = m.mul(N, N)
    ans = 0
    for d in range(1, N):
        ans = m.add(ans, m.mul(m.mul(m.mul(d, N-d), MM), b))

    for d in range(1, M):
        ans = m.add(ans, m.mul(m.mul(m.mul(d, M-d), NN), b))

    return ans


def main():
    N, M, K = read_int_n()
    print(slv(N, M, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29268
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	int N;
	scanf("%d", &N);
	double  v[50];
	double b[50];
	int a = 0;
	int count = 0;
	for (int i = 0; i < N; i++) {
		scanf("%lf", &v[i]);
	}
	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N -j-1; i++) {
			if (v[i] > v[i + 1]) {
				a = v[i + 1];
				v[i + 1] = v[i];
				v[i] = a;
			}

		}
	}

	 for (int i = 0; i < N - 1; i++) {
		v[i + 1] = (double)(v[i] + v[i + 1]) / 2;
	
	}
	 printf("%lf", v[N - 1]);

	

	
	return 0;

}

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

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

#define usize size_t
#define long int_fast64_t
#define ulong uint_fast64_t
#define int int_fast32_t
#define uint uint_fast32_t

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

signed main() {
    int n, m;
    cin >> n >> m;
    cout << (1 << m) * (100 * (n - m) + 1900 * m) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int n, count = 0;
string s;

void lol(int i){
    if ((s[i] == 'A') && (s[i+1] == 'B') && (s[i+2] == 'C')) count++;
}

int main(){
    cin >> n >> s;
    for (int i = 0; i <= n - 3; i++) lol(i);
    cout << count << '\n';
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (a, b) = readLine()!!.split(" ").map { it.toInt() }
    var pList = readLine()!!.split(" ").map { it.toInt() }.sorted()

    var sum = 0
    for (i in 0 until b) {
        sum += pList[i]
    }

    println(sum)
}

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

int main()
{
	int n, i;
	cin>>n;
	for(i=1;;i=i*2){
		if(i>n){
			i/=2;
			break;
		}
		else if(i==n)break;
	}
	cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        int d1, d2; cin >> d1 >> d2;
        if (d1 == d2) v[i] = 1;
        else v[i] = 0;
    }

    for (int i = 0; i < n - 2; ++i) {
        if (v[i] == 1 && v[i + 1] == 1 && v[i + 2] == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" <<  endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<int,int> > VP;

//AGC
// A?GC AG?C ?GAC ?ACG

ll dp[101][4][4][4];

void solve(){
    rep(i,3,n){
        rep(x,4)rep(y,4)rep(z,4)rep(j,4){
			if(x==0 && z==2 && j==3) continue;
			if(x==0 && y==2 && j==3) continue;
			if(y==2 && z==0 && j==3) continue;
			if(y==0 && z==2 && j==3) continue;
			if(y==0 && z==3 && j==2) continue;
            (dp[i][y][z][j]+=dp[i-1][x][y][z])%=mod;
        }
     }
}

int main(){
    cin>>n;
    rep(i,4)rep(j,4)rep(k,4)dp[2][i][j][k]=1;
    dp[2][0][2][3]=0;
    dp[2][0][3][2]=0;
    dp[2][2][0][3]=0;
    solve();
    rep(i,4)rep(j,4)rep(k,4){sum+=dp[n-1][i][j][k];}
    p(sum%mod);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(int (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(int (i) = (n); (i) >= 0; --(i))
typedef long long ll;
typedef unsigned long long ull;
const ull MOD = 1000000007;
ull mpow(ull a, ull n);
ull inv_mod(ull a){return mpow(a, MOD-2);}

ull mpow(ull a, ull n)
{
    ull ans = 1;
    while(n){
        if(n & 1)(ans *= a)%= MOD;
        (a*=a)%MOD;
        n>>1;
    }
}

ull nCr(ull n, ull r)
{
    vector<ull> factorial(n+1);
    factorial[0]=1;
    rep(i, n)factorial[i+1] = factorial[i]*(i+1)%MOD;
    return factorial[n]*inv_mod(factorial[n-r]%MOD)*inv_mod(factorial[r]%MOD);
}

int main()
{
    ll N;
    char s[100];
    cin >> N;
    scanf("%s", s);
    int j = N /2;
    if(N % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
    rep(i, N/2){
        if(s[i] == s[i + j]){
            continue;
        }
        cout << "No" << endl;
        return 0;

    }
    cout << "Yes" << endl;
    return 0;
}


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m, n;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.rbegin(),a.rend());
  bool j = true;
  rep(i,m) {
    if(4*m*a[i] < sum) j = 0;
  }
  cout<<((j)?"Yes":"No")<<endl;  
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by yangyuyin on 16/10/8.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] rabbit = new int[N+1];
        for(int i=1;i<=N;i++){
            rabbit[i]=sc.nextInt();
        }
        int count=0;
        for(int i=1;i<=N;i++){
            int ai=rabbit[i];
            if(rabbit[ai]==i) count++;
        }
        count/=2;
        System.out.println(count);
    }
}

Measured memory_bytes: 32396
"""
fast way to compute a combination using inverse factorials
O(N) to construct tables -> O(1) to compute each combination
"""


def get_factorials(limit: int, MOD: int) -> list:
    """Compute a mod table of factorials (1-indexed)."""
    factorials = [0] * (limit + 1)
    factorials[0] = 1
    x = 1
    for i in range(1, limit + 1):
        x = (x * i) % MOD
        factorials[i] = x
    return factorials


def mod_comb_with_pow(n: int, k: int, MOD: int) -> int:
    """Compute nCr % MOD using pow()."""
    return fact[n] * pow(fact[k], MOD - 2, MOD) * pow(fact[n - k], MOD - 2, MOD) % MOD


# e.g. ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def main():
    global fact, inv
    H, W, A, B = map(int, input().split())
    MOD = 10 ** 9 + 7
    fact = get_factorials(H + W, MOD)
    x, y, a = H - A - 1, W + A - 2, A - 1  # fixed variables
    f = lambda i: mod_comb_with_pow(x + i, i, MOD) * mod_comb_with_pow(y - i, a, MOD)
    ans = sum(f(i) for i in range(B, W)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10868
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<long double> p(n);
    for(int i=0;i<n;++i) {
        cin >> a[i];
        p[i] = double((a[i]+1) * a[i] / 2) * (1.0 / double(a[i]));
        if(i) p[i] += p[i-1];
    }

    long double ans = 0.0;
    for(int i=0;i<=n-k;++i) {
        long double tmp = p[i+k-1] - (i?p[i-1]:0.0);
        ans = max(ans, tmp);
    }

    cout << fixed << setprecision(14) << ans << endl;
}


Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long a = abc[0], b = abc[1], c = abc[2];
            if (a%2 == 0 || b%2 == 0 || c%2 == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                var m = Math.Min(Math.Min(a*b, b*c), c*a);
                Console.WriteLine(m);
            }
        }
    }
}


Measured memory_bytes: 2776
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int A, B;
    void Solve() {
        //input
        A = io.Int;
        B = io.Int;
        //cal
        if (A == 1)
            A = 14;
        if (B == 1)
            B = 14;
        //res
        Console.WriteLine(A > B ? "Alice" : A == B ? "Draw" : "Bob");
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 100000000000
#define mod 1000000007


int main()
{
    ll a,b;
    cin >> a >> b;
    cout << (a*b)/__gcd(a,b);
    return 0;
}

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

int main() {
    int N;
    long long A,B;
    cin >> N >> A >> B;
    long long X[N];
    for(int i = 0; i < N;i++)cin >> X[i];
    vector<long long>DP(N,0);
    DP[0] = 0;
    for(int i = 0;i < N-1;i++){
        //cout << (X[i+1]-X[i])*A  << endl;
        DP[i+1] = min((X[i+1]-X[i])*A + DP[i],B+DP[i]);
    }
    //long long sum = 0;
    //for(int i = 0;i < N;i++)sum += DP[i];
    
    cout << DP[N-1] << endl;
    
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
bool Visited[100005];
int dp[100005];
vector<int> Graph[100005];

void dfs( int root ){
    if( Visited[root] == true || int(Graph[root].size()) == 0 ) return;
    Visited[root] = true;
    int i , Max = 0;

    for( i = 0 ; i < int(Graph[root].size()) ; ++i ){
        if( Visited[Graph[root][i]] == false ) dfs( Graph[root][i] );
        Max = max( Max , dp[Graph[root][i]] );
    }

    dp[root] = Max + 1;
}

int main(){
    int N , m , i , u , v , Ans = 0;
    scanf( "%d%d" , &N , &m );
    fill( Visited + 1 , Visited + N + 1 , false );

    for( i = 1 ; i <= m ; ++i ){
        scanf( "%d%d" , &u , &v );
        Graph[u].emplace_back( v );
    }

    for( i = 1 ; i <= N ; ++i ){
        if( Visited[i] == false ) dfs( i );
        Ans = max( Ans , dp[i] );
    }

    printf( "%d\n" , Ans );
    return 0;
}

Measured memory_bytes: 8192
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    def check(n):
        if n == 1:
            return False
        i = 2
        while i*i <= n:
            if n%i == 0:
                return False
            i += 1
        return True
    f = [0 for i in range(100001)]
    for i in range(1,100001):
        f[i] += f[i-1]
        if check(i):
            if check((i+1)//2):
                f[i] += 1
    q = I()
    for i in range(q):
        l,r = LI()
        print(f[r]-f[l-1])

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 53040
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
#define per(i, a, b) for (int i = a; i >= b; -- i)
const int N = 200005, mo = 1000000007, inf = mo ; 
using namespace std ;

map <int, map<int, int> > h ;
int n, X, Y, inv[N], fa[N], ml[N], mr[N], b[N], fac[N], f[N], tot[N] ;
struct poi {
	int c, w ;
} a[N] ;

bool cmp(poi a, poi b) {
	return (a.c < b.c || (a.c == b.c && a.w < b.w)) ;
}

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

void merge(int x, int y) {
	x = getfa(x), y = getfa(y) ;
	if (x != y) fa[x] = y ; 
}

void pre(int l, int r) {
	int mn = min(ml[l - 1], mr[r + 1]) ;
	rep(i, l + 1, r) if (mn + a[i].w <= Y) {
		merge(i, i - 1) ;
	}
	per(i, r, l) if (a[l].w + a[i].w <= X) {
		merge(l, i) ;
	}
}

bool _cmp(int x, int y) {
	return a[x].w < a[y].w ;
}

void solve() {
	sort(b + 1, b + b[0] + 1, _cmp) ;
	int top = 1 ;
	per(i, b[0], 1) {
		for ( ; top <= i && a[b[top]].w + a[b[i]].w <= Y ; ++ top) {
			if (top - 1) merge(b[top], b[top - 1]) ;
		}
		if (top > i) break ;
		if (top - 1) merge(b[i], b[top - 1]) ;
	}
}

inline int mul(int a, int b) {
	int ans = 1, w = a % mo ;
	for ( ; b; b /= 2) {
		if (b & 1) ans = (ll) ans * w % mo ;
		w = (ll) w * w % mo ;
	}
	return ans ;
}


int main() {
	scanf("%d%d%d", &n, &X, &Y) ;
	rep(i, 1, n) {
		scanf("%d%d", &a[i].c, &a[i].w) ;
		fa[i] = i ;
	}
	sort(a + 1, a + n + 1, cmp) ;
	ml[0] = mr[n + 1] = inf ;
	rep(i, 1, n) ml[i] = min(ml[i - 1], a[i].w) ;
	per(i, n, 1) mr[i] = min(mr[i + 1], a[i].w) ;
	b[0] = 0 ;
	for (int i = 1, j; i <= n; i = j) {
		for (j = i + 1; j <= n && a[i].c == a[j].c; ++ j) ;
		pre(i, j - 1) ;
		b[++ b[0]] = i ; 
	}
	solve() ;
	int ans = 1 ;
	rep(i, 1, n) tot[i] = 0, f[i] = 1 ;
	fac[0] = inv[0] = 1 ;
	rep(i, 1, n) fac[i] = (ll) fac[i - 1] * i % mo ;
	rep(i, 1, n) inv[i] = mul(fac[i], mo - 2) ;
	rep(i, 1, n) {
		int u = getfa(i) ;
		++ tot[u] ;
		f[u] = (ll) f[u] * inv[tot[u] - 1] % mo ;
		f[u] = (ll) f[u] * fac[tot[u]] % mo ;
		f[u] = (ll) f[u] * fac[h[u][a[i].c]] % mo ;
		++ h[u][a[i].c] ;
		f[u] = (ll) f[u] * inv[h[u][a[i].c]] % mo ;
	}
	rep(i, 1, n) if (getfa(i) == i) 
		ans = (ll) ans * f[i] % mo ;
	printf("%d\n", ans) ;
	return 0 ; 
}

Measured memory_bytes: 34816
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// 別の書き方を使ってみる

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n, q;
array<int, max_n> cnts;

array<int, max_n> hd; // n : 頂点数
array<int, 2*max_n> nxt, to; // 2*(n-1)+1 : 辺の個数+1
int edge_cnt;
inline void add_edge(int u, int v) { // u to v
    edge_cnt++; // 辺が1つ増える
    to[edge_cnt] = v; // edge_cnt本目の辺の行き先はv
    nxt[edge_cnt] = hd[u]; // edge_cnt本目の辺の次に見る(uから出る)辺は、はじめに見ていた(uから出る)辺であるhd[u]本目の辺
    hd[u] = edge_cnt; // 新しくはじめに見る(uから出る)辺はedge_cnt本目の辺
}

void dfs(const int cur = 0, const int parent = -1)
{
    for (int e = hd[cur]; e > 0; e = nxt[e]) {
       int child = to[e];
       if (child == parent) { continue; }
       cnts[child] += cnts[cur];
       dfs(child, cur);
   }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << setprecision(10); // 浮動小数の表示の精度

    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(a,b);
        add_edge(b,a);
    }
    rep(j, q)
    {
        int p,x;
        cin >> p >> x;
        p--;
        cnts[p] += x;
    }

    // 集計
    dfs();

    rep(i, n)
    {
        cout << cnts[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 23948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  ll n;
  cin >> n;
  if (n % 2) {
    cout << 0 << endl;
    return;
  }
  ll cnt = 1;
  ll ans = 0;
  n /= 10;
  ans += n;
  while (n) {
    n /= 5;
    ans += n;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
g = Hash.new {|item, key| item[key] = []}
m.times do
  a, b = gets.split.map(&:to_i)
  g[a] << b
end
reachable = false
unless g[1].nil?
  g[1].each do |v|
    reachable = true if !g[v].nil? && g[v].include?(n)
  end
end
puts reachable ? "POSSIBLE" : "IMPOSSIBLE"

Measured memory_bytes: 24572
#include <stdio.h>
#include <stdlib.h>

int N;
double ***dp;

double solve(int i, int j, int k){
	if(i < 0 || j < 0 || k < 0 || N < i || N < j || N < k){
		return 0;
	}
	else if(i == 0 && j == 0 && k == 0){
		return 0;
	}
	else{
		if(dp[i][j][k] < 0){
			dp[i][j][k] = (N + i * solve(i - 1, j, k) + j * solve(i + 1, j - 1, k) + k * solve(i, j + 1, k - 1)) / (i + j + k);
		}
		return dp[i][j][k];
	}
}

int main(){
	int a, i, j, k, count[3] = {0, 0, 0};
	scanf("%d", &N);
	dp = (double ***)malloc(sizeof(double **) * (N + 1));
	for(i = 0; i <= N; i++){
		dp[i] = (double **)malloc(sizeof(double *) * (N + 1));
		for(j = 0; j <= N; j++){
			dp[i][j] = (double *)malloc(sizeof(double) * (N + 1));
			for(k = 0; k <= N; k++){
				dp[i][j][k] = -1;
			}
		}
	}
	for(i = 0; i < N; i++){
		scanf("%d", &a);
		if(a > 0){
			count[a - 1]++;
		}
	}
	printf("%.20lf\n", solve(count[0], count[1], count[2]));
	return 0;
}

Measured memory_bytes: 214656
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std ;
const int N = 1e7 + 4;
void FastInputOutput()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline ll LLD()
{
    ll ret;
    scanf("%lld", &ret);
    return ret;
}
inline int D()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
void bin( int x )
{
    if(!x)
        return;
    bin( x / 2 );
    cout << x % 2 ;
}
bool checkPrimeNumber(int n)
{
    bool flag = true;
    for(int j = 2 ; j <= n ; ++j)
    {
        if (n % j == 0)
        {
            flag = false;
            break;
        }
    }
    return flag;
}
bool cmp(string last, string first)
{
    if(last.size() < first.size())
        return 1;
    return 0;
}
int calculateDigit(int n)
{
    double temp = (double)(n);
    double a = 0.39908-(0.434294 * n);
    double b = log10( n ) ;
    double c = ( n + 0.5 ) * b ;
    double ans = c - abs( a ) ;
    return ceil(ans) ;
}
int findDigits(int n)
{
    double E = 2.71828182845904523536;
    double PI = 3.141592654;

     if (n < 0)
        return 0;
    if (n <= 1)
        return 1;

    double x = ((n * log10(n / E) +
                 log10(2.0 * PI * n) /
                 2.0));

    return floor(x) + 1;
}
ll fact(ll n){
ll ans = 1 ;
for(ll i = 1 ; i <= n ; ++i)
    ans *= i ;
return ans ;
}
int main()
{
    FastInputOutput() ;
    string s ;
    cin >> s ;
    int sz = s.length() ;
    for(int i = 1 ; i <= sz ; i += 2)
            cout << s[i - 1] ;

}


Measured memory_bytes: 592
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := readInt(), readInt()
	l := make([]int, n)
	for i := range l {
		l[i] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(l)))
	ans := 0
	for i := 0; i < k; i++ {
		ans += l[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640