akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
// BIT
template< typename T >
struct BIT {
  int N; int max_2beki;

  vector< T > data;
  // 初期化 1-indexedでデータを管理する 0で初期化
  BIT(int size){
      N = ++size;
      data.assign(N, 0);
      max_2beki = 1;
      while(max_2beki * 2 <= N) max_2beki *= 2;
  }

  // [0,k](閉区間)の総和 閉区間に注意！
  T sum(int k) {
    if(k < 0) return 0; // k<0のとき0を返す
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  // [l,r](閉区間)の総和
  inline T sum(int l,int r){
    return sum(r) - sum(l-1);
  }

  // 一点取得 更新はできないことに注意
  inline T operator[](int k){
    return sum(k) - sum(k-1);
  }

  // data[k] += x;
  void add(int k, T x) {
    for(++k; k < N; k += k & -k) data[k] += x;
  }

  // imos法 [l,r]にxを加算
  void imos(int l,int r,T x){
    add(l , x); add(r + 1 , -x);
  }

  // lower_bound sum(i)がval以上となる最小のi
  int lower_bound(T w){
    if(w <= 0) return 0;
    int x = 0;
    for(int k = max_2beki; k > 0; k /= 2){
      if(x+k <= N - 1 && data[x + k] < w){
        w -= data[x + k];
        x += k;
      }
    }
    return x;
  }

  // upper_bound sum(i)がvalより大きくなる最小のi
  int upper_bound(T w){
    if(w < 0) return 0;
    int x = 0;
    for(int k = max_2beki; k > 0; k /= 2){
      if(x+k <= N - 1 && data[x + k] <= w){
        w -= data[x + k];
        x += k;
      }
    }
    return x;
  }

};
int main(){
    int n;cin >> n;
    vector<BIT<int>> bit(26,BIT<int>(n+10));
    string s;cin >> s;
    for(int i=0;i<n;i++){
        int p=s[i]-'a';
        bit[p].add(i,1);
    }
    int q;cin >> q;
    while(q--){
        int x;cin >> x;
        if(x==1){
            int i;cin >> i;
            i--;
            char c;cin >> c;
            int p=c-'a';
            bit[p].add(i,1);
            bit[s[i]-'a'].add(i,-1);
            s[i]=c;
        }
        else{
            int l,r;cin >> l >> r;
            l--,r--;
            int res=0;
            for(int i=0;i<26;i++){
                if(bit[i].sum(l,r)){
                    res++;
                }
            }
            cout << res << endl;
        }
    }
}

Measured memory_bytes: 53212
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y,sum,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

ll check(ll res1,ll res2,ll now){
    if(res1<=now&&res2<=now){
        return now-min(res1,res2);
    }
    else if(res1>=now&&res2>=now){
        return max(res1,res2)-now;
    }
    else if(res1<=now&&res2>=now){
        return min(now-res1,res2-now)*2+max(now-res1,res2-now);
    }
    else{
        return min(now-res2,res1-now)*2+max(now-res2,res1-now);
    }
}

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

    cin>>a>>b>>q;
    ll s[a+10]={},t[b+10]={};
    ll t1,t2,h1,h2;
    rep(i,a)cin>>s[i];
    rep(i,b)cin>>t[i];
    rep(i,q)cin>>x[i];

    rep(i,q){
        ll le1=0,ri1=a,mid1;
        ll le2=0,ri2=b,mid2;

        while(ri1-le1>1){
            mid1=(ri1+le1)/2;
            if(s[mid1]<=x[i])le1=mid1;
            else ri1=mid1;
        }

         while(ri2-le2>1){
            mid2=(ri2+le2)/2;
            if(t[mid2]<=x[i])le2=mid2;
            else ri2=mid2;
        }

        ll tem[70]={};
        ll hou[70]={};
        ll tem_cou=0;
        ll hou_cou=0;
        rrep(j,max(0LL,le1-30),min(a,ri1+30))tem[tem_cou++]=s[j];
        rrep(j,max(0LL,le2-30),min(b,ri2+30))hou[hou_cou++]=t[j];

        ans=-100;
        rep(j,tem_cou){
            rep(k,hou_cou){
                if(ans==-100)ans=check(tem[j],hou[k],x[i]);
                else ans=min(check(tem[j],hou[k],x[i]),ans);
            }
        }
        Cout(ans);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++){
    cin>>d[i];
  }
  sort(d.begin(),d.end());
  cout<<d[N/2]-d[N/2-1]<<endl;
  return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n;
	sf("%d", &n);
	vector<int> v(n + 7);
	for (int i = 1; i < n; ++i) {
		int x;
		sf("%d", &x);
		++v[x];
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", v[i]);
	}

	return 0;
}


