akhauriyash/Code-Regression huggingface dataset:
S=list(map(int,input().split("/")))
if S[0]>2019:
    print("TBD")
elif S[0]<2019:
    print("Heisei")
else:
    if S[1]<4:
        print("Heisei")
    elif S[1]>4:
        print("TBD")
    else:
        if S[2]<=30:
            print("Heisei")
        else:
            print("TBD")

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



int main() 
{
  ll N,Y; cin>>N>>Y;
  rep(a,N+1)
  {
    rep(b,N+1)
    {
      if(a+b<=N&&9*a+4*b==Y/1000-N)
      {
        cout<<a<<" "<<b<<" "<<N-a-b<<endl;
        return 0;
      }
    }
  }  
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
  public static void main(String[] arg){
    int n;
    int [][][] room = new int[4][3][10];
    int b,f,r,v;

    for(int i=0; i<room.length; i++)
        for(int j=0; j<room[0].length; j++)
            for(int k=0; k<room[0][0].length; k++)
                room[i][j][k] = 0;

    Scanner in = new Scanner(System.in);

    n = in.nextInt();

    for(int i=0; i<n; i++){
        in.nextLine();
        b = in.nextInt();
        f = in.nextInt();
        r = in.nextInt();
        v = in.nextInt();

        room[b-1][f-1][r-1] += v;
    }

    for(int i=0; i<room.length; i++){
        for (int j=0; j<room[0].length; j++) {
            for(int k=0; k<room[0][0].length; k++){
                System.out.print(" " + room[i][j][k]);
            }
            System.out.println();
        }
        if(i <room.length-1)
            System.out.println("####################");
    }
  }
}

Measured memory_bytes: 31052
import sys
while True:
    (H, W) = [int(i) for i in sys.stdin.readline().split()]
    if H == W == 0:
        break
    print("#" * W)
    print(("#" + "." * (W - 2) + "#" + "\n") * (H - 2), end="")
    print("#" * W + "\n")

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

int A[3];

int main(void) {

	for (int i = 0; i < 3; i++)
	{
		std::cin >> A[i];
	}

	for (int i = 0; i < 2; i++)
	{
		for (int j = i + 1; j < 3; j++)
		{
			if (A[i] > A[j]) {
				int tmp = A[i];
				A[i] = A[j];
				A[j] = tmp;
			}
		}		
	}

	std::cout << A[1] - A[0] + A[2] - A[1] << std::endl;

	return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[2]);
            if (s[1][0] == '+')
            {
                Console.WriteLine(a + b);
            }
            else Console.WriteLine(a-b);
        }
    }
}

Measured memory_bytes: 13140
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()

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

	sort.Ints(d)

	ans := d[n/2] - d[n/2-1]

	fmt.Println(ans)
	
}


Measured memory_bytes: 2048
def main():
    S = input()
    target = 753
    minimum_diff = 0
    try:
        for i in range(len(S)):
            num = int(S[i] + S[i+1] + S[i+2])
            diff = abs(target - num)
            if(i==0 or diff<minimum_diff):
                minimum_diff = diff
    except:
        pass
    print(minimum_diff)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import heapq

n = int(input())
ll, rr = [], []
task = []
ans = 0
for _ in range(n):
    l, r = map(int, input().split())
    heapq.heappush(ll, -l)
    heapq.heappush(rr, r)
    task.append([l, r])
maxl1, minr1 = -heapq.heappop(ll), heapq.heappop(rr)
maxl2, minr2 = -heapq.heappop(ll), heapq.heappop(rr)
for i in range(n):
    ma = maxl1 if not task[i][0] == maxl1 else maxl2
    mi = minr1 if not task[i][1] == minr1 else minr2
    ans = max(ans, task[i][1] - task[i][0] + max(0, mi - ma + 1) + 1)
for k in range(1):
    task.sort(key = lambda x : x[k])
    score = [0] * (n - 1)
    l1, r1 = task[0][0], task[0][1]
    l2, r2 = task[n - 1][0], task[n - 1][1]
    i, j = 0, n - 1
    for _ in range(n - 1):
        l1, r1 = max(l1, task[i][0]), min(r1, task[i][1])
        l2, r2 = max(l2, task[j][0]), min(r2, task[j][1])
        j -= 1
        score[i] += max(0, r1 - l1 + 1)
        score[j] += max(0, r2 - l2 + 1)
        i += 1
ans = max(ans, max(score))
print(ans)

