akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();

		if(a == b){
			System.out.println("Draw");
		}else{
			if(a==1){
				System.out.println("Alice");
				return;
			}
			if(b==1){
				System.out.println("Bob");
				return;
			}
			if(a>b){
				System.out.println("Alice");
			}else{
				System.out.println("Bob");
			}
		}
	}
}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
#define int long long int
#define mod 1000000007
int fac[2000001];
void function()
{
	fac[0]=1;
	int j;
	for(j=1;j<=2000000;j++)
	{
		fac[j]=(j*fac[j-1])%mod;
	}
}
int power(int x, int y, int p) 
{ 
    int res = 1;
  
    x = x % p;  
  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
int nCrModPFermat(int n, int r, int p) 
{ 
	if(r>n||r<0)
	  return 0;
   if (r==0) 
      return 1; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
int32_t main()
{
	function();
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	if(h==1||w==1)
	{
		cout<<1<<endl;
		exit(0);
	}
	int val[h+1]={0};
	int i;
	int col=b+1;
	for(i=1;i<=h;i++)
	{
		if(i>h-a)
		{
			val[i]=val[i-1];
			continue;
		}
		int total=i+col-2;
		val[i]=nCrModPFermat(total,b,mod);
	}
	int answer=0;
	for(i=1;i<=h;i++)
	{
		col=b+2;
		int total=h+w-(i+col);
		int r=(w-col);
		int temp=nCrModPFermat(total,r,mod);
		int temp2=val[i];
		int curr=(temp*temp2)%mod;
		answer+=curr;
		answer%=mod;
	}
	if(answer==0)
	  answer+=val[h];
	cout<<answer<<endl;
}


Measured memory_bytes: 16640
import numpy as np
n = int(input())
a = np.cumsum([0] + [int(i) for i in input().split()])
b = np.cumsum([0] + [int(i) for i in input().split()])
ans = 0
if n == 1:
    ans = a[1] + b[1]
else:
    for i in range(n):
        ans = max(ans, a[i+1] + b[-1] - b[i])
print(ans)

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

using namespace std;
#define sz(a) int(a.size())
#define ll  long long
#define mod int(1e9+7)
#define endl '\n'
#define ENGZ ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define pi (acos(-1))
#define S second
#define F first
ll fp(ll n , ll p )
{
    if(p==0)
        return 1;
    if(p==1)
        return n ;
    ll res = fp(n,p/2) ;
    res=((res)*(res)) ;
    if(p%2)
        res=(res*n) ;
    return res ;
}

int main()
{
    ENGZ;
    int n , arr[101] , brr[101];
    int a = -1, b = -1 , c = 0;
    cin>>n ;
    for(int i=0 ; i<n ; i++)
        cin>>arr[i],brr[i]=arr[i] ;

    sort(arr,arr+n);
    for(int i=0 ; i<n ; i++)
    {
        if(arr[i]!=brr[i] && a == -1)
        {
            c++ ;
            a = i ;
        }
        else if(arr[i]!=brr[i] && b == -1)
        {
            c++ ;
            b = i ;
        }
        else if(arr[i]!=brr[i])
            c++ ;
    }
    if(a == b && a == -1){
        cout<<"YES"<<endl ;
    }
    else if(c<=2)
    {
        swap(brr[a],brr[b]);
        c=0 ;
        for(int i=0; i<n ; i++)
        {
            if(arr[i]!=brr[i])
                c++ ;
        }
        if(c==0)cout<<"YES"<<endl ;
        else cout<<"NO" <<endl  ;
    }
    else cout<<"NO" <<endl  ;


    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  vector<int> a(N);
  REP(i, N) a[i] = nextInt();

  bool allPositive = true;
  bool allNegative = true;
  REP(i, N) {
    if (a[i] < 0) allPositive = false;
    if (a[i] > 0) allNegative = false;
  }

  vector< pair<int,int> > ops;

  if (allPositive) {
    REP(i, N-1)  ops.push_back( {i, i+1} );
  } else if (allNegative) {
    for (int i = N - 1; i >= 1; i--) ops.push_back( {i, i-1} ); 
  } else {
    int max_abs = 0;
    int max_abs_i = 0;
    REP(i, N) {
      if (abs(a[i]) > max_abs) {
        max_abs = abs(a[i]);
        max_abs_i = i;
      }
    }

    if (a[max_abs_i] > 0) {
      REP(i, N) if (i != max_abs_i) ops.push_back({max_abs_i, i});
      REP(i, N-1)  ops.push_back( {i, i+1} );
    } else {
      REP(i, N) if (i != max_abs_i) ops.push_back({max_abs_i, i});
      for (int i = N - 1; i >= 1; i--) ops.push_back( {i, i-1} ); 
    }

  }


  cout << ops.size() << endl;
  for (auto x : ops) {
    cout << ((x.first) + 1) << " " << ((x.second) + 1) << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}




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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int a[110];
signed main() {
  cin>>N;
  for(int i=0;i<N;i++)cin>>a[i];
  int ans=0;
  for(int i=1;i<N;i++){
    if(a[i]==a[i-1])ans++,a[i]=-1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n+1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
#define stringc(s) string s; cin >> s;
using namespace std;
int main() {
  llc(x);
  ll b=0,c=0;
  vector<ll> a(10000,0);
  r1(i,10000) a.at(i)=pow(i,5);
  r1(i,10000) {
    r1(j,i) {
      if(a.at(i)-a.at(j)==x) {
        b=i;
        c=j;
        break;
      }
      if(a.at(i)+a.at(j)==x) {
        b=i;
        c-=j;
        break;
      }
    }
    if(b>0) break;
  }
  cout << b << " " << c << endl;
}

Measured memory_bytes: 4256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int r, g, b;
    cin >> r >> g >> b;
    int ans = r * 100 + g * 10 + b;
    if(ans % 4 == 0){
        cout << "YES";
    }else{
        cout << "NO";
    }
    el;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
vector<int> g[100001];
ll dp[100001][2];
ll solv(ll n,ll p)
{
    dp[n][0]=dp[n][1]=1;
    for(ll nd:g[n])
    {
        if(nd==p)
            continue;
        dp[n][1]*=solv(nd,n);
        dp[n][0]*=dp[nd][1];
        dp[n][0]%=mod;
        dp[n][1]%=mod;
    }
    return (dp[n][0]+dp[n][1])%mod;
}
int main()
{
    ll n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    cout<<(solv(1,0))<<endl;
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>

using namespace std;

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

    for(int i=0; i<N; i++){
        int a;
        cin >>a;

        if(a%2==0){
            if(!(a%3==0 || a%5==0)){
                cout << "DENIED";
                return 0;
            }
        }
    }

    cout << "APPROVED";

    
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int ans = 1000000;
  for (int i = 0; i + 2 < S.size(); i++) {
    int num = stoi(S.substr(i, 3));
    if (ans > abs(num - 753)) ans = abs(num - 753);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i, j, num, n;
	char mark, c;
	char str[4] = {'S','H','C','D'};
	int cards[4][13];
	
	scanf("%d",&n);
	
	for(i=0; i<4; i++){
			for(j=0; j<13; j++){
				cards[i][j] = 0;
			}
	}
	for(i=0; i<n; i++){
		scanf("%c",&c);
		scanf("%c %d", &mark, &num);
		
		if(mark =='S'){
			j=0;	
		}else if(mark == 'H'){
			j=1;
		}else if(mark == 'C'){
			j=2;
		}else{
			j=3;
		}
		
		cards[j][num-1] = 1;
	}
	for(i=0; i<4; i++){
			for(j=0; j<13; j++){
				if(cards[i][j] == 0){
					printf("%c %d\n", str[i], j+1);
				}
			}
	}
	
	return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.io.*;

public class Main {

    private static int solver(int[] m){
        int ans=1;
        int height = m[0];
        for(int i=1; i<m.length;i++){
            if(height <= m[i]) {
                height = m[i];
                ans++;
            }
        }

        return ans;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        int[] m = new int[t];
        for (int i = 1; i <= t; ++i) {
            m[i-1] =  in.nextInt();
        }
        System.out.println(solver(m));
    }
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
    	int N = Integer.parseInt(sc.next());
    	ArrayList<Integer> lArrayList = new ArrayList<>();
    	for (int i=0; i<N; i++){
    		lArrayList.add(Integer.parseInt(sc.next()));
    	}

    	int max = lArrayList
    		      .stream()
    		      .mapToInt(v -> v)
    		      .max().orElseThrow(NoSuchElementException::new);

    	int sum = lArrayList
  		      .stream()
  		      .mapToInt(v -> v)
  		      .sum();

    	if ((sum-max) > max){
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}
	}
}


Measured memory_bytes: 28628
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	string t = "ACGT";
	int ans = 0;
	int cnt = 0;
	rep(i, s.size()) {
		bool ok = false;
		rep(j, 4) {
			if(s[i] == t[j]) ok = true;
		}
		if(ok) {
			cnt++;
			ans = max(cnt, ans);
		}
		else {
			cnt = 0;
		}
	}
	cout << ans << endl;
}


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

using namespace std;

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

    int easily_playable = true;
    for(int i = 0; i < steps.size(); i++)
    {
        if( ((i%2 == 0) && steps[i] == 'L') || ((i%2 == 1) && steps[i] == 'R') )
        {
            easily_playable = false;
        }
    }

    cout << (easily_playable ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#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>
#include <stack>
#include <functional>

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

const int INF = 1001001001;
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<vector<int> > dp (m + 1, vector<int>(1 << n));
    rep (i, m + 1) rep (j, 1 << n) dp[i][j] = INF;
    dp[0][0] = 0;
    eprintf("init ok\n");
    rep (i, m) {
        int a, b, c = 0; cin >> a >> b;
        rep (_, b) {
            int x; cin >> x; x--;
            c |= (1 << x);
        }
        rep (j, 1 << n) {
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j | c], dp[i][j] + a);
        }
    }
    if (dp[m][(1 << n) - 1] >= INF) cout << -1 << "\n";
    else cout << dp[m][(1 << n) - 1] << "\n";
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int x[100010];
int nxt[20][100010];

int main(void){
	int n,l;
	cin >> n;
	rep(i,n) cin >> x[i];
	cin >> l;

	int last=0;
	rep(i,n){
		while(last<n && x[last]-x[i]<=l) last++;
		nxt[0][i]=last-1;
	}

	rep(k,19)rep(i,n) nxt[k+1][i]=nxt[k][nxt[k][i]];

	int q;
	cin >> q;

	rep(loop,q){
		int a,b;
		cin >> a >> b;
		a--,b--;
		if(a>b) swap(a,b);
		int ans=0;
		rrep(k,20) if(nxt[k][a]<b) ans|=bit(k),a=nxt[k][a];
		cout << ans+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int a_max, b_max = 0, c = 0;
    if(A >= K){a_max = K;}
    else{
        a_max = A;
        if(B >= K - a_max){b_max = K - a_max;}
        else{
            b_max = B;
            c = K - a_max - b_max;
        }
    }
    cout << a_max - c << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int a=0,b=0,ab=0,abi=0,n,i,res;
  string s;
  string::size_type pos;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> s;
    pos=s.find("AB");
    while(pos!=string::npos){
      pos=s.find("AB",pos+2);
      abi++;
    }
    if(s.front()=='B'){
      if(s.back()=='A') ab++;
      else b++;
    }else if(s.back()=='A') a++;
  }
  res=abi+ab+min(a,b);
  if(a==0&&b==0&&ab>0) res--;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int dp[2][N+1][1<<N];
bool bad[N+1][N+1][2];

inline void fix(int &x){
	if (x>=mod) x-=mod;
	if (x<0) x+=mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m>>k;
	n--;
	while (k--){
		cin>>a>>b>>x;
		bad[a-1][b-1][x^1]=1;
	}
	dp[0][0][0]=1;
	for (int i=0; i<m; i++){
		int x=(i&1);
		for (int j=0; j<n; j++){
			for (int mask=0; mask<(1<<n); mask++){
//				cerr<<"dp["<<i<<"]["<<j<<"]["<<mask<<"]="<<dp[x][j][mask]<<"\n";
				if (!bad[i][j][0] && ((mask>>j)&1)==0)
					fix(dp[x][j+1][mask]+=dp[x][j][mask]);
				if (!bad[i][j][1]){
					if (mask&(1<<j)) fix(dp[x][j+1][mask]+=dp[x][j][mask]);
					else{
						int msk=mask|(1<<j);
						int tmp=mask&(~((1<<j)-1));
						int bit=__builtin_ctz(tmp);
						if (tmp) msk^=(1<<bit);
						fix(dp[x][j+1][msk]+=dp[x][j][mask]);
					}
				}
			}
//			cerr<<"\n";
		}
		memset(dp[x^1], 0, sizeof(dp[x^1]));
		for (int mask=0; mask<(1<<n); mask++){
			fix(dp[x^1][0][mask]+=dp[x][n][mask]);
		}
	}
	for (int mask=0; mask<(1<<n); mask++) fix(ans+=dp[m&1][0][mask]);
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 175684
import collections
N = int(input())
S = input()
dp = [0]*N
for i in range(N-1):
  if S[i] == "W":
    dp[i+1] = dp[i]+1
  else:
    dp[i+1] = dp[i]
dpE = [0]*N
for i in range(1,N)[::-1]:
  if S[i] == "E":
    dpE[i-1] = dpE[i]+1
  else:
    dpE[i-1] = dpE[i]
ret = float("inf")
for i in range(N):
  ret = min(ret,dp[i]+dpE[i])
print(ret)

Measured memory_bytes: 17848
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		
		Map<String, Integer> map = new HashMap<>();
		for(int i=0;i<n;i++) {
			String s = fs.next();
			if(map.containsKey(s)) {
				map.put(s, map.get(s)+1);
			}
			else {
				map.put(s, 1);
			}
		}
		
		List<String> ls[] = new ArrayList[n+1];
		int max = 0;
		for(int i=0;i<n+1;i++)ls[i] = new ArrayList<>();
		for(String key:map.keySet()) {
			int v = map.get(key);
			max = Math.max(max, v);
			ls[v].add(key);
		}
		StringBuilder sb = new StringBuilder();
		ArrayList<String> now = (ArrayList)ls[max];
		Collections.sort(now);
		for(String t : now)sb.append(t+"\n");
		
		System.out.println(sb.toString());

	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 80120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    map<int, int> cnt;
    rep(i,n) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    Int ans = 0;
    for(auto itr = cnt.begin(); itr != cnt.end(); itr++) {
        if (itr->first > itr->second) ans += itr->second;
        else ans += itr->second - itr->first;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fr first
#define sc second
#define close(x){cout<<x<<endl;return 0;}
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for(ll i=a;i<b;i++)

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n;
cin>>n;
if(n&1)cout<<(n/2)*(n/2+1);
else cout<<n*n/4<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string.h>

using namespace std;
typedef pair<int, int> P;



void solve()
{
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<long long> s(A + 2);
	s[0] = -1e18;
	for (int i = 1; i <= A; ++i)
	{
		cin >> s[i];
	}
	s[A + 1] = 1e18;
	vector<long long> t(B + 2);
	t[0] = -1e18;
	for (int i = 1; i <= B; ++i)
	{
		cin >> t[i];
	}
	t[B + 1] = 1e18;
	for (int i = 0; i < Q; ++i)
	{
		long long x;
		cin >> x;
		int sHigh = lower_bound(s.begin(), s.end(), x) - s.begin();
		int tHigh = lower_bound(t.begin(), t.end(), x) - t.begin();
		long long ans = 1e18;
		for (int j = sHigh - 1; j <= sHigh; ++j)
		{
			for (int k = tHigh - 1; k <= tHigh; ++k)
			{
				ans = min(ans, abs(s[j] - x) + abs(s[j] - t[k]));
				ans = min(ans, abs(t[k] - x) + abs(t[k] - s[j]));
			}
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 1e9 + 7;

int modpow(int x, int n) {
    int ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int modcomb(int n, int k) {
    if (n - k < k) k = n - k;
    int x = 1, y = 1;
    for (int i = 0; i < k; i++) x = x * (n - i) % MOD;
    for (int i = k; i > 0; i--) y = y * i % MOD;
    return x * modpow(y, MOD - 2) % MOD;
}

signed main() {
    int n, a, b;
    cin>>n>>a>>b;
    int ans = modpow(2, n) - 1;
    ans -= modcomb(n, a);
    if (ans < 0) ans += MOD;
    ans -= modcomb(n, b);
    if (ans < 0) ans += MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    cout << z << " " <<  x << " " << y << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ii;
typedef pair<int64, int64> int64int64;
typedef vector<int> vint;
typedef vector<int64> vint64;
typedef vector<uint64> vuint64;
typedef vector<vint> vvint;
typedef vector<vint64> vvint64;
typedef vector<vuint64> vvuint64;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;

#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define fori(n) for(int i = 0; i < n; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)

template<typename T>
void prinMatrix(string txt, vector<vector<T>> &a){
	cout << txt;
	fori(a.size()){
		forj(a[i].size())
			cout << a[i][j] << ' ';

		cout << endl;
	}
}

template<typename T>
void printVector(string txt, vector<T> &a){
	cout << txt;
	for (int i = 0; i < a.size(); ++i)
		cout << a[i] << ' ';
	cout << endl;
}


int main(){

	ios_base::sync_with_stdio(0);
	cin.tie();

	string s;
	cin >> s;
	int n = s.length();

	/*/
	int ans1 = (n / 3) * 2;
	if (n % 3 == 1){
		if (s[n - 1] != s[n - 2])
			++ans1;
	}
	else if (n % 3 == 2)
		++ans1;
	for (int i = 0; i < (n / 3) * 3; i += 3){
		if (s[i] != s[i + 1] && s[i + 1] != s[i + 2])
			++ans1;
	}


	int ans2 = (n / 3) * 2;
	if (n % 3 == 2){
		if (s[n - 1] != s[n - 2])
			ans2 += 2;
		else if (n > 3){
			string s1, s2;
			s1.pb(s[n - 2]);
			s1.pb(s[n - 1]);
			s2.pb(s[n - 4]);
			s2.pb(s[n - 3]);

			if (s1 != s2)
				++ans2;
		}
	}
	*/

	int i = 1;
	int ans = 1;
	int l = 1;
	while (i < n){
		if (l == 2){
			++ans;
			++i;
			l = 1;
		}
		else{
			if (s[i] != s[i - 1]){
				l = 1;
				++ans;
				++i;
			}
			else{
				if (i < n - 1){
					l = 2;
					++ans;
					i += 2;
				}
				else{
					i += 2;
					l = 2;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 720
#include <iostream>
int main() {
  int n, a, b, c, d, e, f, x;
  std::cin >> n;
  a = n % 10; 
  b = ((n - a) % 100) / 10; 
  c = ((n - a - b * 10) % 1000) / 100;
  d = ((n - a - b * 10 - c * 100) % 10000) / 1000;
  e = ((n - a - b * 10 - c * 100 - d * 1000) % 100000) / 10000;
  f = ((n - a - b * 10 - c * 100 - d * 1000 - e * 10000) % 1000000) / 100000;
  x = a + b + c + d + e + f;
  if (x == 1) { 
    x = 10; 
  }
  std::cout << x << std::endl;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc086/tasks/abc086_a
#include <bits/stdc++.h>
using namespace std;

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

  int product = a * b;

  if(product %2 ==0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,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; }

set<ll> enumDivisor(ll n) {
  set<ll> res;
  for (ll i = 1; i*i <= n; ++i) {
    if (n%i) continue;
    res.insert(i);
    res.insert(n/i);
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  int ans = 0;
  for (ll x : enumDivisor(n)) {
    if (x==1) continue;
    ll tmp = n;
    while (tmp%x == 0) tmp /= x;
    tmp %= x;
    if (tmp==1) ans++;
  }
  ans += enumDivisor(n-1).size() - 1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int d, e;
    d=min(min(a, b), c);
    e=max(max(a, b), c);
    cout << d << " " << e << "\n";
    
    
    return 0;
}


Measured memory_bytes: 3116
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int fun(int n){
    int f=n%10,s=0,h=n;
    while(n){
        s = n%10;
        n /= 10;
    }
    if (f==0) return 0;
    if (f != s) return f*10+s;
    return f;
}

int helper (int n){
    int s=0;
    while (n){
        s = s*10 + (n%10) ; 
        n /= 10 ; 
    }
    return s;
}

inline void solve(){
    int n; cin>>n; 
    map <int,int> cnt;
    for (int i=1;i<=n;i++) { 
        cnt[fun(i)]++; 
    } 
    int  ans = 0 ; 
    for (auto &it: cnt){
        if (it.ff==0) continue;
        int x=it.ff;
        if (x<=9) ans += it.ss*it.ss; 
        else {
            int h= helper(x);
            ans += it.ss*cnt[h];
        }
    } 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, a, b, c;
	cin >> n;
	vector<int> list(n);
	for (int i = 0; i < n; ++i) {
		cin >> list.at(i);
	}
	sort(list.rbegin(), list.rend());

	int count = 0;
	for (int i = 0; i < n - 2; ++i) {
		for (int j = i + 1; j < n - 1; ++j) {
			for (int k = j + 1; k < n; ++k) {
				a = list.at(i);
				b = list.at(j);
				c = list.at(k);
				if (a < b+c) {
					count++;
				} else {
					break;
				}
			}
		}
	}
	cout << count;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] times = new int[5];
        for (int i = 0; i < 5; i += 1) {
            times[i] = sc.nextInt();
        }

        Integer[] indices = new Integer[5];
        for (int i = 0; i < 5; i += 1) {
            indices[i] = i;
        }
        List<List<Integer>> permutations = permute(indices);

        int minTime = Integer.MAX_VALUE;
        for (List<Integer> perm : permutations) {
            int time = 0;
            for (int index : perm) {
                if (time % 10 != 0) {
                    time += 10 - (time % 10);
                }
                time += times[index];
            }
            if (minTime > time) {
                minTime = time;
            }
        }

        System.out.println(minTime);
    }

    private static <T> List<List<T>> permute(T[] items) {
        List<List<T>> perms = new LinkedList<>();
        permuteHelper(perms, items, 0);
        return perms;
    }

    private static <T> void permuteHelper(List<List<T>> perms, T[] items, int n) {
        if (n == items.length - 1) {
            List<T> perm = new LinkedList<>();
            for (T item : items) {
                perm.add(item);
            }
            perms.add(perm);
        } else {
            for (int m = n; m < items.length; m += 1) {
                swap(items, n, m);
                permuteHelper(perms, items, n + 1);
                swap(items, n, m);
            }
        }
    }

    private static <T> void swap(T[] items, int index1, int index2) {
        T tmp = items[index1];
        items[index1] = items[index2];
        items[index2] = tmp;
    }

}


Measured memory_bytes: 23252
import math
import random
# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]
n=int(input())
P=primes(55555)
P=[int(i) for i in P if i%5==1]
print(*P[:n])

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=998244353;

LL n,t,n2=1,a[3010],dp[3010][3010],dat[3010][30010],ans;

void upd(LL kk,LL k,LL val)
{
	dat[kk][k]=val;
	while(k>0)
	{
		k=(k-1)/2;
		dat[kk][k]=(dat[kk][k*2+1]+dat[kk][k*2+2])%MOD;
	}
}

LL query(LL kk,LL k,LL lb,LL ub,LL tlb,LL tub)
{
	if(ub<tlb||tub<lb) return 0;
	if(tlb<=lb&&ub<=tub) return dat[kk][k];
	return query(kk,k*2+1,lb,(lb+ub)/2,tlb,tub)+query(kk,k*2+2,(lb+ub)/2+1,ub,tlb,tub);
}

int main()
{
	cin>>n>>t;
	while(n2<3000) n2*=2;
	rep(i,n)
	{
		cin>>a[i];
		dp[i][a[i]]=i+1;
		upd(a[i],i+n2-1,i+1);
	}
	repn(i,n-1)
	{
		rep(j,3001)
		{
			if(j-a[i]<0) continue;
			dp[i][j]=(dp[i][j]+query(j-a[i],0,0,n2-1,0,i-1))%MOD;
			//if(j<=10) cout<<i<<' '<<j<<' '<<query(j-a[i],0,0,n2-1,0,i-1)<<endl;
			upd(j,i+n2-1,dp[i][j]);
			//if(j==5&&i==3) cout<<dp[i][j]<<'p'<<' '<<query(5,0,0,n2-1,0,3)<<endl;
		}
	}
	rep(i,n) ans=(ans+dp[i][t]*(n-i)%MOD)%MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 774912
N=int(input())
D=[]
for i in range(N):
    d=list(map(int,input().split()))
    D.append(d)
for i in range(N-2):
    if D[i][0]==D[i][1]:
        if D[i+1][0]==D[i+1][1]:
            if D[i+2][0]==D[i+2][1]:
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 9188
use std::io;

fn main() -> io::Result<()>{
    let stdin = io::stdin();
    
    let (n,k) = {
	let mut buf = String::new();
	stdin.read_line(&mut buf)?;
	buf.retain(|c| c != '\n');
	let split = buf.split_ascii_whitespace();
	let tmp: Vec::<usize> = split.map(|c|  c.parse::<usize>().unwrap()).collect();
	(tmp[0],tmp[1])
    };

    let prices = {
	let mut buf = String::new();                                              
	stdin.read_line(&mut buf)?;                                                
	buf.retain(|c| c != '\n');                                                
	let split = buf.split_ascii_whitespace();                                 
	let mut tmp = split.map(|c| c.parse::<u64>().unwrap()).collect::<Vec::<u64>>();
	tmp.sort();
	tmp
    };

    println!("{:}",sum(&prices[..k]));

    Ok(())
}

fn sum(arr: &[u64]) -> u64{
    let mut res = 0;
    for ele in arr{
	res += *ele;
    }
    res
}



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

int main()
{
	string t;
  	cin >> t;
  	int n;
  	n = t.size();
  	if(t.at(0) == '?')
    {
    	t.at(0) = 'D';
    }
  	for(int i = 1; i < n; i++)
    {
    	if(t.at(i) == '?')
        {
            t.at(i) = 'D';
        }
    }
  	cout << t << endl;
}


Measured memory_bytes: 3748
inputS = input()
s = inputS

def month(tuki):
    return 0 < tuki <= 12 

mae = int(s[:2])
ushiro = int(s[-2:])

if month(mae) and month(ushiro):
    print("AMBIGUOUS")
elif month(mae):
    print("MMYY")
elif month(ushiro):
    print("YYMM")
else:
    print("NA")
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	    // #ifndef ONLINE_JUDGE
     //   // for getting input from input.txt
     //   freopen("input.txt", "r", stdin);
     //   // for writing output to output.txt
     //   freopen("output.txt", "w", stdout);
     //  #endif
		int d;
		cin>>d;
		if(d == 25){ cout<<"Christmas"<<endl; }
		else if(d == 22){ cout<<"Christmas Eve Eve Eve"<<endl; }
		else if(d == 23){ cout<<"Christmas Eve Eve"<<endl; }
		else{  cout<<"Christmas Eve"<<endl; } 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}
 
template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}
 
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {

	vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	int k;
	cin >> k;

	cout << v[k - 1] << endl;
  
}

Measured memory_bytes: 256
N = int(input())
M = ["S", "H", "C", "D"]

sr = set()
for _ in range(N):
    s, r = input().split()
    sr.add(s+r)
for m in M:
    for i in range(1, 14):
        mi = m+str(i)
        if mi not in sr:
            print(m, i)



Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint a[100005], b[100005];
P p[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i<= n; i++){
		cin >> a[i] >> b[i];
		p[i] = P(a[i], i);
	}
	sort(p+1, p+n+1);
	
	llint ans = 0, rem = m;
	for(int i = 1; i <= n; i++){
		if(rem <= 0) break;
		llint id = p[i].second;
		llint x = min(rem, b[id]);
		ans += x * a[id], rem -= x;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6740
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

vector<ll> fact_inv, fact;

ll pow(int a, int b) {
	if (!b) {
		return 1;
	}
	else if (b % 2 == 0) {
		ll d = pow(a, b/2);
		return (d * d) % MOD;
	}
	else {
		return (a*pow(a, b-1)) % MOD;
	}
}


ll inv(int a){
    return pow(a, int(MOD-2));
}

ll comb(int a, int b){
    if(a < b) return 0;
    if(a < 0 || b < 0) return 0;
    ll ret = fact[a];
    ret = ret * fact_inv[b] % MOD;
    ret = ret * fact_inv[a-b] % MOD;
    return ret;
}

void precom(int n){
    fact.resize(n);
    fact_inv.resize(n);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    for(int i = 2; i < n; ++i) fact[i] = fact[i-1] * i % MOD;
    for(int i = 2; i < n; ++i) fact_inv[i] = inv(fact[i]);
    return;
}

int main(){
    int n; cin >> n;
    precom(n+10);
    int dif;
    
    vector<int> idx(n, 0);
    REP(i, n+1){
        int a; cin >> a;
        if(idx[a-1] == 0) idx[a-1] = i+1;
        else dif = i+1 - idx[a-1];
    }
    REP(i, n+1){
        ll ans = comb(n+1, i+1) - comb(n-dif, i);
        cout << (ans<0 ? ans + MOD : ans) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3200
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int K, S;
	std::cin >> K >> S;

	int result = 0;
	for (int x = 0; x <= K; ++x) {
		for (int y = 0; y <= K; ++y) {
			int z = S - x - y;
			if (0 <= z && z <= K) {
				++result;
			}
		}
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 512
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
import itertools
import math
import sys
from typing import *

INF = float('inf')


def solve(N: int, S: "List[str]"):
    return "\n".join([f'{v} x {S.count(v)}' for v in ["AC", "WA", "TLE", "RE"]])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    print(solve(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83280
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int N;
  cin >> N;
  long long int A[N], acum[N+1];
  acum[0] = 0;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    acum[i+1] = acum[i] + A[i];
  }
  long long int ans = 10000000000;
  for(int i = 1; i < N; ++i){
    ans = min(ans, abs(acum[N]-2*acum[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#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 main(){
    int n;
    cin>>n;
    n %= 10;
    cout << (n==3?"bon":!n||n==1||n==6||n==8?"pon":"hon");
    return 0;
}

Measured memory_bytes: 3592
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
vll L;

ll ltmp;
string stmp;
double dtmp;

ll getIndexUpperBoundLong(vll x_vector,ll key){
    decltype(x_vector)::iterator it = upper_bound(x_vector.begin(), x_vector.end(), key);
    ll index = distance(x_vector.begin(), it);
    return index;
}
ll getIndexUpperBoundString(vector<string> x_vector,string key){
    decltype(x_vector)::iterator it = upper_bound(x_vector.begin(), x_vector.end(), key);
    ll index = distance(x_vector.begin(), it);
    return index;
}
ll getIndexLowerBoundLong(vll x_vector,ll key){
    decltype(x_vector)::iterator it = lower_bound(x_vector.begin(), x_vector.end(), key);
    ll index = distance(x_vector.begin(), it);
    return index;
}
ll getIndexLowerBoundString(vector<string> x_vector,string key){
    decltype(x_vector)::iterator it = lower_bound(x_vector.begin(), x_vector.end(), key);
    ll index = distance(x_vector.begin(), it);
    return index;
}

int main(){

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

    cin >> N;

    rep(ni,N){
        cin >> ltmp;
        L.push_back(ltmp);
    }
    L.push_back(100000);

    ll max_index = N-1;
    ll cnt = 0;
    sort(L.begin(),L.end());
    for( ll t1 = 0 ; t1 <=max_index-2 ; t1++ ){
        for( ll t2 = t1+1 ; t2 <=max_index-1 ; t2++ ){
            ll sum2 = L[t1]+L[t2];
            ll index = getIndexLowerBoundLong(L,sum2);
            //cout << index << endl;
            cnt+=((index-1) - t2 );

        }
    }
    cout << cnt << endl;


}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll n;
    string s;
    cin>>n>>s;
    ll ans=0;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
    for (int i = 0;i < n;++i) {
        int u,v;
        cin >> u >> v;
        dp[i+1] = dp[i];
        for (int j = 0;j < w;++j) {
            if (j+u > w) break;
            dp[i+1][j+u] = max(dp[i+1][j+u],dp[i][j]+v);
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 80256
n, m = map(int, input().split())
L=list(map(int, input().split()))
A=[]
for i in range(n):
	A.append(-L[i])

import heapq
heapq.heapify(A)

for i in range(m):
	a= -heapq.heappop(A)
	heapq.heappush(A, -(a//2))

print(-sum(A))

Measured memory_bytes: 14224