Measured memory_bytes: 4064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int oo = 23041997, maxN = 2e5 + 10, modP = 1e9 + 7;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < int, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int c[maxN][2], n, k, m, q[maxN], flag;
vector < int > adj[maxN];
map < PINT, int > mmap;

void bfs(int u, int t) {
    int l = 1, r = 1;
    q[1] = u; 
    c[u][t] = ++flag;
    while (l <= r) {
        int u = q[l++];
        c[u][t] = flag;
        REPU(i, adj[u].size()) {
            int v = adj[u][i];
            if (c[v][t]) continue;
            c[v][t] = flag;
            q[++r] = v;
        }
    }
}

int main() {
    cin >> n >> k >> m;
    FORU(i, 1, k) {
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u].PB(v);
        adj[v].PB(u);
    }

    FORU(i, 1, n)
        if (!c[i][0]) bfs(i, 0);

    flag = 0;
    FORU(i, 1, n) adj[i].clear();
    FORU(i, 1, m) {
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u].PB(v);
        adj[v].PB(u);
    }

    FORU(i, 1, n)
        if (!c[i][1]) bfs(i, 1);

    FORU(i, 1, n) mmap[MP(c[i][0], c[i][1])]++;
    FORU(i, 1, n) printf("%d ", mmap[MP(c[i][0], c[i][1])]);
}


Measured memory_bytes: 23040
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Measured memory_bytes: 25716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
int main() {
	int n, q, l, r;
	int c = 0;
	string s, s1;
	int v[n];
	char before = 'X';
	cin >> n >> q;
	cin >> s;
	for(int i=0;i<n;i++) {
		if(before=='A' && s[i] == 'C' ) {
			c+=1;
		}
		v[i] = c;
		before = s[i];
	}
	for(int i=0;i<q;i++) {
		cin >> l >> r;
		cout << v[r-1] - v[l-1] << endl;
	}
}

Measured memory_bytes: 3328
int main()
{
	char s[10];
	int i,a,b;
	scanf("%s",s);
	a=s[8]-'0';
	b=s[9]-'0';
	if ((a*10+b)>=1&&(a*10+b)<=31)
	{
		s[0]='2';
		s[1]='0';
		s[2]='1';
		s[3]='8';
		printf("%s\n",s);
	}
}

Measured memory_bytes: 128
w,a,b = map(int,input().split())
aw = w+a
bw = w+b

if a > b:
    if bw >= a:
        print(0)
    else:
        print(a-bw)
else:
    if aw >= b:
        print(0)
    else:
        print(b-aw)

Measured memory_bytes: 8892
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>

using namespace std;

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

    string odd;
    string even;

    bool is_odd = true;
    for(char& c : s){
        if(is_odd){
            odd += c;
        } else {
            even += c;
        }
        is_odd ^= true;
    }

    bool easy = true;
    if(easy){
        if(odd.find('L') != string::npos){
            easy = false;
        }
    }

    if(easy){
        if(even.find('R') != string::npos){
            easy = false;
        }
    }

    cout << (easy ? "Yes" : "No") << endl;

    return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k; 
    cin >> n >> k;
    vector<int> p(n);
    vector<ll> c(n);
    rep(i,n){
        cin >> p[i];
        --p[i];
    }
    rep(i,n) cin >> c[i];
    ll answ=-1000000000000000000;
    vector<ll> sum(n,0);
    vector<int> time(n,0);
    rep(i,n){
        int j=i;
        while(1){
            sum[i]+=c[p[j]];
            j=p[j];
            ++time[i];
            if(j==i) break;
        }
    }
    rep(i,n){
        ll res=0,ans=-1000000000000000000;
        int t=0,j=i;
        if(time[i]>=k || sum[i]<=0){
            int cnt;
            if(time[i]>=k) cnt=k;
            else cnt=time[i];
            while(1){
                if(t==cnt) break;
                res+=c[p[j]];
                j=p[j]; ++t;
                ans=max(res,ans);
            }
            answ=max(answ,ans);
        }else{
            int m1=0,m2=i;
            while(1){
                if(m1==(k-(k/time[i])*time[i])) break;
                res+=c[p[m2]];
                m2=p[m2]; ++m1;
            }
            j=m2;
            while(1){
                if(t==time[i]) break;
                res+=c[p[j]];
                j=p[j]; ++t;
                ans=max(ans,res);
            }
            answ=max(answ,ans+sum[i]*((k/time[i])-1));
        }
/* //        else if(sum[i]<=0 && time[i]<k) cnt=time[i];
//        else cnt=k-(k/time[i])*time[i];
        while(1){
            if(t==cnt) break;
            res+=c[p[j]];
            j=p[j]; ++t;
            ans=max(res,ans);
        }
        if(sum[i]>0 && k>time[i]) answ=max(answ,ans+sum[i]*(k/time[i]));
        else answ=max(answ,ans); */
    }
    cout << answ << "\n";
    return 0;
}   

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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

