akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int Nmax = 1500;

int main(){
	int n, m;
	while(cin >> n >> m && (n || m)){
		int h[Nmax+1];
		int w[Nmax+1];
		vector<int> hs;
		vector<int> ws;
		int length;
		h[0] = w[0] = 0;
		for(int i = 1; i <= n; i++){
			cin >> length;
			h[i] = h[i-1] + length;
		}
		for(int i = 1; i <= m; i++){
			cin >> length;
			w[i] = w[i-1] + length;
		}
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < i; j++){
				hs.push_back(h[i] - h[j]);
			}
		}
		for(int i = 1; i <= m; i++){
			for(int j = 0; j < i; j++){
				ws.push_back(w[i] - w[j]);
			}
		}
		sort(hs.begin(), hs.end());
		sort(ws.begin(), ws.end());
		int count = 0;
		for(vector<int>::iterator iter = hs.begin();
			iter != hs.end(); iter++)
		{
			count += upper_bound(ws.begin(), ws.end(), *iter) - lower_bound(ws.begin(), ws.end(), *iter);
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 12000
# from scipy.sparse.csgraph import floyd_warshall
INF = 100000000


def make_adj_list(vertex, edge):
    adj_list = []
    dp = []

    # adj_listの初期化と入力
    for i in range(vertex):
        adj_list.append([])
        for j in range(vertex):
            if i == j:
                adj_list[i].append(0)
            else:
                adj_list[i].append(INF)
    for i in range(edge):
        s, t, cost = map(int, input().split())
        adj_list[s][t] = cost

    # dpの初期化
    for i in range(1 << vertex):
        dp.append([])
        for j in range(vertex):
            dp[i].append(-1)

    return adj_list, dp


def cal_min_cost(dp, vertex, edge, d, already, now_v):
    if dp[already][now_v] >= 0:
        # すでに通ったことがある場合
        return dp[already][now_v]

    if already == (1 << vertex) - 1 and now_v == 0:
        # 全ての頂点を通った
        dp[already][now_v] = 0
        return dp[already][now_v]

    res = INF
    for i in range(vertex):
        if not already >> i & 1:
            # 次にiに移動する
            res = min(res, cal_min_cost(dp, vertex, edge, d,
                      already | 1 << i, i) + d[now_v][i])
    dp[already][now_v] = res
    return dp[already][now_v]


def main():
    vertex, edge = map(int, input().split())
    adj_list, dp = make_adj_list(vertex, edge)  # 初期化と入力
    # d = floyd_warshall(adj_list)  # それぞれの頂点からの最小を求める
    d = adj_list
    # for k in range(vertex):
    #     for i in range(vertex):
    #         for j in range(vertex):
    #             d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # print(d)
    # 最短距離は頂点のどこからはじめても変わらないので0からスタートとする
    min_cost = cal_min_cost(dp, vertex, edge, d, 0, 0)  # 計算
    if min_cost == INF:
        print(-1)
    else:
        print(int(min_cost))


if __name__ == "__main__":
    main()



Measured memory_bytes: 15700
#include <cstdio>

using namespace std;

int main(){
    int m, f, r;
    
    while(scanf("%d %d %d", &m, &f, &r), m > -1 || f > -1 || r > -1){
        if(m < 0 || f < 0){
            putchar('F');
        }
        
        else if(m + f >= 80){
            putchar('A');
        }
        
        else if(m + f >= 65){
            putchar('B');
        }
        
        else if(m + f >= 50){
            putchar('C');
        }
        
        else if(m + f >= 30){
            
            if(r >= 50){
                putchar('C');
            }
            
            else {
                putchar('D');
            }
        }
        
        else {
            putchar('F');
        }
        
        putchar('\n');
    }
    
    return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int n,m;
vi adj[100001];
int dp[100001];
bool vis[100001];

void dfs(int cur){
    vis[cur]=1;
    dp[cur]=0;
    for(int ch:adj[cur]){
        if(!vis[ch])dfs(ch);
        dp[cur]=max(dp[cur],1+dp[ch]);
    }
}

signed main(){
    FASTER;
    cin>>n>>m;
    while(m--){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(!vis[i])dfs(i);
    }
    for(int i=1;i<=n;i++){
        ans=max(dp[i],ans);
    }
    cout<<ans;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, s, n) for (int i = (s); i < (n); i++)
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; }
#define MOD 1000000007

int  main(){
    string s;
    cin>>s;

    if(char(s[s.size()-1])=='s'){
        s=s+"es";
      cout<<s<<endl;
    }
    else{
        s=s+'s';
      cout<<s<<endl;
    }

    return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define INF INT_MAX
#define cases(t) ll t; cin>>t; while(t--)
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }

#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define msi map<string,int>

int main(){
	IOS
	ll n;
	cin>>n;
	ll a[n];
	for(ll i = 0; i < n; ++i){
		cin>>a[i];
	}
	ll money = 1000, stock = 0;
	char order[n];
	for(ll i = 0; i < n - 1; ++i){
		if(a[i+1] >= a[i]){
			order[i] = 'a';
		} 
		else{
			order[i] = 'd';
		}
		//cout<<order[i]<<" ";
	}
	//order[n-1] = order[n-2];
	//cout<<order[n-1]<<endl;

	if(order[0] == 'a'){
		stock += money/a[0];
		money -= (stock*a[0]);
	}
	//cout<<money<<" "<<stock<<endl;

	for(ll i = 0; i < n - 1; ++i){
		if(order[i] == 'd' and order[i+1] == 'a'){//buy
			stock += money/a[i+1];
			money -= (stock*a[i+1]);
		}
		if(order[i] == 'a' and order[i+1] == 'd'){//sell
			money += (stock*a[i+1]);
			stock = 0;
		}
		//cout<<i<<" "<<money<<" "<<stock<<endl;
	}

	if(stock)
		money+=(stock*a[n-1]);
	cout<<money;

return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
    int ub,lb,h,a=0;
    scanf("%d%d%d",&ub,&lb,&h);
    if(1<=ub&&ub<=100&&1<=lb&&ub<=100&&1<=h&&h<=100&&h%2==0)
    {
        a=(ub+lb)*(h/2);
    }
    printf("%d",a);
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define len(a) (int) (a).size()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define int long long
using namespace std;
void solve();
mt19937 rnd(2007);
signed main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    swap(rng, rnd);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}

void solve() {
    int h1, s1, h2, s2; cin >> h1 >> s1 >> h2 >> s2;
    int cnt = 0;
    while (h1 > 0 && h2 > 0){
        h2 -= s1;
        swap(h1, h2);
        swap(s1, s2);
        cnt++;
    }
    if (cnt % 2 == 1){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string str;
	cin >> str;
	vector<bool> vec(27);
	for(char c : str){
		vec[c-'a'] = true;
	}
	for(int i = 0; i < 26; i++){
		if(vec[i] == false){
			cout << (char)('a'+i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

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

int main()
{
    int n, r;
    cin >> n >> r;
    if (n > 10)
    {
        cout << r << endl;
    }
    else
    {
        cout << r + (100 * (10 - n)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;

    int n=s.size();
    stack<char> st;
    int cnt=0;
    rep(i,n){
        if(s[i]=='S') st.push('S');
        else{
            if(!st.empty()){
                cnt++;
                st.pop();
            }
        }
    }

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




Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,ans=1e18;
    scanf("%lld",&n);
    for(int i=1;i<=floor(sqrt(n)+0.5);i++)
        if(n%i==0)
            ans=min(ans,i+n/i);
    printf("%lld",ans-2);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  vector<int> a(m),b(m);
  int s,t,u,v;
  if(n%2==1){
    s=1;
    t=s+n/2;
    u=t+1;
    v=n;

  }else{
    s=1;
    t=n/2;
    u=t+1;
    v=n-1;
  }
  for(int i=0;i<m;i++){
    if(i%2==0){
      a[i]=s;
      b[i]=t;
      s++;
      t--;
    }else{
      a[i]=u;
      b[i]=v;
      u++;
      v--;
    }
  }
  for(int i=0;i<m;i++){
    cout<<a[i]<<" "<<b[i]<<endl;
  }



  return 0;
}




Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define LL long long
#define N 2005
using namespace std;
int n,m,q,A[N][N],B[N][N],S[N][N]; char st[N][N];
int E(int xi,int yi,int xj,int yj,int X[N][N])
{
	return X[xj][yj]-X[xi-1][yj]-X[xj][yi-1]+X[xi-1][yi-1];
}
int main()
{
	int i,j,a,b,c,d;
	scanf("%d %d %d\n",&n,&m,&q);
	for(i=1;i<=n;i++)
		scanf("%s",st[i]+1);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			S[i][j]=S[i][j-1]+st[i][j]-'0';
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			S[i][j]+=S[i-1][j];
	for(i=1;i<n;i++)
		for(j=1;j<=m;j++)
			A[i][j]=A[i][j-1]+(st[i][j]=='1'&&st[i+1][j]=='1');
	for(i=1;i<n;i++)
		for(j=1;j<=m;j++)
			A[i][j]+=A[i-1][j];
	for(i=1;i<=n;i++)
		for(j=1;j<m;j++)
			B[i][j]=B[i][j-1]+(st[i][j]=='1'&&st[i][j+1]=='1');
	for(i=1;i<=n;i++)
		for(j=1;j<m;j++)
			B[i][j]+=B[i-1][j];
	while(q--){
		scanf("%d %d %d %d",&a,&b,&c,&d);
		int ans=E(a,b,c,d,S);
		ans-=E(a,b,c-1,d,A);
		ans-=E(a,b,c,d-1,B);
		printf("%d\n",ans);
	  }
	return 0;
}


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



int main()
{
  while (true)
  {
    ll n;
    cin >> n;
    if (n == 0)
    {
      break;
    }
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i)
    {
      cin >> a.at(i);
    }
    vector<vector<ll>> dp(n, vector<ll>(n, 0));
    for (ll i = 0; i < n - 1; ++i)
    {
      if (abs(a.at(i + 1) - a.at(i)) <= 1)
      {
        dp.at(i).at(i + 1) += 1;
      }
    }
    for (ll w = 0; w < n; ++w)
    {
      for (ll l = 0; l < n - w; ++l)
      {
        ll r = l + w;
        // cout << "r" << r << endl;
        for (ll m = l; m < r; ++m)
        {
          dp.at(l).at(r) = max(dp.at(l).at(r), dp.at(l).at(m) + dp.at(m + 1).at(r));
        }
        if (l - 1 >= 0 && r + 1 < n)
        {
          // cout << dp.at(l).at(r) << "w" << w << endl;
          // if (dp.at(l).at(r) * 2 == w + 1)
          // {
            //   cout << l << r << endl;
            // }
            if ((dp.at(l).at(r) * 2 == w + 1) && (abs(a.at(l - 1) - a.at(r + 1)) <= 1))
            {
              // cout << l << r << endl;
              dp.at(l - 1).at(r + 1) = dp.at(l).at(r) + 1;
            }
          }
        }
      }
      cout << dp.at(0).at(n - 1) * 2 << endl;
      // for (ll i = 0; i < n; ++i)
      // {
        //   for (ll j = 0; j < n; ++j)
        //   {
          //     cout << dp.at(i).at(j) << ' ';
          //   }
          //   cout << endl;
          // }
  }
}



Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

signed main() {
  ll M, n = 0, s = 0;
  cin >> M;
  rep(i, M) {
    ll d, c;
    cin >> d >> c;
    n += c;
    s += d * c;
  }
  cout << (n - 1) + (s - 1) / 9 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    char c = 'X';

    int count = 0;
    for(int i=0;i<N;++i){
        if(c != S[i]){
            c = S[i];
            ++count;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  ll K;cin >> K;
  vector<PCI> v;
  char pre = s[0];
  int num = 0;
  rep(i,s.length()){
    if(pre==s[i])++num;
    else{
      v.push_back(PCI(pre,num));
      num = 1;
    }
    pre = s[i];
  }

  v.push_back(PCI(pre,num));
  if(v.size()==1){
    ll N = s.length();
    cout << (ll)K*N/2 << endl;
  }
  else{
    ll count = 0;
    if(s[0] == s[s.size()-1] && 
        v[0].second%2 == 1 &&
        v[v.size()-1].second%2 == 1) count += K-1;
    rep(i,v.size()) count += (ll)K*(v[i].second/2);
    cout << (ll)count << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 596
def task(n, a):
    for value in a:
        if value == 0:
            print(0)
            return

    ans = a[0]
    limit = pow(10, 18)
    for i in range(1, n):
        ans *= a[i]
        if ans > limit:
            print(-1)
            return

    print(ans)


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


Measured memory_bytes: 87856
#include<iostream>
#include<cstdio>
#include<queue>
#define ULL unsigned long long
#define LL long long
using namespace std;
const int mod = 998244353;
const int N = 1e5+7;

int main()
{
	int n;
	cin>>n;
	int a[N],num[N] = {0};
	for(int i=0;i<n;i++){
		cin>>a[i];
		num[a[i]]++;
	}
	if(a[0]!=0) {
		cout<<0<<endl;return 0;
	}
	ULL ans=1;
	for(int i=1;i<n;i++){
		if(a[i]==1) continue;
		ans=ans*num[a[i]-1]%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 3732
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    int aoki = 0;
    int takahasi = 0;
    
    while (c > 0){
        c = c - b;
        takahasi++;
    }
    while (a > 0){
        a = a - d;
        aoki++;
    }
    if (takahasi <= aoki){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3624
import math

In=input().split( )

a=int(In[0])
b=int(In[1])
C=int(In[2])

s=math.sin((C/180)*3.14159265)
c=math.cos((C/180)*3.14159265)

S=a*b*s/2
L=a+b+math.sqrt(a**2+b**2-2*a*b*c)
h=2*S/a

print(S)
print(L)
print(h)



Measured memory_bytes: 5688
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = lr()
A.sort()

MOD = 10 ** 9 + 7
if K == 1:
    print(0)
    exit()


def cmb(n, k):
    # nCkを計算する
    k = min(k, n-k)
    return fac[n] * ifac[k] % MOD * ifac[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

fac, ifac = make_fact(10**6, MOD)
answer = 0
for i in range(K-1, N):
    # 最大値として何回登場するか、A[i] * i C (K-1)
    answer += A[i] * cmb(i, K-1)
    answer %= MOD

for i in range(N-K+1):
    # A[i] * (N-(i+1)) C (k-1)
    answer -= A[i] * cmb(N-(i+1), K-1)
    answer %= MOD

print(answer % MOD)
# 51

Measured memory_bytes: 56316
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
class SAT2 {
public:
  int N;
  vector< vector<int> > G, R;
  vector<int> vs, used, ord;

  SAT2 (int N) : N(N) {
    G.resize(N);
    R.resize(N);
    used.resize(N);
    ord.resize(N);
  }

  void add_edge(int x, int y) {
    assert(x < N && y < N);
    G[x].pb(y);
    R[y].pb(x);
  }

  void dfs(int x) {
    if (used[x]) return;
    used[x] = true;
    for (int t : G[x]) dfs(t);
    vs.pb(x);
  }
  void rdfs(int x, int k) {
    if (used[x]) return;
    used[x] = true;
    ord[x] = k;
    for (int t : R[x]) rdfs(t, k);
  }

  int scc() {
    rep(i, N) used[i] = false;
    rep(i, N) dfs(i);
    rep(i, N) used[i] = false;
    int k = 0;
    for (int i=vs.size()-1; i>=0; i--) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }
};


#define MAX_N (1<<16)

int seg(int x) {
  return x+2*N;
}
void add_edge(SAT2 &sat, int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
  if (r <= a || b <= l) return;
  if (a <= l && r <= b) {
    sat.add_edge(x, seg(k));
    return;
  }
  add_edge(sat, a, b, x, k*2+1, l, (l+r)/2);
  add_edge(sat, a, b, x, k*2+2, (l+r)/2, r);
}

int flip(int x) {
  if (x >= N) return x-N;
  return x+N;
}

vector<P> xs;
bool f(int X) {
  SAT2 sat(2*N + 2*MAX_N-1);

  rep(i, 2*N) {
    sat.add_edge(seg(i+MAX_N-1), flip(xs[i]._2));
  }
  for (int i=MAX_N-2; i>=0; i--) {
    sat.add_edge(seg(i), seg(i*2+1));
    sat.add_edge(seg(i), seg(i*2+2));
  }
  rep(i, 2*N) {
    int x = xs[i]._1, xi = xs[i]._2;
    int l = lower_bound(all(xs), P(x-(X-1), -1)) - xs.begin(),
        r = upper_bound(all(xs), P(x+(X-1), INF)) - xs.begin() - 1;
    // [l, x), [x+1, r+1)
    add_edge(sat, l, i, xi);
    add_edge(sat, i+1, r+1, xi);
  }
  sat.scc();
  rep(i, N) {
    if (sat.ord[i] == sat.ord[i+N]) return false;
  }
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;

  rep(i, N) {
    int x, y;
    cin >> x >> y;
    xs.pb(P(x, i));
    xs.pb(P(y, i+N));
  }
  sort(all(xs));

  int lo = -1, hi = 1000000001;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (f(mid)) lo = mid;
    else hi = mid;
  }
  cout << lo << "\n";
  return 0;
}


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

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    unsigned long long N, K;
    std::cin >> N >> K;
    if( N >= K){
        N = N % K;
    }
    std::cout << std::min(N, K - N) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string.h>

int main(){
	char ch[1024];
	scanf("%s",ch);
	int sz = strlen(ch);
	for(int i = 0; i < sz; i++){
		ch[i] -= 'A';
		if(ch[i] < 3){
			ch[i] += 26;
		}
		ch[i] = ch[i] + 'A' - 3;
	}
	printf("%s\n",ch);
	return 0;
}

Measured memory_bytes: 2588
class UnionFind:
    def __init__(self, num):
        self.rank = [0] * num
        self.par = [i for i in range(num)]
        self.n = num

    def find_root(self, node):
        if self.par[node] == node:
            return node
        else:
            self.par[node] = self.find_root(self.par[node])
            return self.par[node]

    def same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def union(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1


def main():
    N, M = map(int,input().split())
    L = list(map(int,input().split()))
    UF = UnionFind(N)
    
    for i in range(M) :
        A, B = map(int,input().split())
        A -= 1
        B -= 1
        UF.union(A, B)
    
    ans = 0
    
    for i, v in enumerate(L) :
        ans += (UF.same_root(i, v-1))
    
    print(ans)
    
        

import sys
input = sys.stdin.readline

if __name__ == "__main__":
    main()


Measured memory_bytes: 14388
#include<stdio.h>
int main(){
  int n=0;
  long long max,d,sum=0;
  long long min = 1;
  scanf("%d",&n);
  scanf("%lld",&d);
  max=d;
  min=d;
  sum=sum+d;
  n=n-1;
  
  while(n!=0){
    scanf("%lld",&d);
    sum = sum + d;
    if(max < d)max=d;
    if(min > d)min=d;
    n = n-1;}
  printf("%lld %lld %lld\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 600
package main

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

//=====I/O=====

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

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

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n,t := scanInt(), scanInt()

	d := make(dishes, n)

	for i := 0; i < n; i++ {
		d[i] = dish{scanInt(), scanInt()}
	}

	sort.Sort(d)

	dp := [3001][6001]int{}

	for i := 1; i < n+1; i++ {
		for j := 0; j < t+3001; j++ {
			if j-d[i-1].a < 0 || j-d[i-1].a >= t {
				dp[i][j] = dp[i-1][j]
				continue
			}
			dp[i][j] = max(dp[i-1][j-d[i-1].a]+d[i-1].b, dp[i-1][j])
		}
	}

	ans := 0

	for i := 0; i < 3001; i++ {
		ans = max(ans, dp[n][t+i])
	}

	fmt.Println(ans)
}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}

type dish struct {
	a int
	b int
}

type dishes []dish

func (a dishes) Len() int           { return len(a) }
func (a dishes) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a dishes) Less(i, j int) bool { return a[i].a < a[j].a }


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

int main() {
  int A,B,ans=-1;
  cin >> A >> B;
  for(int i=0;i<100000;i++){
    if((2*i)/25==A&&i/10==B){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n = int(input())
if n < 600:
    print(8)
elif n < 800:
    print(7)
elif n < 1000:
    print(6)
elif n < 1200:
    print(5)
elif n < 1400:
    print(4)
elif n < 1600:
    print(3)
elif n < 1800:
    print(2)
else:
    print(1)


Measured memory_bytes: 68852
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007


int main() {
  string s,t;
  cin >> s;

  for(int i=0;i < s.size();i +=2)
    t.push_back(s.at(i));

  cout << t << endl;

}


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

int main(){
  ll x,y;
  cin>>x>>y;
  ll l=min(x,y);
  ll a= x+y;
  if(a%2!=0)
    cout<<"IMPOSSIBLE";
    else{
      ll ans= a/2;
      cout<<ans;
    }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);

 int main(){
   int H, W, ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8, ans, a, b, c, d;
   cin >> H >> W;
   if(H%3 == 0 || W%3 == 0)
     ans = 0;
   else {a = W/3; b = (W+3)/3; c = H/3; d = (H+3)/3;
   ans1 = max({H*a, (W-a)*(H/2), (W-a)*(H - (H/2))}) - 
              min({H*a, (W-a)*(H/2), (W-a)*(H - (H/2))});
   ans2 = max({H*b, (W-b)*(H/2), (W-b)*(H - (H/2))}) - 
              min({H*b, (W-b)*(H/2), (W-b)*(H - (H/2))});
   ans3 = max({W*c, (H-c)*(W/2), (H-c)*(W - (W/2))}) - 
              min({W*c, (H-c)*(W/2), (H-c)*(W - (W/2))});
   ans4 = max({W*d, (H-d)*(W/2), (H-d)*(W - (W/2))}) - 
              min({W*d, (H-d)*(W/2), (H-d)*(W - (W/2))});
   ans5 = abs(H*a - H*(W-2*a));
   ans6 = abs(H*b - H*(W-2*b)); 
   ans7 = abs(W*c - W*(H-2*c));
   ans8 = abs(W*d - W*(H-2*d));
   ans = min({ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8});}
   cout << ans << endl;
 }
     
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005,INF=1e9;
namespace flows{
	const int N=100005*2,M=N*2;
	struct Edge{
		int x,y,nxt,cap;
		Edge(){}
		Edge(int _x,int _y,int _nxt,int _cap){
			x=_x,y=_y,nxt=_nxt,cap=_cap;
		}
	}e[M];
	int n,S,T,cnt;
	int fst[N],cur[N],dis[N];
	void clear(int _n,int _S,int _T){
		n=_n,S=_S,T=_T,cnt=1;
		clr(fst);
	}
	void Add(int x,int y,int cap){
		e[++cnt]=Edge(x,y,fst[x],cap),fst[x]=cnt;
		e[++cnt]=Edge(y,x,fst[y],0),fst[y]=cnt;
	}
	int bfs(){
		static queue <int> q;
		For(i,1,n)
			dis[i]=0;
		dis[S]=1;
		q.push(S);
		while (!q.empty()){
			int x=q.front();
			q.pop();
			for (int i=fst[x];i;i=e[i].nxt){
				int y=e[i].y;
				if (e[i].cap&&!dis[y]){
					dis[y]=dis[x]+1;
					q.push(y);
				}
			}
		}
		return dis[T]!=0;
	}
	int dfs(int x,int Lim){
		if (x==T||!Lim)
			return Lim;
		int rem=Lim;
		for (int &i=cur[x];i;i=e[i].nxt){
			int y=e[i].y;
			if (dis[x]+1==dis[y]&&e[i].cap){
				int d=dfs(y,min(rem,e[i].cap));
				rem-=d,e[i].cap-=d,e[i^1].cap+=d;
				if (!rem)
					break;
			}
		}
		return Lim-rem;
	}
	int Dinic(){
		int res=0;
		while (bfs()){
			For(i,1,n)
				cur[i]=fst[i];
			res+=dfs(S,INF);
		}
		return res;
	}
}
int n,c=0;
int p[N],q[N];
int x[N],y[N];
int main(){
	n=read();
	For(i,1,n)
		p[i]=read()+1;
	For(i,1,n)
		q[i]=read()+1;
	For(i,1,n){
		if (x[i])
			continue;
		c++;
		for (int j=i;!x[j];j=p[j])
			x[j]=c;
	}
	For(i,1,n){
		if (y[i])
			continue;
		c++;
		for (int j=i;!y[j];j=q[j])
			y[j]=c;
	}
	int S=c+1,T=S+1;
	flows::clear(T,S,T);
	int ans=0;
	For(i,1,n){
		if (i==p[i]&&i==q[i])
			ans++;
		else if (i==p[i]&&i!=q[i])
			flows::Add(S,y[i],1);
		else if (i==q[i]&&i!=p[i])
			flows::Add(x[i],T,1);
		else if (p[i]!=q[i])
			flows::Add(x[i],y[i],1);
		else {
			flows::Add(x[i],y[i],1);
			flows::Add(y[i],x[i],1);
		}
	}
	ans+=flows::Dinic();
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 10240
n = int(input())

for _ in range(n):
    balllist = list(map(int, input().split()))
    leftlist = []
    rightlist = []

    for i, ball in enumerate(balllist):
        if i == 0:
            leftlist.append(ball)
            continue
        if leftlist[-1] < ball:
            leftlist.append(ball)
        elif rightlist == [] or rightlist[-1] < ball:
            rightlist.append(ball)
        else:
            print("NO")
            break
    else:
        print("YES")



Measured memory_bytes: 5592
import java.util.Objects;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();

        String[] c = new String[n];

        int left = 0;
        int right = 0;

        c[0] = str.substring(0, 1);
        for (int i = 1; i < n; i++) {
            String tmp = str.substring(i, i + 1);
            if((Objects.equals(tmp, "E"))){
                right++;
            }
            c[i] = tmp;

        }

        long min = right;
        for (int i = 1; i < n; i++) {
            if(Objects.equals(c[i - 1], "W")) {
                left++;
            }

            if(Objects.equals(c[i], "E")) {
                right--;
            }

            if(left + right < min){
                min = left + right;
            }
        }

        System.out.println(min);
    }
}


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

int main() {
    int n,k;
    cin>>n>>k;
    int l[n];
    for(int i=0;i<n;++i) cin>>l[i];
    sort(l,l+n,greater<int>());
    int s=0;
    for(int j=0;j<k;++j){
        s+=l[j];
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
const int maxn = 1e5 + 5;
int a[maxn];

int main(){
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
		#if __cplusplus >= 201103L
		auto start = steady_clock::now();
		#endif
	#endif
	int n = read();
	rep(i, 1, n) a[i] = read();
	sort(a + 1, a + 1 + n);
	if (n & 1) {
		puts("0");
		return 0;
	}
	int l = n / 2, r = n / 2 + 1;
	if (a[l] == a[r]) {
		puts("0");
		return 0;
	}
	int ans = 0;
	for (int i = a[l] + 1; i <= a[r]; ++i) {
		++ans;
	}
	cout << ans << endl;


	#ifdef LOCAL
		#if __cplusplus >= 201103L
		auto end = steady_clock::now();
		duration<double> time_span = duration_cast<duration<double>>(end - start);;
		printf("Total time: %.6fs\n", time_span.count());
		#endif
	#endif
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n;
	scanf("%d", &n);
	for (int x = 0; x < n; x++) {
		for (int y = x + 1; y < n; y++) {
			int k = 0;
			while((((x ^ y) >> k) & 1) == 0) k++;
			printf("%d ", k + 1);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    if(n % 2 == 1){
        cout << 0;
    }
    else{
        ll ans = 0;
        ll now = 10;
        now = 10;
        while(now <= n){
            ans += n / now;
            now *= 5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]

ok = [True] * (N + 1)
for a, b in X:
    ok[a] &= H[a - 1] > H[b - 1]
    ok[b] &= H[a - 1] < H[b - 1]

print(sum(ok[1:]))


Measured memory_bytes: 97088
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





















int main(){
    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    vector<pair<double, ll>> r(n);
    REP(i, n){
        cin >> x[i] >> y[i];
        double res = atan2(y[i], x[i]);
        if(res < 0){
            res = 2.0 * acos(-1) + res;
        }
        r[i] = {res, i};
    }
    sort(r.begin(), r.end());
    long double ans = 0.0;
    REP(i, n){
        REP(j, n){
            ll sx = 0, sy = 0;
            if(i <= j){
                for(ll k = i; k <= j; k++){
                    sx += x[r[k].second];
                    sy += y[r[k].second];
                }
            }
            else{
                for(ll k = i; k <= j + n; k++){
                    sx += x[r[k % n].second];
                    sy += y[r[k % n].second];
                }
            }
            ans = max(ans, sqrt((long double)(sx * sx + sy * sy)));
        }
    }
    printf("%.12Lf\n", ans);
}

Measured memory_bytes: 768
while True:
    r = str(input())
    if r == '0':
        break
    r = r[1:]
    ten = [r.count('A'),r.count('B')]
    if ten[0] > ten[1]:
        ten[0] += 1
    else:
        ten [1] += 1
    print(ten[0],ten[1])


Measured memory_bytes: 5556
#!/usr/bin/env python3
# coding: utf-8

# def debug(arg):
#     if __debug__:
#         pass
#     else:
#         import sys
#         print(arg, file=sys.stderr)

def main():
    N, *A = map(int, open(0).read().split())

    b = dict.fromkeys(range(1, N + 1), 0)

    for i, a in enumerate(A, 1):
        b[a] += 1
    
    for bb in b.values():
        print(bb)

if __name__ == "__main__":
    main()

Measured memory_bytes: 40244
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  int a[3]{};
  for (char &c: S) ++a[c-'a'];
  sort(a,a+3);
  cout << (a[2] - a[0] < 2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3732
function Main(input){
	input = input.split("\n");
  var X = input[0].split(" ")[2];
  var Y = input[0].split(" ")[3];
  var maxX = Math.max(...input[1].split(" ").map(a=>~~a));
  var minY = Math.min(...input[2].split(" ").map(a=>~~a));
  
  
  for(var z = Math.max(maxX,X) + 1 ; z <= Math.min(minY,Y); z++){
  	return "No War";
  }
  return "War";
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
5 3 6 8
-10 3 1 5 -100
100 6 14
`);

Measured memory_bytes: 7372
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep0(i, n) for(int i = 0; i < (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    for(int i=1; i<=5; ++i){
        int n;
        cin >> n;
        if(n == 0){
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3692
main = do
    l <- getLine
    let (a:b:[]) = map read $ words l :: [Int]
    putStrLn $ unwords [show (area a b) , show (perimeter a b)]

area :: Int -> Int -> Int
area a b = a * b

perimeter :: Int -> Int -> Int
perimeter a b = 2 * (a + b)



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

 const int N=100005;
 const int inf=1e18;
 const double eps=1e-9;
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
map<int,string>m;
vector<int>adj[10];
int c=1;
void form(string s,int l){
    if(l==0){
        m[c]=s;
        c++;
        return;
    }
    if(s.size()==0){
        for(int x=1;x<=9;x++){
            char c1=48+x;
            
            form(s+c1,l-1);
        }
    }else{
        int p=s[s.size()-1]-'0';
        for(int x=0;x<adj[p].size();x++){
            char re=adj[p][x]+48;
            form(s+re,l-1);
        }
    }

}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int k;
    cin>>k;
    for(int x=0;x<=9;x++){
        for(int w=0;w<=9;w++){
            if(abs(w-x)<=1){
                adj[x].pb(w);
            }
        }
    }
    for(int x=0;x<=9;x++){
        sort(adj[x].begin(),adj[x].end());
    }
    // int c=1;
    for(int x=1;x<=11;x++){
        string s="";
        // char c=48+x;
        // s+=""
        form(s,x);
    }

    cout<<m[k];






	
return 0;
}


Measured memory_bytes: 72576
/*
    Problem 62
    https://atcoder.jp/contests/abc079/tasks/abc079_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int> > mapping(10, vector<int>(10, INF));
/* function */
void floyd() {
    for (int k = 0; k <= 9; k++) {
        for (int i = 0; i <= 9; i++) {
            if (mapping[i][k] == INF) continue;
            for (int j = 0; j <= 9; j++) {
                if (mapping[k][j] == INF) continue;
                mapping[i][j] = min(mapping[i][j], mapping[i][k] + mapping[k][j]);
            }
        }
    }
}
/* main */
int main(){
    int H, W;
    cin >> H >> W;
    for (int i = 0; i <= 9; i++) for (int j = 0; j <= 9; j++) cin >> mapping[i][j];

    floyd();

    int c;
    int ans = 0;
    for (int i = 0 ; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> c;
            if (c == -1) continue;
            ans += mapping[c][1];
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 1e3 + 2;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    string s;
    cin >> s;
    int cnt = 0, type = s[0] == '1' ? 1 : 0;
    for (int i = 1; i < (int)s.size(); i++) {
        if (s[i] == '1') {
            if (type == 1)
                cnt++, type = 0;
            else type = 1;
        }
        else if (s[i] == '0') {
            if (type == 0)
                cnt++, type = 1;
            else type = 0;
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3728
import sys
input = sys.stdin.readline
def waru(N,num):
  cnt = 0
  while N%num==0:
    N //= num
    cnt += 1
  return cnt
def solve():
  N = int(input())
  num = [[0]*101 for _ in range(101)]
  lis = [0]*N
  for i in range(N):
    a = int(round(float(input())*10**9))
    p,q = waru(a,2)-9-50,waru(a,5)-9-50
    num[p][q] += 1
    lis[i] = [p,q]
  cum2 = [[0]*101 for _ in range(101)]
  for i in range(99,-1,-1):
    for j in range(99,-1,-1):
      cum2[i][j] = cum2[i+1][j]+cum2[i][j+1]-cum2[i+1][j+1]+num[i][j]
  ans = 0
  for i in range(N):
    p,q = lis[i]
    x,y = p+50,q+50
    p = -x-50
    q = -y-50
    ans += cum2[p][q]
    if x>=0 and y>=0:
      ans -= 1
  return ans//2
print(solve())

Measured memory_bytes: 95676
'use strict'

function main(input) {
    input = input.split(' ').map(v=>~~v)
        
    let start = input[0]
    let end = input[1]
    let limit = input[2]
    let set = new Set()
    let ans = ''

    let i=0

    while(limit > i )
    {  
        let tmp = start + i
        if(tmp <= end ){
            set.add(tmp)
        } 
        i++;
    }

    i=0
    while(limit > i )
    {  
        let tmp = end - i
        if(tmp >= start ){

            set.add(tmp)
        } 
        i++;
    }
    let ary = [...set].sort((a,b)=>a-b)
    for( let v in ary)
    {
        ans += ary[v]+'\n'
    }
    console.log(ans)
}

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

Measured memory_bytes: 7756
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

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

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

	sort(a.begin(), a.end(), greater<double>());

	int l = a[0] / (k + 1);
	int r = a[0];
	bool f = false;
	while (l < r) 
	{
		int m = (l + r) / 2;

		ll re = k;
		for (int i = 0; i < n; i++)
		{
			if (a[i] > m)
			{
				re -= ceil(a[i] / m) - 1;
				if (re < 0) break;
			}
		}

		if (re >= 0) {
			r = m;
			f = true;
		}
		else {
			l = m + 1;
			f = false;
		}
	}

	if (f) {
		cout << setprecision(20) << r << endl;
		return 0;
	}
	else {
		cout << setprecision(20) << l << endl;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<vector<int>> txy(n, vector<int>(3));
	rep(i, n) rep(j, 3) cin >> txy[i][j];
	bool ans = true;
	int t = 0;
	int x = 0;
	int y = 0;

	rep(i, n) {
		int dt = txy[i][0] - t;
		int dx = abs(txy[i][1] - x);
		int dy = abs(txy[i][2] - y);
		if (dt < dx + dy) ans = false;
		if ((dx + dy) % 2 != dt % 2) ans = false;
		t = txy[i][0];
		x = txy[i][1];
		y = txy[i][2];
	}

	if (ans) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 5760