Measured memory_bytes: 32644
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        double pai=3.141592653589;
        vector<int>ar(3);
        for(auto&e:ar){
                cin>>e;
        }
        sort(ar.begin(),ar.end());
        cout<<ar[0]<<" "<<ar[1]<<" "<<ar[2]<<endl;
        return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int a[26];
    int b[26];
    for(int i=0;i<26;i++){
        a[i]=b[i]=0;
    }
    for(int i=0;i<s.length();i++){
        a[s[i]-'a']++;
    }
    for(int i=0;i<t.length();i++){
        b[t[i]-'a']++;
    }
    sort(a,a+26);
    sort(b,b+26);
    bool flag=true;
    for(int i=0;i<26;i++){
        if(a[i]!=b[i]){flag=false;}
    }
    if(flag){cout<<"Yes"<<endl;}
    else cout<<"No"<<endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(var,start,end) for(int var=start; var<end; var++)
#define REP(var,cnt) FOR(var,0,cnt)

int main(void) {

	unsigned long X;
	cin >> X;
	
	int aa = 0;
	for(int i=X; i>0; i/=10) {
		
		aa += (i%10);
	}
	
	if ( X % aa == 0 ) {
		cout << "Yes" <<endl;
	
	}else{
		cout << "No"<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

vector<int> st[404040];
const int zero = 202020;

int main(){
    fastcin();

    string s;
    cin >> s;
    int n = s.size();
    int p = zero;
    st[p].push_back(1);
    string t = "";
    LL ans = 0;
    rep(i, n){
        if(s[i] == '('){
            p++;
            st[p].push_back(1);
            t += s[i];
        }else if(s[i] == ')'){
            p--;
            if(st[p].empty()) st[p].push_back(0);
            ans += st[p].back();
            st[p].back()++;
            t += s[i];
        }else{
            char dl = t.back();
            t = t.substr(0, t.size()-1);
            if(dl == '('){
                if(st[p].back() == 1){
                    st[p].pop_back();
                }else{
                    st[p].back()--;
                }
                p--;
            }else{
                st[p].back()--;
                ans -= st[p].back();
                p++;
            }
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 19208
#include <cmath>
#include <string.h>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_nested(i, s, n) for (int i = s; i <= n; i++)
#define ll long long
#define ull unsigned long long

const int N = 500;
const ll INF = 1000000007;

using namespace std;

template <class T>
T limit(T n, T k) {
	return (n > k) ? k : n;
}

template <class T>
T has_order(T a, T b, T c) {
	return (b > a && b < c) || (b < a && b >c);
}

int main() {
	int n, k;
	vector<int> v;
	
	cin >> n;
	
	rep(i, n) {
		cin >> k;
		v.push_back(k);
	}
	
	k = 0;
	
	for (int i = 1; i < n - 1; i++) {
		k += has_order(v[i - 1], v[i], v[i + 1]);
	}
	
	cout << k << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
    double r;
    cin>>r;
    double length=2*r*M_PI;
    double area=M_PI*r*r;
    cout<<fixed;
    cout<<setprecision(30)<<area<<" "<<setprecision(30)<<length<<endl;
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    while(n)
    {
        ans++;
        n/=k;
    }
    cout<<ans;
}


Measured memory_bytes: 256
H = int(input())

num = 0
while True:
    if H == 1:
        break
    else:
        if H % 2 == 0:
            H = H // 2
            num += 1
        else:
            H = (H - 1) // 2
            num += 1
print(pow(2, num + 1) - 1)

Measured memory_bytes: 2940
from collections import defaultdict

n, p = map(int, input().split())
s = input()

if p in (2, 5):
    if p == 2:
        ok_list = [i for i in range(10)][::2]
    else:
        ok_list = [0, 5]
    ans = 0
    for i in range(n):
        if int(s[i]) in ok_list:
            ans += i+1
    print(ans)
else:
    dd = defaultdict(int)
    dd[0] = 1
    prev = 0

    for i in range(n-1, -1, -1):
        d = int(s[i]) * pow(10, n-i, p)
        prev = (prev + d) % p
        dd[prev] += 1

    print(sum(v*(v-1)//2 for v in dd.values()))

Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	string S; cin >> S;
	vector<char> acgt = {'A', 'C', 'G', 'T'};
	int res = 0;
	REP(i, S.size()) {
		FOR(j, i, S.size()) {
		    bool isAcgt = true;
			FOR (k, i, j + 1) {
				bool ok = false;
				REP(l, acgt.size()) {
					if (acgt[l] == S[k]) ok = true;
				}
				if (!ok) isAcgt = false;
			}
			if (isAcgt) res = max(res, j - i + 1);
		}
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

int main() {
    int n;cin>>n;
    vector<string> s(n);
    for (auto& v : s) cin>>v;
    
    int m;cin>>m;
    vector<string> t(m);
    for (auto& v : t) cin>>v;
    
    int res = 0;
    
    for (const auto& v : s) {
        int x = count(all(s), v) - count(all(t), v);
        res = max(res, x);
    }
    
    cout << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  int M = 101, zero = 50 * N;

  vector<vector<ll>> dp(N + 1, vector<ll>(M * N + 1, 0));
  dp[0][zero] = 1;
  for (int i = 0; i < (int)N; ++i) for (int j = 0; j < (int)N * M + 1; ++j) {
    dp[i + 1][j] = dp[i][j];
    int pj = j - x[i];
    if (0 <= pj && pj <= N * M) dp[i + 1][j] += dp[i][pj];
  }

  cout << dp[N][zero] - 1 << endl;
  return 0;
}


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

using namespace std;

vector<stack<int> > st;

void f0()
{
    int p1,p2;
    cin>>p1>>p2;

    st[p1].push(p2);
}

void f1()
{
    int p;
    cin>>p;

    if(!st[p].empty())
        cout<<st[p].top()<<endl;
}

void f2()
{
    int p;
    cin>>p;

    if(!st[p].empty()) st[p].pop();
}

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

    cin>>n>>q;

    st.resize(n);

    while(q--)
    {
        int op;
        cin>>op;

        switch(op)
        {
            case 0:f0();break;
            case 1:f1();break;
            case 2:f2();break;
        }
    }


    return 0;
}



Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
const int YYQ=1e9+7;
int h,w,dp[1001][1001];
char g[1001][1001];
const int dx[]={0,0,-1};
const int dy[]={0,-1,0};
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++)	for(int j=1;j<=w;j++)	cin>>g[i][j];
	dp[1][1]=1;
	for(int i=1;i<=h;i++)	for(int j=1;j<=w;j++){
		if(g[i][j]=='#')	continue;
		for(int d=1;d<=2;d++)
			if(g[i+dx[d]][j+dy[d]]=='.')
				dp[i][j]=(dp[i][j]+dp[i+dx[d]][j+dy[d]])%YYQ;
	}
	cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 5120
import sys
x, y, a, b, c = map(int, sys.stdin.readline().split())
p = map(int, sys.stdin.readline().split())
q = map(int, sys.stdin.readline().split())
r = map(int, sys.stdin.readline().split())

p = sorted(p, reverse=True)[:x]
q = sorted(q, reverse=True)[:y]
r = sorted(r, reverse=True)
final = p + q + r
final = sorted(final, reverse=True)
print(sum(final[:x+y]))

Measured memory_bytes: 101416
x = [int(x) for x in input().split()]
N = x[0]
A = x[1]
B = x[2]
def check(x):
  ans = 0
  while x >= 10:
    ans += x%10
    x = x//10  
  ans += x
  return ans
ans1 = 0
for i in range(N):
  i = i+1
  if (check(i) >= A) & (check(i) <= B):
    ans1 += i

print(ans1)

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

int main(){
    int N, L, Q;
    cin >> N;
    vector<int> X(N);
    for(int i=0; i<N; i++) cin >> X[i];
    cin >> L >> Q;

    vector<vector<int>> nxt(17, vector<int>(N));
    int r = 0;
    for(int l=0; l<N; l++){
        while(r<N && X[r]-X[l] <= L) r++;
        nxt[0][l] = r-1;
    }
    for(int k=1; k<17; k++) for(int i=0; i<N; i++) nxt[k][i] = nxt[k-1][nxt[k-1][i]];

    for(int i=0; i<Q; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a > b) swap(a, b);
        int ans = 0;
        for(int k=16; k>=0; k--) if(nxt[k][a] < b){
            ans += 1<<k;
            a = nxt[k][a];
        }
        cout << ans+1 << endl;
    }
}

Measured memory_bytes: 7928
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    long long res = N / K;
    long long sum = res * res * res;

    if (K % 2 == 1) {
        cout << sum << endl;
    }
    else {
        if (N - (K / 2) >= 0) {
            long long res2 = ((N - (K / 2)) / K) + 1;
            sum += res2 * res2 * res2;
            cout << sum << endl;
        }
        else {
            cout << sum << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

bool isIn(long xl, long yl, long xr, long yr, P target) {
  bool res = true;
  res = res && xr >= target.first;
  res = res && yr >= target.second;
  res = res && xl <= target.first;
  res = res && yl <= target.second;
  return res;
}

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

  int n, m;
  cin >> n >> m;

  vector<P> points(n);
  vector<long> xs(n);
  vector<long> ys(n);

  rep(i, n) {
    long x, y;
    cin >> x >> y;
    points[i] = {x, y};
    xs[i] = x;
    ys[i] = y;
  }

  sortv(xs);
  sortv(ys);

  ll res = INF*INF*4;

  rep(il, n-1) rep(jl, n-1) {
    for(int i = il+1; i < n; i++) {
      for(int j = jl+1; j < n; j++) {
        ll size = (xs[i] - xs[il]) * (ys[j] - ys[jl]);
        if (size == 0) continue;
        int tmp = 0;
        rep(k, n) {
          if (isIn(xs[il], ys[jl], xs[i], ys[j], points[k])) tmp++;
        }
        if (tmp >= m) {
          res = min(res, size);
        }
      } 
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  double n,m;
  cin >>n>>m;
  cout << fixed << setprecision(6);
  vector<double> A(n);
  for(int i=0;i<n;i++) cin >>A[i];
  double sum=0;
  for(int i=0;i<n;i++) sum+=A[i];
  
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  double x = sum/(4*m);

  if(A[m-1] >= x) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int x,y;
	cin>>x>>y;
	int mx=x*4,mn=x*2;
	if(!(y&1) && (y>=mn && y<=mx))
		cout<<"Yes\n";
	else cout<<"No\n";
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[100];	
	char p[100];	
	char str[100];	
	int i;
	int j;
	int judge = 0;

	for (i = 0; i < 100; i++)
	{
		s[i] = '\0';
		p[i] = '\0';
		str[i] = '\0';
	}

	//文字列sを入力する
	scanf("%s", s);
	//fgets(s, 100, stdin);
	//文字列pを入力する
	scanf("%s", p);
	//fgets(p, 100, stdin);

	//文字列sが文字列pより短ければNoと出力する
	if (strlen(s) < strlen(p))
	{
		printf("No\n");
	}
	else
	{
		for (i = 0; i <= strlen(s); i++)
		{
			for (j = 0; j < strlen(p); j++)
			{
				str[j] = s[(i + j) % strlen(s)];
			}
			//s[i]とp[0]が一致すれば
			if (strcmp(str, p) == 0)
			{
				judge = 1;
				break;
			}
			else
			{
				judge = 0;
			}

		}

		printf((judge == 1) ? "Yes\n" : "No\n");
	}

	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  ll ans = 0;
  ll tmp = S[0] - '0';
  // cout << tmp << endl;
  ll size = S.size();
  for(ll i = 0; i < pow(2, size - 1); i++) {
    ll tmp = S[0] - '0';
    for(ll j = 0; j < size - 1; j++) {
      if(i & (1 << j)) {
        ans += tmp;
        tmp = S[j + 1] - '0';
      } else {
        tmp *= 10;
        tmp += S[j + 1] - '0';
      }
    }
    ans += tmp;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    def cmb(n, r, mod):#コンビネーションの高速計算　
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    N = 10**6
    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 )

    X,Y=map(int,input().split())
    if (2*Y-X)%3!=0 or (2*X-Y)%3!=0:
        print(0)
    else:
        s=(2*Y-X)//3
        t=(2*X-Y)//3
        if s<0 or t<0:
            print(0)
        else:
            print(cmb(s+t,t,mod))

if __name__ == '__main__':
    main()

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int n;
  cin >> n;
  vector<int> xs(n), ys(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> ys[i];
  }

  auto process_pattern_fn = [&](int p) -> int {
    vector<int> flags(n);
    for (int i = 0; i < n; i++) {
      if (p & (1 << i)) flags[i] = 1;
    }

    vector<int> vs(n);
    for (int i = 0; i < n; i++) {
      if (flags[i]) vs[i] = ys[i];
      else vs[i] = xs[i];
    }
    sort(vs.begin(), vs.end());

    vector<int> used(n);
    vector<int> indexes(n, -1);
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        if (used[i]) continue;
        if (abs(k - i) % 2 != flags[i]) continue;
        int v = flags[i] ? ys[i] : xs[i];
        if (vs[k] != v) continue;
        used[i] = 1;
        indexes[k] = i;
        break;
      }
      if (indexes[k] == -1) return -1;
    }

    int r = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (indexes[i] > indexes[j]) r++;
      }
    }
    return r;
  };

  int ans = INT_MAX;
  for (int p = 0; p < 1 << n; p++) {
    int r = process_pattern_fn(p);
    // cout << p << " " << r << endl;
    if (r >= 0) {
      UpdateMin(ans, r);
    }
  }
  if (ans == INT_MAX) {
    ans = -1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GetEverything | diff GetEverything.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GetEverything.cpp && ./a.out

/*
 
 9/28/2019
 
 5:32-
 
 */

const int MAX_N=12;
const int MAX_M=1e3+1;
LL A[MAX_M];
int B[MAX_M];
int N,M;

const LL Inf=1e10;
LL memo[1<<MAX_N];
LL f(int mask) {
  if(mask==(1<<N)-1) return 0;
  LL &res=memo[mask];
  if(res>=0) return res;
  res=Inf;
  REP(i,M) {
    int mask2=mask|B[i];
    if(__builtin_popcount(mask2)>__builtin_popcount(mask)) {
      SMIN(res,f(mask2)+A[i]);
    }
  }
//  dump(mask,res);
  return res;
}
void solve() {
  MINUS(memo);
  LL res=f(0);
  if(res>=Inf) res=-1;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,M) {
    int cnt;
    cin>>A[i]>>cnt;
    int mask=0;
    REP(j,cnt) {
      int x; cin>>x;
      --x;
      mask|=1<<x;
    }
    B[i]=mask;
  }
  solve();
  
  return 0;
}


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

using namespace std;

int main(){
    int N, Q;
    cin >> N >> Q;
    
    string S;
    cin >> S;

    vector<int> AC(N);
    int count = 0;
    for(int i = 0; i < N; i++){
        if (S[i] =='A' && S[i+1] == 'C') {
            count += 1;
        }
        AC[i] = count;
    }
    
    vector<int> ans(Q);

    for(int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        ans[i] = AC[r - 2] - AC[l - 2]; 
    }
    
    for(int i = 0; i < Q; i++){
        cout << ans[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint n; cin >> n;
  for (lint a = 1; a < 3501; a++) for (lint b = 1; b < 3501; b++) {
    if ((4 * a * b - n * (a + b)) and (n * a * b) % (4 * a * b - n * (a + b)) == 0) {
      lint c = n * a * b / (4 * a * b - n * (a + b));
      if (c > 0) return cout << a << ' ' << b << ' ' << c << '\n', 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
ll ls1[Max], ls2[Max],ls3[Max],sum[Max];

int main()
{
	PRE;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)cin >> ls1[i];
	for (int i = 1;i <= n;i++)cin >> ls2[i];
	for (int i = 1;i <= n;i++)cin >> ls3[i];
	sort(ls1 + 1, ls1 + 1 + n);
	sort(ls2 + 1, ls2 + 1 + n);
	for (int i = 1;i <= n;i++)
	{
		int g = lower_bound(ls1 + 1, ls1 + 1 + n, ls2[i]) - ls1-1;
		sum[i] = sum[i - 1] + lower_bound(ls1 + 1, ls1 + 1 + n, ls2[i]) - ls1-1;
	}
	ll res = 0;
	for (int i = 1;i <= n;i++)
	{
		res += sum[lower_bound(ls2 + 1, ls2 + n + 1, ls3[i]) - ls2-1];
	}
	cout << res;
}

Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a+b);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a-b);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;


void solve()
{
	int n;
	cin>>n;
	int ans=0;
	
	for(int i=1;i<n;i++)
	{
		ans+=((n-1)/i);
	}
	cout<<ans<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>

using namespace std;

int main()
{
	int H, W;

	while (true)
	{
		cin >> H >> W;
		
		if (H == 0 && W == 0)
			break;
		else
		{
			for (int i = 0; i < H; i++)
			{
				for (int j = 0; j < W; j++)
					cout << '#';

				cout << endl;
			}
			cout << endl;
		}
	}
}

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


int main() {
    int l, r, d;
    cin >> l >> r >> d;

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

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
//@sakshjha
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
const ll mod = 1000000007 ;
const ll N=500005;
int main()
{
    FAST
    ll t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n,m,k;
        cin>>n>>m>>k;
        ll a[n+5],b[m+5];
        for(i=0; i<n; i++)
            cin>>a[i];
        for(i=0; i<m; i++)
            cin>>b[i];
        for(i=1; i<n; i++)
            a[i]+=a[i-1];
        for(i=1; i<m; i++)
            b[i]+=b[i-1];
        ll lo=0;
        ll hi=n+m;
        ll ans=0;
        while(lo<=hi)
        {
            ll mi=(lo+hi)/2;
            ll tmp=0;
            for(j=mi; j>=0; j--)
            {
                if(j>n)
                    continue;
                if(mi-j>m)
                    continue;
                ll fir=0,sec=0;
                if(j>=1)
                    fir=a[j-1];
                if(mi-j>=1)
                    sec=b[mi-j-1];

                if(fir+sec<=k)
                {
                    tmp=1;
                    break;
                }
            }
            if(tmp)
            {
                ans=max(ans,mi);
                lo=mi+1;
            }
            else
                hi=mi-1;


        }
        cout<<ans<<"\n";

    }
    return 0;
}
/*ll pow (ll x, ll y, ll m)
{
    ll res=1;
    x=x%m;
    if(x==0)
        return 0;
    while(y>0)
    {
        if(y&1)
        {
            res*=x;
            res%=m;
        }
        y=y/2;
        x=(x*x)%m;
    }
    return res;
}*/


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

int main() {
  int a,b;
  cin >> a >> b;
  
  int count = 0;
  for(int i = a; i < b + 1; i++) {
    if(i%10 == i/10000 && (i/10)%10 == (i/1000)%10)
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

ll d[100][32000][2];
int t[32000];
ll sum[2][32000],tmp[2][32000];
int main(){
	int k,n;
	scanf("%d%d",&k,&n);
	int sq=(int)sqrt(k);
	fup(i,1,sq,1)t[i]=k/i-k/(i+1);
	if(k/sq==sq)t[sq]--;
	fup(i,1,sq,1)
	{
		d[n-1][i][0]=1;
		d[n-1][i][1]=1;
		sum[0][i]=(sum[0][i-1]+d[n-1][i][0])%MOD;
		sum[1][i]=(sum[1][i-1]+d[n-1][i][1]*t[i])%MOD;
	}
	fdn(N,n-2,0,1)
	{
		fup(i,1,sq,1)
		{
			d[N][i][0]=(sum[0][sq]+sum[1][sq]-sum[1][i-1]+MOD)%MOD;
			d[N][i][1]=sum[0][i];
			tmp[0][i]=(tmp[0][i-1]+d[N][i][0])%MOD;
			tmp[1][i]=(tmp[1][i-1]+d[N][i][1]*t[i])%MOD;
		}
		memcpy(sum,tmp,sizeof(sum));
	}
	ll ans=(sum[0][sq]+sum[1][sq])%MOD;
	printf("%lld",ans);
}

Measured memory_bytes: 51328
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; putInts [a*b, 2*(a+b)]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3596
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] ={ 1,0,-1,0 };
int dy[4] ={ 0,1,0,-1 };

int A, B, C;

signed main() {
	cin >> A >> B >> C;
	if(A > B) swap(A, B);
	if(A < C && C < B) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
s = input()

a_i = None
z_i = None
set_a = False

for i in range(len(s)):
    if (not set_a) and s[i] == 'A':
        a_i = i
        set_a = True
    if s[i] == 'Z':
        z_i = i
print(z_i - a_i + 1)

Measured memory_bytes: 3516
#include <algorithm>
#include <climits>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
 
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()
 
#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);}} premain;

#define MAX_N (100000)

static double MAX(double a, double b) {
  return ((a) > (b) ? (a) : (b));
}
static double MIN(double a, double b) {
  return ((a) < (b) ? (a) : (b));
}

//MINUS(0), STOP(1), PLUS(2)
double b_x_min[] = {INF, INF, INF};
double b_x_max[] = {-INF, -INF, -INF};
double b_y_min[] = {INF, INF, INF};
double b_y_max[] = {-INF, -INF, -INF};

int N;

static double calc_area(double time) {
  double xmin = INF;
  double xmax = -INF;
  double ymin = INF;
  double ymax = -INF;
  
  for (int i = 0; i < 3; i++) {
    double t = (double)(i)*time;
    xmin = MIN(xmin, b_x_min[i]+t);
    xmax = MAX(xmax, b_x_max[i]+t);
    ymin = MIN(ymin, b_y_min[i]+t);
    ymax = MAX(ymax, b_y_max[i]+t);
  }
  //print(xmax, xmin, ymax, ymin);
  
  return ((xmax - xmin) * (ymax - ymin));
}

int main() {
  cin >> N;
  
  REP(i, N) {
    int x, y;
    char d;
    cin >> x >> y >> d;
    int xmode, ymode;
    switch (d) {
      case 'R':
        xmode = 2;
        ymode = 1;
        break;
      case 'L':
        xmode = 0;
        ymode = 1;
        break;
      case 'U':
        xmode = 1;
        ymode = 2;
        break;
      case 'D':
        xmode = 1;
        ymode = 0;
        break;
      default:
        xmode = 0;
        ymode = 1;
        break;
    }
    
    b_x_min[xmode] = MIN(b_x_min[xmode], x);
    b_x_max[xmode] = MAX(b_x_max[xmode], x);
    b_y_min[ymode] = MIN(b_y_min[ymode], y);
    b_y_max[ymode] = MAX(b_y_max[ymode], y);
  }

  double* b_list[] = {b_x_min, b_x_max, b_y_min, b_y_max};
  vector<double> time;
  time.push_back(0.0);
  for (auto b : b_list) {
    double t_list[] = {b[0]-b[1], b[1]-b[2], (b[0]-b[2])/2};
    for (auto t : t_list) {
      if (0 <= t) {
        time.push_back(t);
      }
    }
  }
  double ans = INF*INF;
  for (auto t : time) {
    auto tmp = calc_area(t);
    ans = MIN(ans, tmp);
  }
  
  print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (!n) break;
    V<lint> a(n); for (auto&& e : a) cin >> e;
    lint s = accumulate(begin(a), end(a), 0LL);
    int res = 0;
    for (int i = 0; i < n; ++i) {
      res += n * a[i] <= s;
    }
    cout << res << '\n';
  }
}


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

using namespace std;
using ll = long long;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

// 0-based index, range inclusive.
template<class T> struct BIT {
    vector<T> as;
    void init(int n, T u = 0) { as.assign(n, u);}
    T sum(int s, int e) { return sum(e) - sum(s - 1);}
    T sum(int e) { T s = 0; for (; e >= 0; e = (e & e + 1) - 1) s += as[e]; return s; }
    void add(int p, T v) { for (; p < as.size(); p |= p + 1) as[p] += v; }
};

BIT<int> bit;

struct Prime {
    static const int N = 1000101;
    int pr[N + 1], is[N + 1], n;
    Prime() {
        int i, j, d;
        memset(is, 0, sizeof(is)), n = 0;
        for (i = 3, is[2] = 1; i <= N; i += 2) is[i] = 1;
        for (i = 3; i * i <= N; i += 2) if (is[i]) for (j = i * i, d = i << 1; j <= N; j += d) is[j] = 0;
        for (i = 2; i <= N; i++) if (is[i]) pr[n++] = i;
    }
    int size() { return n; }
    bool operator()(int k) { return is[k]; }
    int operator[](int k) { return pr[k]; }
};

Prime pr;


int main () {

    const int n = 111111;
    bit.init(n);
    for (auto k = 1; k < n; ++k) {
        if (pr(k) && pr((k + 1) >> 1)) {
            bit.add(k, 1);
        }
    }
    int Q = getint();
    while (Q--) {
        int a = getint(), b = getint();
        cout << bit.sum(a, b) << endl;
    }

    return 0;
}



Measured memory_bytes: 7168
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    x = int(input())
    a = x // 500
    b = x %500
    c = b // 5
    print(a*1000+c*5)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;

int main() {
  string s;
  cin>>s;
  if(s=="SUN") cout<<7<<endl;
  if(s=="MON") cout<<6<<endl;
  if(s=="TUE") cout<<5<<endl;
  if(s=="WED") cout<<4<<endl;
  if(s=="THU") cout<<3<<endl;
  if(s=="FRI") cout<<2<<endl;
  if(s=="SAT") cout<<1<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int i,j,n,u,k,m,v[N][N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)
      v[i][j]=0;
  }

  for(i=0;i<n;i++){
      scanf("%d",&u);
      scanf("%d",&k);
      u--;
      for(j=0;j<k;j++){
      scanf("%d",&m);
      m--;
      v[u][m]=1;
      }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",v[i][j]);
	if(j!=n-1) printf(" ");
    }
    printf("\n");
  }
  



  return 0;

}



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

int main(){
  
  long long int a;
  cin >>a;
  string ans ="";
  
  
  while (a!=0){
    
    if (a%2!=0){
      a--;
      ans ="1"+ans;
      
    }
    else {
      ans = "0"+ans;
    }
    a /= -2;
      
  }
   if(ans  ==""){
     cout << "0" << endl;
   }
  
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
const int M = 1e7 + 50;
using namespace std;
int a[M] = {0};
int main(){
	int s;
	cin>>s;
	int sum = 1;
	while(a[s] == 0){
		a[s]++;
		if(s%2 == 0){
			s/=2;
		}
		else{
			s = 3*s+1;
		}
		sum++;
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

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

    p((a-1)*(b-1))
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define ll long long
const int inf=1000000000;

bool cmp(pair<int,int> a, pair<int,int> b){
	return a.second<b.second;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
    
    	int n;
    	cin >>n;
    	double a[n];
    	for(int i=0;i<n;i++) cin >>a[i];
    double	dp[n+1][n+1];
    	memset(dp , 0, sizeof(dp));
    	dp[0][0]=1.0;
    	for(int i=1;i<=n;i++){
    		for(int j=0;j<=i;j++){
    			if(j==0){
    				dp[i][j]=dp[i-1][j]*(1-a[i-1]);
				}
				else{
					dp[i][j]=dp[i-1][j]*(1-a[i-1])+ dp[i-1][j-1]*(a[i-1]);
				}
			}
		}
	double res = 0.0; 
 
    for (int i = (n + 1) / 2; i <= n; i ++) 
        res += dp[n][i];
	
	cout <<setprecision(10) << res<<"\n";

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll>> DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX/3
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define ub(x,y)     upper_bound(all(x),y)
#define lb(x,y)     lower_bound(all(x),y)
#define uni(x)      x.erase(unique(all(x)),x.end())
#define rep(i,n)    repl(i,0,n-1)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<int>())
#define mkp(x,y)    make_pair(x,y)

int ans = INF;
int n,k;

void dfs(int count,int num){
  if(count == n){
    if(ans>num)ans=num;
  }else{
    dfs(count+1,num+k);
    dfs(count+1,num*2);
  }
}

int main(){
  cin.sync_with_stdio(false);
  cin >> n >> k;
  dfs(0,1);
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int INF = 1000000007;
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		if(n % 2 == 0) {
			boolean ok = true;
			for(int i = 0 ; i < n ; i += 2) {
				if(a[i] == i + 1 && a[i + 1] == i + 1);
				else ok = false;
			}
			if(ok) {
				long temp = n / 2;
				long ans = 1;
				for(int i = 0 ; i < temp ; i++) {
					ans = ans * 2 % INF;
				}
				System.out.println(ans);
			} else {
				System.out.println(0);
			}
		} else {
			boolean ok = true;
			if(a[0] == 0) {
				for(int i = 1 ; i < n ; i += 2) {
					if(a[i] == i + 1 && a[i + 1] == i + 1);
					else ok = false;
				}
			} else ok = false;
			if(ok) {
				long temp = (n - 1) / 2;
				long ans = 1;
				for(int i = 0 ; i < temp ; i++) {
					ans = ans * 2 % INF;
				}
				System.out.println(ans);
			} else {
				System.out.println(0);
			}
		}
	}
}


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

int n;

vector <string> ans;

void dfs(string s,int x){
    int l;
    int xx;
    l=s.size();
    if(l==n){
        ans.push_back(s);
    }
    else{
        char a;
        a='a';
        rep(i,x){
            if(i==0){
                a='a';
            }
            else if(i==1){
                a='b';
            }
            else if(i==2){
                a='c';
            }
            else if(i==3){
                a='d';
            }
            else if(i==4){
                a='e';
            }
            else if(i==5){
                a='f';
            }
            else if(i==6){
                a='g';
            }
            else if(i==7){
                a='h';
            }
            else if(i==8){
                a='i';
            }
            else if(i==9){
                a='j';
            }
            //xx=max(x,)
            xx=x;
            if(i==x-1){
                xx=x+1;
            }
            
            
            
            string ss;
            ss=s+a;
            dfs(ss,xx);
        }
    }
}

int main(){
    cin >> n;
    string aa;
    aa='a';
    dfs(aa,2);

    sort(ans.begin(),ans.end());

    int l2;
    l2=ans.size();

    

    rep(i,l2){
        cout << ans[i] << endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 7360