bool vis[10];
int n, m, w[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10005], ans;
vector<pair<int, int>> d;

bool smaller(string a, string b) {
    if (a.size() < b.size())  return 1;
    else if (a.size() > b.size())  return 0;
    loop (i, a.size()) {
        if (a[i] < b[i])  return 1;
        else if (a[i] > b[i])  return 0;
    }
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    cont (i, m) {
        int a;
        cin >> a;
        vis[a] = 1;
    }
    dp[0] = "#";
    cont (i, n) {
        cont (j, 9) {
            if (!vis[j])  continue;
            if (i - w[j] >= 0 && dp[i - w[j]] != null) {
                string tmp = dp[i - w[j]];
//                cout << tmp << << ' ' << j << ' ' << j + '0' << endl;
                tmp += j + '0';
                if (smaller(dp[i], tmp)) {
                    dp[i] = tmp;
                }
            }
        }
    }
    ans = dp[n].substr(1, dp[n].size() - 1);
    cout << ans << endl;
}


Measured memory_bytes: 41728
// #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int & 
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<class T>
void show(const vector<T> &a) {
	for (T x : a)
		cout << x << " ";
	cout << endl;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	string s;
	cin >> s;
	int lf = 0;
	int rf = 0;
	for (int i = 0; i < n; ++i)
		rf += s[i] == 'E';
	int ans = n;
	for (int i = 0; i < n; ++i) {
		rf -= s[i] == 'E';
		mmin(ans, lf + rf);
		lf += s[i] == 'W';
	}
	cout << ans << endl;
}


Measured memory_bytes: 720
#include<iostream>
#include<string.h>
using namespace std;

int h, w, a[85][85], b[85][85], grid[85][85][16000], ans, n, m;

void input(void) {
	cin >> h >> w;
	n = h; m = w;
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)cin >> a[i][j];
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)cin >> b[i][j];
	ans = 1000000000;
	memset(grid, -1, sizeof grid);
}

void solve(int x, int y, int diff) {
	if (x == h - 1 && y == w - 1) {
		ans = min(ans, abs(diff + (a[x][y] - b[x][y])));
		ans = min(ans, abs(diff - (a[x][y] - b[x][y])));
		return;
	}
	if (x > h || y > w)return;
	if (grid[x][y][diff] != -1)return;
	grid[x][y][diff] = 1;
	solve(x + 1, y, abs(diff + (a[x][y] - b[x][y])));
	solve(x + 1, y, abs(diff - (a[x][y] - b[x][y])));
	solve(x, y + 1, abs(diff + (a[x][y] - b[x][y])));
	solve(x, y + 1, abs(diff - (a[x][y] - b[x][y])));
}

int main() {
	input();
	solve(0, 0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 451840
#include<stdio.h>
int main()
{

  int n,m,gr[1001][1001],i,j,count[1001],x;

  while(1){

    scanf("%d%d",&n,&m);

    if(n==0 && m==0) break;
  
    for(i=0; i<n; i++){
      for(j=0; j<m; j++){
	scanf("%d",&gr[i][j]);
      }
    }

    int count[1001];

    for(i=0;i<m;i++){
      count[i]=0;
    }
    
    for(i=0; i<n; i++){
      for(j=0; j<m; j++){

	if(gr[i][j]==1){
	  count[j]+=1;
	}
      }
    }

    for(i=0;i<m;i++){

      int ans = -1;
      int maxm = -1;

      for(j=0;j<m;j++){
	if( maxm < count[j] ){
	  maxm=count[j];
	  ans=j;
	}
      }

      printf("%d",ans+1);

      count[ans] = -1;
      
      if(i+1==m){
	printf("\n");
      } else {
	printf(" ");
      }
    }
    
    /*
    for(i=0; i<m; i++){
      rank[i]+=1;
    }

    for(i=0; i<n; i++){
      if(count[i]<count[i-1]){
	x=rank[i];
	rank[i]=rank[j];
	rank[j]=x;
      }
    }
  
    for(i=0; i<m; i++){
      printf("%d",rank[i]);

    }
    */
  }

  return 0;
}

Measured memory_bytes: 6484
s = input()

# s[0] == 0
c = 0
for i in range(len(s)):
  b = i % 2
  if int(s[i]) == b:
    c += 1


# s[0] == 1
d = 0
for i in range(len(s)):
  b = (i+1) % 2
  if int(s[i]) == b:
    d += 1
    
print(min(c, d))


Measured memory_bytes: 3188
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]
    ans = 0
    memo = [0] * 26
    for i in range(1, d + 1):
        t = int(readline()) - 1
        ans += s[i - 1][t]
        memo[t] = i
        for m, cc in zip(memo, c):
            ans -= cc * (i - m)
        print(ans)


if __name__ == '__main__':
    main()

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

int main()
{
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if(s < t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int maxN = 1e5 + 10;

int n;
int a[maxN], b[maxN], c[maxN], f[maxN][5];

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i] >> b[i] >> c[i];

    f[1][0] = a[1];
    f[1][1] = b[1];
    f[1][2] = c[1];

    for(int i = 2; i <= n; ++i)
    {
        f[i][0] = max(f[i-1][1], f[i-1][2]) + a[i];
        f[i][1] = max(f[i-1][0], f[i-1][2]) + b[i];
        f[i][2] = max(f[i-1][1], f[i-1][0]) + c[i];
    }

    cout << max({f[n][0], f[n][1], f[n][2]});

}


Measured memory_bytes: 9816
#include<bits/stdc++.h>
template<class T> inline void read(T &x){
	x=0;register char c=getchar();register bool f=0;
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();if(f)x=-x;
}
const int N=5e4+10,M=1e6+10;
bool pre[2][M];
struct edge{int u,v,c;}e[N];
int n,m,q,g,z,mod,fa[N*6],tr[6][3];
inline int gcd(int n,int m){return m?gcd(m,n%m):n;}
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
signed main(){
	read(n),read(m),read(q),read(mod);
	for(int i=1;i<=m;i++){
		read(e[i].u),read(e[i].v),read(e[i].c);
		g=gcd(g,std::abs(e[i].c-e[1].c));
	}
	g=g?g:mod,mod=gcd(3*g,mod),z=e[1].c%g;
	for(int i=1;i<=6*n;i++)fa[i]=i;
	tr[0][0]=3,tr[0][1]=4,tr[0][2]=5,tr[1][0]=5,tr[1][1]=3,tr[1][2]=4,tr[2][0]=4,tr[2][1]=5,tr[2][2]=3;
	tr[3][0]=0,tr[3][1]=1,tr[3][2]=2,tr[4][0]=2,tr[4][1]=0,tr[4][2]=1,tr[5][0]=1,tr[5][1]=2,tr[5][2]=0;
	for(int i=1;i<=m;i++){
		int t=(e[i].c-z)/g%3;
		for(int j=0;j<6;j++){
			fa[find(j*n+e[i].u)]=find(tr[j][t]*n+e[i].v);
			fa[find(j*n+e[i].v)]=find(tr[j][t]*n+e[i].u);
		}
	}
	for(int u=z*1%mod;!pre[0][u];u=u*4%mod)pre[0][u]=1;
	for(int u=z*2%mod;!pre[1][u];u=u*4%mod)pre[1][u]=1;
	// for(int i=1;i<=n;i++){
	// 	printf(">>> ");
	// 	for(int j=0;j<6;j++)printf("%d%c",find(j*n+i)," \n"[j==5]);
	// }
	for(int s,t,r,fl,i=1;i<=q;i++){
		read(s),read(t),read(r),fl=0;
		for(int p=0;p<2;p++)for(int q=0;q<3;q++)if(find((p*3+q)*n+s)==find(t)){
			// printf("-> %d %d | %d %d\n",p,q,r+z-q*g,pre[p][pure(r+z-q*g)]);
			if(pre[p][(r+z+(3-q)*g)%mod]){fl=1;break;}
		}
		puts(fl?"YES":"NO");
	}
}

Measured memory_bytes: 4096
N = int(input())
A = list(map(int, input().split()))
sum = 0

for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
        sum += 1
print(*A)
print(sum)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int main()
{
  int A,P;
  cin >> A >> P;
  cout << (A * 3 + P) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

	int num = 5;
	int sum = 0;
	int dish[5];
	int i, tmp;

	for (i = 0; i < num; i++) {
		scanf("%d", &dish[i]);
		//dish[i] = dish[i] % 10;
	}

	for (i = 0; i < num; i++) {
		for (int j = i + 1; j < num; j++) {
			if (dish[j] % 10 == 0) {
				tmp = dish[j];
				dish[j] = dish[i];
				dish[i] = tmp;
			}
			else if(dish[j] % 10 > dish[i] % 10 && dish[i] % 10 != 0){
				tmp = dish[j];
				dish[j] = dish[i];
				dish[i] = tmp;
			}
		}
	}
	i = 0;
	while (num) {
		sum += dish[i];
		while (num != 1 && sum % 10 != 0)	sum += 1;
		i++;
		num--;
	}
	printf("%d", sum);
}

Measured memory_bytes: 128
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var tmp = input.split(" ");

  var a = parseInt( tmp[0], 10 );
  var b = parseInt ( tmp[1], 10 );

  var payed_price = 0;

  if ( a >= 13 ) {
    payed_price = b;
  } else if ( a >= 6 ){
    payed_price = b / 2;
  } else {
    payed_price = 0;
  }

  console.log(payed_price);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int cnt=0;
  queue<int> q;
  rep(i,n){
    if(a[i]==i+1){
      cnt++;
    }
    if(cnt>0&&(a[i]!=i+1||i==n-1)){
      q.push(cnt);
      //cout << cnt << endl;
      cnt=0;
    }
  }
  int ans=0;
  int l=q.size();
  rep(i,l){
    ans+=q.front()%2==0?q.front()/2:(q.front()+1)/2;
    q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
# coding: utf-8
N = int(input())
A = {}
for i in range(N):
    a = int(input())
    l = []
    for j in range(a):
        tmp = list(map(int, input().split()))
        l.append(tmp[:])
    A[i+1] = l[:]
ans = -1
for bit in range(2**N):
    l = []
    # 正直者と嘘つきの配列
    for i in range(N):
        if (bit >> i) & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    
    flag = True
    for i in range(N):
        # 正直者の場合、それぞれのいうことに整合性があるかを確認する
        if (bit >> i) & 1 == 1:
            for j in range(len(A[i+1])):
                # 正直者を嘘つき(もしくは逆)を言った場合はその組み合わせで
                # 整合性が取れないので成り立たない組み合わせ
                if l[A[i+1][j][0]-1] != A[i+1][j][1]:
                    flag = False
    if flag:
        ans = max(ans, sum(l))
print(ans)

Measured memory_bytes: 44140
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
 
input = sys.stdin.readline
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

a = 0
for i in range(len(v)):
    t = v[i] - c[i]
    if t > 0:
        a += t

print(a)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	char a[55][55];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				int sum=0;
				for(int ii=i-1;ii<=i+1;ii++)
				{
					for(int jj=j-1;jj<=j+1;jj++)
					{
						if(ii<n&&ii>=0&&jj<m&&jj>=0)
							if(a[ii][jj]=='#')
								sum++;
					}
				}
				printf("%d",sum);
			}
			else
				printf("%c",a[i][j]);
		}
		puts("");
	}
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        
        if(a + b >= c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
       cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
       cout << a << " " << c << " " << b << endl;
    else if(c <= a && a <= b)
       cout << c << " " << a << " " << b << endl;
    else if(c <= b && b <= a)
       cout << c << " " << b << " " << a << endl;
     else if(b <= c && c <= a)
       cout << b << " " << c << " " << a << endl;
    else if(b <= a && a <= c)
       cout << b << " " << a << " " << c << endl;
       
       
       
}



Measured memory_bytes: 3104
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

# 速度調整版
def primes(n):
    sq = int(math.sqrt(n)+1)
    ss = 30030
    a = [None] * (ss)
    a[0] = 1
    t = 1
    for i in range(2,ss):
        if not a[i] is None:
            continue
        if t * i > ss:
            break
        t *= i
        for j in range(i*2,ss,i):
            a[j] = 1
    a = [i for i in range(t) if a[i] is None]
    d = collections.defaultdict(int)
    for i in a[1:]:
        while n % i == 0:
            n //= i
            d[i] += 1

    for j in range(1,sq//t+2):
        if j > n:
            break
        for ii in a:
            i = t*j+ii
            while n % i == 0:
                n //= i
                d[i] += 1
    if n > 1:
        d[n] += 1

    return d

# 約数をすべて返す
def divisions(n):
    d = primes(n)

    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1,v+1):
                r.append(c*(k**i))

    return sorted(r)


def main():
    n,m = LI()
    d = divisions(m)
    # print(len(d),d)
    r = 1
    for c in d:
        if c * n > m:
            break
        r = c

    return r


print(main())


Measured memory_bytes: 5848
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,k;
	cin>>a>>b>>c>>k;

	if(a>=k)
		cout<<k<<endl;
	else if(a+b>=k)
		cout<<a<<endl;
	else if(a+b+c>=k)
	{
		cout<<a-(k-a-b)<<endl;
	}
	else
		cout<<a-c<<endl;
}

Measured memory_bytes: 3652
package main

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

var sc *bufio.Scanner

func nextString() string {
	sc.Scan()
	i := sc.Text()
	return i
}

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

func Prime(n int) bool {
	flag := true

	for i := 2; i <= int(math.Sqrt(float64(n))); i++ {
		if n%i == 0 {
			flag = false
			break
		}
	}
	return flag
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ans := 0
	for i := 0; i < n; i++ {
		a := nextInt()
		if Prime(a) {
			ans++
		}
	}
	fmt.Println(ans)
}



Measured memory_bytes: 1164
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            if(n==0){
                break;
            }
            for(int i=0;i<n;i++){
                int x1=sc.nextInt();
                int y1=sc.nextInt();
                int z1=sc.nextInt();
                int w1=sc.nextInt();
                int x2=sc.nextInt();
                int y2=sc.nextInt();
                int z2=sc.nextInt();
                int w2=sc.nextInt();
                System.out.print(x1*x2-y1*y2-z1*z2-w1*w2+" ");
                System.out.print(x1*y2+y1*x2+z1*w2-w1*z2+" ");
                System.out.print(x1*z2-y1*w2+z1*x2+w1*y2+" ");
                System.out.println(x1*w2+y1*z2-z1*y2+w1*x2);
            }
        }
    }
}


Measured memory_bytes: 31476
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
/*freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);*/
#define ll long long
const int inf=0x3f3f3f3f;
const int maxc=100010;
#define mod 1000000007
ll gcd(ll a,ll b){
    ll t;
    if(a>b){
        ll k=b;
        b=a;
        a=k;
    }
    while(b){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}
ll a[maxc];
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    ll minx=inf;
    int x=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0)
            x++;
        sum+=abs(a[i]);
        if(abs(a[i])<minx)
            minx=abs(a[i]);
    }
    if(x&1)
        cout<<sum-2*minx<<endl;
    else
        cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    int ary[n][n];
    rep(i,n) rep(j,n) ary[i][j]=0;

    rep(i,m)
    {
        int a,b;
        cin >> a >> b;
        --a;--b;
        ary[a][b]++;
        ary[b][a]++;
    }
    rep(i,n) {
        int ret=0;
        rep(j,n) {
            ret+=ary[i][j];
        }
        cout << ret << endl;
    }
}


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

using namespace std;

int n, a, b;
vector<int> v1[maxn], v2[maxn]; 
int x, y;
int fa[maxn][25], dep[maxn], lg[maxn];

void dfs1(int i){
	if(fa[i][0]) dep[i] = dep[fa[i][0]] + 1;
	for(int j = 1;j <= 20;j++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
	for(int j = 0;j < v2[i].size();j++){
		int to = v2[i][j];
		if(to == fa[i][0]) continue;
		fa[to][0] = i, dfs1(to);
	}
}

inline int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	while(dep[x] > dep[y]) x = fa[x][lg[dep[x] - dep[y]]];
	if(x == y) return x;
	for(int i = 20;~i;i--) if(fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}

inline int dist(int x, int y){
	return dep[x] + dep[y] - 2 * dep[lca(x, y)];
}

int d[maxn], ans;

void dfs2(int i, int fa){
	if(fa) d[i] = d[fa] + 1;
	if(d[i] >= dep[i]) return;
	ans = max(ans, dep[i]);
	for(int j = 0;j < v1[i].size();j++){
		int to = v1[i][j];
		if(to == fa) continue;
		if(dist(i, to) > 2) printf("-1"), exit(0); 
		dfs2(to, i); 
	}
}

int main(){
	scanf("%d%d%d", &n, &a, &b);
	for(int i = 2;i <= n;i++) lg[i] = lg[i - 1] + (1 << (lg[i - 1] + 1) == i);
	for(int i = 1;i < n;i++){
		scanf("%d%d", &x, &y);
		v1[x].push_back(y), v1[y].push_back(x);
	}
	for(int i = 1;i < n;i++){
		scanf("%d%d", &x, &y);
		v2[x].push_back(y), v2[y].push_back(x);
	}
	dfs1(b), dfs2(a, 0);
	printf("%d", ans * 2);
	
} 

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli dp[200100];

lli cnt[2019];

void func(string &S){

    reverse(S.begin(),S.end());

    lli ten = 1;
    REP(i,0,S.size()){
        dp[i+1] += dp[i]+(S[i]-'0')*ten;
        dp[i+1] %= 2019;
        ten *= 10;
        ten %= 2019;
    }

    REP(i,0,S.size()+1){
        cnt[dp[i]]++;
    }

    REP(i,0,S.size()+1){
        LOG2(S.size()-i,dp[i]);
    }

    lli ans = 0;

    //ans += (cnt[0]*(cnt[0]-1))/2;

    REP(i,0,2019)ans += (cnt[i]*(cnt[i]-1)/2);

    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    string S;
    cin>>S;

    func(S);
    return 0;
}


Measured memory_bytes: 5240
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=tmp*10+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll tmp=1; for(;b;b>>=1){if(b&1)tmp=tmp*a%mod; a=a*a%mod;} return tmp;}
using namespace std;
int main()
{
	int a=read(),b=read();
	if(a<=b)printf("%d\n",a);
	else printf("%d\n",a-1);
	return 0;
}

Measured memory_bytes: 128
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

N, Cn = list(map(int, input().split()))
S, T, C = zip(*[list(map(int, input().split())) for _ in range(N)])

channels = np.zeros((Cn + 1, 10 ** 5 + 1), dtype=int)
for s, t, c in zip(S, T, C):
    channels[c][s - 1] += 1
    channels[c][t] -= 1
# 同じチャンネルで連続すると 2 になっちゃうので 1 にする
counts = np.minimum(1, channels.cumsum(axis=1)).sum(axis=0)
print(counts.max())


Measured memory_bytes: 112508
#include<iostream>
using namespace std;
int main(){
	int a;
	bool stu[31]={false};
	for(int i=0;i<28;i++){
		cin>>a;
		stu[a-1]=true;
	}
	for(int i=0;i<30;i++){
		if(stu[i]==false){
			cout<<i+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3088
// https://atcoder.jp/contests/abc063/tasks/abc063_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int t = a + b;
    if (t >= 10) {
        cout << "error\n";
    } else {
        cout << t << "\n";
    }

    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    cout << max({a+b,a+a-1,b+b-1}) << endl;
}   

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int maxn = 1e6 + 3;
int n, m, k;
char mat[1111][11];
int ans = 1<<30;
int t[11], cur[11];
void go(int msk) {
	int cuts = 0;
	memset(cur, 0, sizeof cur);
	for(int j = 0; j < m; j++) {
		memset(t, 0, sizeof t);
		for(int cc = 0, i = 0; i < n; i++) {
			t[cc] += mat[j][i];
			if((msk>>i)&1) cc++;
		}
		int inc = 0;
		for(int i = 0; i < n; i++) {
			if(t[i]>k) return;
			if(cur[i]+t[i]>k) inc = 1;//, cout << cur[i] << " " << t[i] << '\n';
		}
		if(inc) {
			//cout << "cut at " << j << ",\n";
			cuts++;
		}
		for(int i = 0; i < n; i++) cur[i] = (inc?0:cur[i]) + t[i], t[i] = 0;
	}
	//cout << msk << " " << cuts << '\n';
	ans = min(ans, __builtin_popcount(msk) - 1 + cuts);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> mat[j][i], mat[j][i] -= '0';
	for(int i = 1<<(n-1); i < 1<<n; i++) {
		go(i);
	}
	cout << ans;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007LL

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int down[100005];
int a[100005];
int cnt[100005];
int l, r;
ll inv[100005];
ll fact[100005];

void factor(ll a) {
	ll ret = 1LL;
	for (ll i = 1; i <= a; i++) {
		ret = ret*i%MOD;
		fact[i] = ret;
	}
	
}

ll beki(ll a, ll p) {
	ll ret = 1LL;
	while (p > 0) {
		if (p & 1) {
			ret = ret*a%MOD;
		}
		a = a*a%MOD;
		p >>= 1;
	}
	return ret;
}

ll comb(ll a, ll b) {
	if (a < 0 || b < 0 || a < b)return 0LL;
	if (a == b || b == 0)return 1LL;
	ll ret = fact[a]*inv[b]%MOD;
	ret = ret*inv[a - b] % MOD;
	return ret;

}

int main() {
	int n;
	scanf("%d ", &n);
	rep(i, n+1) {
		scanf("%d ", &a[i]);
		cnt[a[i]]++;
		if (cnt[a[i]] == 2) {
			r = i;
		}

	}

	rep(i,n+1){
		if (a[i] == a[r]) {
			l = i;
			break;
		}
	}
	l++; r++;
	factor(n + 1);//


	FOR(i, 1, n + 1) {
		inv[i] = beki(fact[i], MOD - 2);
	}
	
	FOR(i,1,n+1) {
		printf("%lld\n", (comb(n + 1, i) + MOD - comb(n - r + l, i - 1)) % MOD);

	}
	return 0;
}


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



int main() {
    string s;
    cin >> s;
    
    sort(s.begin(),s.end());
    
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    return 0;
}




Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <set>
#include <map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
 
int h, w, n, md;
bool g[51][51] = {};
 
void answer() {
    ll res = 0;
    ll base = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (g[i][j]) res = (res+base) % md;
            base = 2*base % md;
        }
    }
    cout << "! " << res << endl;
}
 
using T = tuple<int, int, int, int>;
map<T, int> buf;
int que(int ax, int ay, int bx, int by) {
    bx--; by--;
    if (buf.count(T(ax, ay, bx, by))) return buf[T(ax, ay, bx, by)];
    cout << "? " << ay << " " << ax << " " << by << " " << bx << endl;
    int p;
    cin >> p;
    return buf[T(ax, ay, bx, by)] = p;
}


ll rand_int(ll l, ll r) { //[l, r]
    using D = uniform_int_distribution<ll>;
    static random_device rd;
    static mt19937 gen(rd());
    return D(l, r)(gen);
}

int dfs(int y, int l, int r, int nm = -1) {
    if (nm == -1) {
        nm = que(l, y, r, y+1);
    }
    if (nm == 0) return 0;
    if (l+1 == r) {
        g[y][l] = true;
        return 1;
    }
    int md = (l+r)/2;
    if (rand_int(0, 1) == 0) {
        int buf = dfs(y, l, md);
        if (nm != buf) dfs(y, md, r, nm-buf);
    } else {
        int buf = dfs(y, md, r);
        if (nm != buf) dfs(y, l, md, nm-buf);
    }
    return nm;
}
 
int main() {
    ios::sync_with_stdio(0);
    cin >> h >> w >> n >> md;
    for (int i = 0; i < h; i++) {
/*        for (int j = 0; j < w; j++) {
            g[i][j] = (que(j, i, j+1, i+1) != 0);
        }*/
        dfs(i, 0, w);
    }
    answer();
    return 0;
}
 

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

int main()
{
    long long int n,i,sum=0;
    cin>>n;

    for(i=1;i<=n;i++)
    {
        if(i==3||i==5)
            continue;
        else if(i%3==0||i%5==0)
            continue;
        else
            sum+=i;
    }

    cout<<sum<<endl;
}


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

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
  int N,M,K;
  cin >> N >> M >> K;
  UnionFind tree(N);
  vector<vector<int>> follow(N);
  vector<vector<int>> block(N);
  
  for(int i = 0; i < M; i++){
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    tmp1--; tmp2--;
    follow.at(tmp1).push_back(tmp2);
    follow.at(tmp2).push_back(tmp1);
    tree.unionSet(tmp1,tmp2);
  }
  for(int i = 0; i < K; i++){
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    tmp1--; tmp2--;
    block.at(tmp1).push_back(tmp2);
    block.at(tmp2).push_back(tmp1);
  }
  
  for(int i = 0; i < N; i++){
    // 同じ集合
    // フォロー数
    // 同じ集合かつブロックしている人をひく
    int ans = tree.size(i);
    ans -= follow.at(i).size();
    for(int j: block.at(i)){
      if(tree.root(i) == tree.root(j)){
        ans--;
      }
    }
    // 自分を引く
    ans--;
    if(i < N-1) cout << ans << " ";
    else cout << ans << endl;
  }
  
}


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

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  for(int i = 1; i < n; ++i) {
    ans = (ans + v[i]) / 2;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	ll x[5]; rep(i,5) { cin >> x[i]; if (x[i] == 0) {cout << i+1 << endl; break;} }
	//vector<ll> vs(n+1), ws(n+1);
	//rep1(i,n) cin >> vs[i] >> ws[i];
}


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

signed main() {
  int N, K;
  cin >> N >> K;
  
  map<int, int> kazu;
  int A, B;
  for( int i = 0; i < N; i++ ){
    cin >> A >> B;
    if( kazu.count(A) ) kazu[A] += B;
    else kazu[A] = B;
  }
  
  
  int cnt = 0;
  for( auto p : kazu ){
    if( cnt + p.second >= K ){
      cout << p.first << endl;
      return 0;
    }else cnt += p.second;
  }
  
  
  
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> c(N+1);
  for(int i = 0; i < N+1; i++){
    if(i == 0){
      c.at(0) = 2;
    }else if(i == 1){
      c.at(1) = 1;
    }else{
      c.at(i) = c.at(i - 1) + c.at(i - 2);
    }
  }
  cout << c.at(N) << endl;
}


Measured memory_bytes: 3616
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

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

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

    vector<int> nimber(K + 1);

    for (int i = 1; i <= K; i++) {
        vector<bool> used(N + 1);
        for (auto a : A) {
            if (i - a >= 0) {
                used[nimber[i - a]] = true;
            }
        }
        for (int j = 0; j <= 2 * N; j++) {
            if (!used[j]) {
                if (j > N) {
                    assert(false);
                }
                nimber[i] = j;
                break;
            }
        }
        //cerr << i << " : " << nimber[i] << "\n";
    }

    cout << (nimber[K] ? "First\n" : "Second\n"); 

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pic pair<int,char>
#define pci pair<char,int>
#define pll pair<ll,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define vic vector<pic>
#define vci vector<pci>
#define vlc vector<plc>
#define vcl vector<pcl>
#define pb push_back
const ll MOD=1e9+7;
const ll MAXN=1e5+3;
const ll MAXM=1e5+3;
multiset<double>ms;
int n;
double x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        ms.insert(x);
    }
    for(int i=1;i<n;i++)
    {
        double d1=(*ms.begin());
        ms.erase(ms.begin());
        double d2=(*ms.begin());
        //cout<<d1<<" "<<d2<<endl;
        ms.erase(ms.begin());
        ms.insert((d1+d2)/2);
    }
    cout<<fixed<<setprecision(10)<<(*ms.begin())<<endl;
return 0;
}


Measured memory_bytes: 256