akhauriyash/Code-Regression huggingface dataset:
N = int(input())
D_list = list(map(int, input().split()))
mod = 998244353
ans = 1
count_list = [0]*(max(D_list) + 1)
if max(D_list) >= N:
    ans = 0
else:
    for i in range(len(D_list)):
        count_list[D_list[i]] += 1
    if count_list[1] == 0:
        ans = 0
    else:
        for i in range(2, len(count_list)):
            if count_list[i] == 0:
                ans = 0
                break
            ans *= count_list[i-1]**count_list[i]

if D_list[0] != 0 or count_list[0] >= 2:
    ans = 0

print(ans%mod)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(Node u){
  if (u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
#define maxn 3001
using namespace std;

int n,m;
string s,t;
int dp[maxn][maxn];
int best[maxn][maxn];

int main() {
	cin >> s >> t;
	n = s.length();
	m = t.length();
	for( int i = n-1 ; i >= 0 ; i-- )
		for( int j = m-1 ; j >= 0 ; j-- ) {
			best[i][j] = 1;
			dp[i][j] = dp[i+1][j];
			if( dp[i][j+1] > dp[i][j] ) {
				best[i][j] = 2;
				dp[i][j] = dp[i][j+1];
			}
			if( s[i] == t[j] && dp[i+1][j+1] + 1 > dp[i][j] ) {
				best[i][j] = 0;
				dp[i][j] = dp[i+1][j+1] + 1;
			}
		}
	int x = 0 , y = 0;
	while( x < n && y < m ) {
		if( best[x][y] == 0 ) {
			cout << s[x];
			x++,y++;
		}
		else if( best[x][y] == 1 )
			x++;
		else
			y++;
	}
}


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

int n, m;
int a[105] = {0}, cnt = 0;
bool ch[10005] = {0};

int main() {
  int i, j, next = 1;
  cin >> n;
  for(i = 0; i < n; ++i) {
    cin >> a[i];
    ch[a[i]] = 1;
  }
  while(ch[next] == 1) next++;
  for(i = 1; i < n; ++i) {
    // cout << a[i] << " " << a[i - 1];
    if(a[i] == a[i - 1]) {
      cnt++;
      // cout << cnt << endl;
      a[i] = next;
    }
    while(ch[next] == 1) next++;
  }
  cout << cnt << endl;
  return 0;
}

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

int main(){
	string n;
	cin >> n;
	for(int i = 0; i < 3; i++){
		if(n[i] == '1')n[i] = '9';
		else n[i] = '1';
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
vector< vector<ll> > e;
vector<ll> l;

ll dfs(ll v) {
    if (l.at(v) >= 0) return l.at(v);
    l.at(v) = 0;
    for (ll dv : e.at(v)) l.at(v) = max(l.at(v), dfs(dv) + 1);
    return l.at(v);
}

int main() {
    ll n, m, x, y, ans = 0;
    scanf("%lld%lld", &n, &m);
    e = vector< vector<ll> >(n + 1);
    l = vector<ll>(n + 1, -1);
    for (ll i = 0; i < m; ++i) {
        scanf("%lld%lld", &x, &y);
        e.at(x).push_back(y);
    }
    for (ll i = 1; i <= n; ++i) ans = max(ans, dfs(i));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define maxn 5086

using namespace std;

int n, k;
int a[maxn];
bitset<maxn> bs;

inline bool check(int x){
	bs.reset();
	bs[0] = 1;
	for(int i = 1;i <= n;i++){
		if(i == x) continue;
		bs |= bs << a[i];
	}
	for(int i = max(0, k - a[x]);i < k;i++) if(bs[i]) return true;
	return false;
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	int l = 1, r = n, mid;
	while(l < r){
		mid = l + r >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	if(l == n && !check(n)) l++;
	printf("%d", l - 1);
}

Measured memory_bytes: 3812
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
int N;
vector <int> G[100005], G2[100005];
map <int, int> M[100005];
bool Use[100005], InQ[100005];
multiset <int> S[100005];
queue <pair <int, int> > Q;
int TT[100005], Sz[100005];
int Father(int x)
{
    int init = x;
    while(TT[x] != x)
    {
        x = TT[x];
    }
    while(init != x)
    {
        int next = TT[init];
        TT[init] = x;
        init = next;
    }
    return x;
}

void Unite(int x, int y)
{
        TT[y] = x;
        Sz[x] += Sz[y];
}
void Read()
{
    cin >> N;
    for(int i = 1; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        TT[i] = i;
        G[x].push_back(y);
        G[y].push_back(x);
        M[x][y]++;
        M[y][x]++;
        S[x].insert(y);
        S[y].insert(x);
        Sz[i] = 1;
    }
    TT[N] = N;
    Sz[N] = 1;
    for(int i = 1; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        S[x].insert(y);
        S[y].insert(x);
        M[x][y]++;
        M[y][x]++;
        if(M[x][y] == 2)
            Q.push(make_pair(x, y));
    }
}

void Solve()
{
    int cnt = 0;
    while(!Q.empty())
    {
        pair <int, int> p = Q.front();
        Q.pop();
        int x = p.first, y = p.second;
        x = Father(x);
        y = Father(y);
        if(x == y)
        {
            continue;
        }
        ++cnt;
        M[x][y] -= 2;
        M[y][x] -= 2;
        if(M[x][y] > 0)
        {
            cout << "NO\n";
            return;
        }
        /*if(M[x][y] >= 2)
            Q.push(make_pair(x, y));*/
        if(S[x].size() < S[y].size())
            swap(x, y);
        for(auto it = S[y].begin(); it != S[y].end(); it = next(it))
        {

            int neighb = *it;
            if(neighb == x)
                continue;
            auto it2 = S[neighb].find(y);
            if(it2 != S[neighb].end())
                S[neighb].erase(it2);
            S[x].insert(neighb);
            S[neighb].insert(x);
            M[y].erase(neighb);
            M[neighb].erase(y);
            M[x][neighb]++;
            M[neighb][x]++;
            if(M[x][neighb] == 2)
                Q.push(make_pair(x, neighb));
        }
        S[y].clear();
        Unite(x, y);
    }
    for(int i = 1; i <= N; i++)
        if(Sz[i] == N)
        {
            cout << "YES\n";
            return;
        }
        cout << "NO\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 58112
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct Data{
  int b;
  int c;
  bool operator<(const Data &another) const
    {
        return c < another.c;
    };
};

int main(){
  int n,m,i,j,b,c;
  cin>>n>>m;
  vector<int> a(n);
  for(i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  
  vector<Data> cs(m);
  for(i=0;i<m;i++){
    cin>>b>>c;
    cs[i].b=b;
    cs[i].c=c;
  }
  sort(cs.rbegin(),cs.rend());

  long r=0;
  j=0;
  for(i=0;i<m;i++){
    if(cs[i].c<a[j]) break;
    for(int k=0;k<cs[i].b;k++){
      if(cs[i].c>a[j]){
        a[j]=cs[i].c;
        j++;
      }
      else break;
    }
  }

  for(i=0;i<n;i++) r+=a[i];

  cout<<r<<endl;

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  map<string,int> cnt;
  
  int N;
  cin >> N;
  rep(i,N){
    string s;
    cin >> s;
    cnt[s]++;
  }

  cout << "AC x " << cnt["AC"] << endl;
  cout << "WA x " << cnt["WA"] << endl;
  cout << "TLE x " << cnt["TLE"] << endl;
  cout << "RE x " << cnt["RE"] << endl;
  
  return 0;
}



Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"in%s.txt",s);
	freopen(str,"r",stdin);
//	sprintf(str,"out%s.txt",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=100010;
const ll Inf=1000000000000000000ll;
int n,m,a[N],rt;
ll ans=0,mx,delta;

namespace Seg{
#define lson tr[o].ls,l,mid
#define rson tr[o].rs,mid+1,r
#define qlson lson,L,min(mid,R)
#define qrson rson,max(mid+1,L),R
struct tree{
	int ls,rs;ll tag,siz;
	tree(){ls=rs=tag=siz=0;}
}tr[N<<1];int cnt=0;

void build(int &o,int l,int r)
{
	o=++cnt;
	if(l==r)return;
	int mid=(l+r)>>1;
	build(lson);build(rson);
}

inline void pushdown(int o,int l,int mid,int r,int ty)
{
	if(tr[o].tag==0)return;
	int ls=tr[o].ls,rs=tr[o].rs;
	tr[ls].tag+=tr[o].tag;tr[ls].siz+=tr[o].siz;
	tr[rs].tag+=tr[o].tag+tr[o].siz*(mid-l+1ll);tr[rs].siz+=tr[o].siz;
//	if(!ty)printf("pushdown of %d %d %d %d:\n",l,mid,mid+1,r);
//	if(!ty)printf("%lld %lld\n\n",tr[o].tag,tr[o].tag+tr[o].siz*(mid-l+1));
	tr[o].tag=tr[o].siz=0;
}

void modify(int o,int l,int r,int L,int R,ll &x)
{
	if(L>R)return;
	if(l==L&&r==R){
		tr[o].tag+=x;tr[o].siz++;
//		printf("add: %d %d %lld\n",L,R,x);
		x+=r-l+1;
		return;
	}
	int mid=(l+r)>>1;
	pushdown(o,l,mid,r,0);
	if(L<=mid)modify(qlson,x);
	if(R>mid)modify(qrson,x);
}

void travel(int o,int l,int r)
{
	if(l==r){
//		printf("%lld ",tr[o].tag);
		return void(mx=max(mx,tr[o].tag));
	}
	int mid=(l+r)>>1;
	pushdown(o,l,mid,r,1);
	travel(lson);travel(rson);	
}

}

int main()
{
	n=rd();m=rd();
	fo(i,1,n)a[i]=rd();
	Seg::build(rt,1,m);
	fo(i,2,n){
		ans+=(a[i]>a[i-1])?a[i]-a[i-1]:a[i]+m-a[i-1];
		if(a[i]>a[i-1])Seg::modify(rt,1,m,a[i-1]+2,a[i],delta=1);
		else{
			Seg::modify(rt,1,m,a[i-1]+2,m,delta=1);
			if(a[i-1]<m)Seg::modify(rt,1,m,1,a[i],delta=m-a[i-1]);
			else Seg::modify(rt,1,m,2,a[i],delta=1);
		}
	}
	mx=-Inf;Seg::travel(rt,1,m);
//	puts("");
	ans-=mx;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int x,t;
  cin>>x>>t;
  cout<<(x-t>0? x-t:0)<<endl;
}

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

bool is_valid(int i, int j, int H, int W) {
  if (i < 0 || i > H - 1 || j < 0 || j > W - 1) {
    return false;
  }
  else {
    return true;
  }
}

void count(int H, int W, int i, int j, vector<vector<char>> &masu) {
  if (masu.at(i).at(j) == '#') {
    cout << '#';
  }
  else {
    int sum = 0;
    if (is_valid(i - 1, j, H, W) && masu.at(i - 1).at(j) == '#') {
      sum += 1;
    }
    if (is_valid(i + 1, j, H, W) && masu.at(i + 1).at(j) == '#') {
      sum += 1;
    }
    if (is_valid(i, j - 1, H, W) && masu.at(i).at(j - 1) == '#') {
      sum += 1;
    }
    if (is_valid(i, j + 1, H, W) && masu.at(i).at(j + 1) == '#') {
      sum += 1;
    }
    if (is_valid(i - 1, j - 1, H, W) && masu.at(i - 1).at(j - 1) == '#') {
      sum += 1;
    }
    if (is_valid(i - 1, j + 1, H, W) && masu.at(i - 1).at(j + 1) == '#') {
      sum += 1;
    }
    if (is_valid(i + 1, j + 1, H, W) && masu.at(i + 1).at(j + 1) == '#') {
      sum += 1;
    }
    if (is_valid(i + 1, j - 1, H, W) && masu.at(i + 1).at(j - 1) == '#') {
      sum += 1;
    }
    cout << sum;
  }
  if (j == W - 1) {
    cout << endl;
  }
}
   
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> masu(H, vector<char> (W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      masu.at(i).at(j) = c;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count(H, W, i, j, masu);
    }
  } 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int A[100010];char ch[100010];
ll f[100010][3];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)A[i]=gi(),ch[i]=getchar();
	for(int i=1;i<=n;++i)if(ch[i]=='-')A[i+1]*=-1;
	++n;
	memset(f,-63,sizeof f);
	f[0][0]=0;
	for(int i=1;i<=n;++i)
		for(int j=0;j<3;++j){
			for(int k=0;k<3;++k){
				if(k>=j)cxk(f[i][j],f[i-1][k]+A[i]*(j&1?-1:1));
				if(A[i]<0&&j&&k>=j-1)cxk(f[i][j],f[i-1][k]+A[i]*(~j&1?-1:1));
			}
		}
	printf("%lld\n",f[n][0]);
	return 0;
}


Measured memory_bytes: 3072
#

import sys
input=sys.stdin.readline

MOD=10**9+7
            
def main():
    N=int(input())
    A=list(map(int,input().split()))
    if N==1:
        print(1)
        exit()
    kl=[0]*(10**6+1)
    for j in range(N):
        n=A[j]
        for i in range(2,int((n)**0.5)+1):
            if n%i==0:
                cnt=0
                while(n%i==0):
                    n//=i
                    cnt+=1
                if kl[i]<cnt:
                    kl[i]=cnt
        if n!=1:
            if kl[int(n)]<1:
                kl[int(n)]=1
                
    lcm=1
    for i in range(2,10**6+1):
        lcm*=i**kl[i]
        lcm%=MOD
    ans=0
    for i in range(N):
        ans+=lcm*pow(A[i],MOD-2,MOD)
        ans%=MOD
    print(ans)
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 53852
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n;
    cin >> n;
    vector <long long> a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    long long ans = 0;

    for(int i=0; i<n; i++){
        if(a[i] >= b[i]){
            ans += b[i];
        }
        else{
            ans += a[i];
            if(a[i+1] <= (b[i]-a[i])){
                ans += a[i+1];
                a[i+1] = 0;
            }
            else{
                ans += (b[i] - a[i]);
                a[i+1] -= (b[i] - a[i]);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4768
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
	long long int n, a, b;
	cin >> n >> a >> b;
	if(a > b || (n == 1 && a != b)) cout << 0 << endl;
	else cout << (b - a) * (n - 2) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>//B
#include<cstdio>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    int ans;
    if((b-1)%(a-1)) ans=(b-1)/(a-1)+1;
    else ans=(b-1)/(a-1);
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long fib[233],x,y,ans;
int now;long long all;
void dfs(long long u,long long v,int c,int err)
{
	//cout<<u<<' '<<v<<' '<<c<<' '<<err<<' '<<(((u>=fib[c+2])&&(v>=fib[c+3]))||(u>x)||(v>y))<<endl;
	if (((u>=fib[c+2])&&(v>=fib[c+3]))||(u>x)||(v>y)) return;
	//if (c==now) {ans+=(int)((u<=x)&&(v<=y))+(int)((v<=x)&&(u<=y));return;}
	if (c==now-1)
	{
		ans+=max(0ll,(y-u)/v)*(v<=x)+max(0ll,(x-u)/v)*(v<=y);
		return;
	}
	if (!err)
	{
		dfs(v,u+v,c+1,0);
		dfs(v,u+v+v,c+1,1);
		//v,u+kv
		//p=fib[now-c-2]*v+fib[now-c-1]*(u+kv)
		//q=fib[now-c-1]*v+fib[now-c]*(u+kv)
		//p<=x q<=y
	}
	else if (err==1) dfs(v,u+v,c+1,1);
}
int main()
{
	fib[0]=0;fib[1]=1;for (int i=2;i<=90;i++) fib[i]=fib[i-1]+fib[i-2];
	int q;scanf("%d",&q);
	while (q--)
	{//if (q%1000==0) cerr<<q<<endl;
		scanf("%lld%lld",&x,&y);if (x>y) swap(x,y);
		if (x==1) {printf("1 %lld\n",y%1000000007);continue;}
		if (y==2) {printf("1 4\n");continue;}
		now=0;while ((fib[now+2]<=x)&&(fib[now+3]<=y)) now++;
		printf("%d ",now);
		ans=0;dfs(1,1,0,0);
		printf("%lld\n",ans%1000000007);
	}
	//cerr<<all<<endl;
}

Measured memory_bytes: 4096
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> all(n);
    for(int i = 0; i < n; i++){
        cin >> all[i].first >> all[i].second;
    }
    sort(all.begin(), all.end(), [&](const pair<int, int> &x, const pair<int, int> &y){
        if(x.first == y.first)
            return x.second > y.second;
        return x.first < y.first;
    });
    ll res = 0, curr = m;
    for(auto p : all){
        ll no = p.second;
        // cout << no << " " << curr << " " << res << "\n";
        if(no <= curr){
            res += (no * p.first);
            curr -= no;
        }
        else{
            res += (curr * p.first);
            curr = 0;
        }
        if(curr <= 0)
            break;
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,n,sum,k;
    cin>>n;
    k=n;
    sum=0;
    while(k!=0)
    {
        sum=sum+k%10;
        k=k/10;
    }
//    cout<<sum<<endl;
    if(n%sum==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int main() {
    int N;
    cin>>N;
    vector<int> D;
    map<int, int> Dmap;
    int tmp;
    long ans;
    long mod = 998244353;
    for(int i=0;i<N;++i){
        cin>>tmp;
        D.push_back(tmp);
    }
    if(D[0] != 0){
        ans = 0;
    }
    else {
        ans = 1;
    }
    Dmap[0]++;
    sort(D.begin(), D.end());
    for(int i=1;i<D.size();++i){
        if(D[i] == 0){
            ans = 0;
        }
        Dmap[D[i]]++;
    }
    /**
    for(int i=0;i<D[D.size()-1];++i){
        cout<<i<<" "<<Dmap[i]<<endl;
    }
    **/
    for(int i=0;i<D[D.size()-1];++i){
        for(int j=0;j<Dmap[i+1];++j){
            ans *= Dmap[i];
            ans %= mod;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5368
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  int l_sum = 0;
  int i;
  for (i = 0; i < n; i++) {
    cin >> l[i];
    l_sum += l[i];
  }
  sort(l.begin(), l.end());
  l_sum -= l[n - 1];
  cout << (l_sum > l[n - 1] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
int cmp(const void *p,const void *q){
    return *(int*)p-*(int*)q;
}
int main(void){
    int a[1000];
    int n,i,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(a[0]),cmp);
    for(i=0;i<n-1;i++){
        sum+=a[i+1]-a[i];
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1020, mod = 1e9 + 7, i2 = (mod+1)/2;
ll n, a, b, c, d, dp[maxn][maxn], C[maxn][maxn];
ll bp(ll a, ll p) {
	ll r = 1;
	while(p) {
		if(p&1) r = r*a%mod;
		a = a*a%mod, p>>=1;
	}
	return r;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> a >> b >> c >> d;
	dp[0][a] = 1;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= i; j++) {
			if(!j) C[i][j] = 1;
			else C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod;
		}
	for(int i = 0; i <= n; i++) {
		for(int j = a; j <= b; j++) {
			//cout << i << " " << j << " " << dp[i][j] << '\n';;
			(dp[i][j+1] += dp[i][j])%=mod;
			ll t = 1;
			for(int k = 0; k < c && n-i-k*j >= 0; k++) {
				t = t*C[n-i-k*j][j]%mod;
				t = t*bp(k+1, mod-2)%mod;
			}
			for(int k = j*c; i+k <= n && k <= j*d; k+=j) {
				(dp[i+k][j+1] += dp[i][j]*t)%=mod;
				t = t*C[n-i-k][j]%mod;
				t = t*bp((k/j)+1, mod-2)%mod;
			}
		}
	}
	cout << dp[n][b+1];
	return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
static const double cos60 = 0.5;
static const double sin60 = sqrt(3) / 2;

class Point {
    public:
        double x;
        double y;
};

void koch(int d, Point p1, Point p2) {
    if (d == 0) return;
    Point s, u, t;
    s.x = (2 * p1.x + p2.x) / 3;
    s.y = (2 * p1.y + p2.y) / 3;
    t.x = (p1.x + 2 * p2.x) / 3;
    t.y = (p1.y + 2 * p2.y) / 3;
    u.x = (t.x - s.x) * cos60 - (t.y - s.y) * sin60 + s.x;
    u.y = (t.x - s.x) * sin60 + (t.y - s.y) * cos60 + s.y;
    koch(d-1, p1, s);
    cout << fixed << setprecision(8) << s.x << " " << s.y << endl;
    koch(d-1, s, u);
    cout << fixed << setprecision(8) << u.x << " " << u.y << endl;
    koch(d-1, u, t);
    cout << fixed << setprecision(8) << t.x << " " << t.y << endl;
    koch(d-1, t, p2);
}

int main() {
    int n;
    cin >> n;
    Point p1, p2;
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;
    cout << fixed << setprecision(8) << p1.x << " " << p1.y << endl;
    koch(n, p1, p2);
    cout << fixed << setprecision(8) << p2.x << " " << p2.y << endl;
    
    return 0;
}


Measured memory_bytes: 3284
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(void){
  int a,b,x;

  scanf("%d%d%d", &a, &b, &x);

  if(a > x)
    puts("NO");
  else{
    if((a+b) >= x)
      puts("YES");
    else
      puts("NO");
  }

  
  
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

min_capa = min(A,B,C,D,E)
neck_pass_time = max(1, (N + min_capa - 1) // min_capa)
ans = 4 + neck_pass_time
print(ans)

Measured memory_bytes: 3064
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}

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

  ll K, X;
  cin >> K >> X;

  out(500 * K >= X ? "Yes" : "No");
}


Measured memory_bytes: 256
# ABC 65, B - trained
n = int(input())
A = [int(input()) for i in range(n)]
now = 1
went = set()
for i in range(n):
    if now == 2:
        print(i)
        break
    if now in went:
        print(-1)
        break
    went.add(now)
    now = A[now-1]


Measured memory_bytes: 13220
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
namespace {

	void chmin(long long& x, long long y)
	{
		if (x > y || x < 0)
			x = y;
	}

	void chmax(long long& x, long long y)
	{
		if (x < y)
			x = y;
	}

	void core()
	{
		long N;
		cin >> N;

		long W;
		cin >> W;

		std::vector<long long> w(N + 1, 0);
		std::vector<long long> v(N + 1, 0);

		for (long i = 1; i <= N; ++i)
		{
			cin >> w[i];
			cin >> v[i];
		}

		vector<vector<long long>> dp(N + 1, vector<long long>(W+1, -1));
		for (long j = 0; j <= W; ++j)
			dp[0][j] = 0;


		for (long i = 1; i <= N; ++i)
		{
			auto this_weight = w[i];
			for (long j = 0; j <= W; ++j)
			{
				if (j - this_weight >= 0)
					chmax(dp[i][j], dp[i - 1][j-this_weight] + v[i]);
				chmax(dp[i][j], dp[i - 1][j]);
			}
		}

		long long ret = dp[N][W];

		cout << ret;
	}
}

int main()
{
	core();

	return 0;
}

//int main()
//{
//	for (long i = 0; i < 3; ++i)
//	{
//		cout << "Input test" << endl;
//		core();
//		cout << endl;
//	}
//
//	cout << "test ended" << endl;
//
//	int ret;
//	cin >> ret;
//
//	return 0;
//}

Measured memory_bytes: 80256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<i32>();
    let t=(read::<i32>()-read::<i32>())*1000;
    let mut ans=1000000000;
    let mut id=0;
    let mut i=0;
    for h in (0..n).map(|_|read::<i32>()){
        let now=(t-h*6).abs();
        i+=1;
        if now<ans{
            ans=now;
            id=i
        }
    }
    println!("{}",id)
}


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

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

    int N = S.size();

    string revS = S;
    string smallS;
    reverse(revS.begin(), revS.end());
    smallS = S.substr(0, (N-1)/2);
    string revSmallS = smallS;
    reverse(revSmallS.begin(), revSmallS.end());

    if ((revS == S) and (revSmallS == smallS)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    int64 ans=0;
    rep1(i, n){
        if (i%3!=0 && i%5!=0)
            ans += i;
    }
    co(ans);

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>

using namespace std;

#define MAX 110

struct Page{
  int sx,sy,tx,ty;
  string next;
  Page(int sx,int sy,int tx,int ty,string next)
    : sx(sx),sy(sy),tx(tx),ty(ty),next(next) {}
};

vector<Page> vec[MAX];

void init(){
  for(int i = 0 ; i < MAX ; i++){
    vec[i].clear();
  }
}

int main(){
  int N,W,H,b,sx,sy,tx,ty;
  string str[MAX],s;

  while(cin >> N,N){
    int p = 0;
    cin >> W >> H;
    init();
    for(int i = 0 ; i < N ; i++){
      cin >> str[i] >> b;
      for(int j = 0 ; j < b ; j++){
        cin >> sx >> sy >> tx >> ty >> s;
        vec[i].push_back(Page(sx,sy,tx,ty,s));
      }
    }
    int m,w,h,now = 0;
    vector<int> now_page;
    now_page.push_back(now);
    string next;
    cin >> m;
    for(int I = 0 ; I < m ; I++){
      cin >> s;
      if(s == "click"){
        bool found = false;
        cin >> w >> h;
        for(int i = 0 ; i < vec[now_page[p]].size() ; i++){
          sx = vec[now_page[p]][i].sx, sy = vec[now_page[p]][i].sy;
          tx = vec[now_page[p]][i].tx, ty = vec[now_page[p]][i].ty;
          next = vec[now_page[p]][i].next;
          if(sx <= w && w <= tx && sy <= h && h <= ty){
            for(int j = 0 ; j < N ; j++){
              if(str[j] == next){
                now = j;
                found = true;
                break;
              }
            }
          }
          if(found){
            p++;
            while(p < now_page.size()){
              now_page.pop_back();
            }
            now_page.push_back(now);
            break;
          }
        }
      }else if(s == "show"){
        cout << str[now_page[p]] << endl;
      }else if(s == "back"){
        if(p > 0) p--;
      }else{
        if(p+1 < now_page.size()) p++;
      }
    }
  }

  return 0;
}

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

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

int main() {
    set<int> s;
    int q, x, c;
    cin >> q;
    while (q--) {
        cin >> c;
        if (c == 0) {
            cin >> x;
            s.insert(x);
            cout << s.size() << endl;
        } else {
            cin >> x;
            if (s.find(x) != s.end()) { cout << 1 << endl; }
            else cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12468
#include <iostream>
#include <map>

using namespace std;

const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    int k = 0;
    for (auto& p : mp) p.second = k++;
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    string hi="hi";
    bool flag=true;
    for(int i=0,j=0;i<str.size();++i,j=(j+1)%2)
    {
        if(str[i]!=hi[j])
            flag=false;
    }
    if(str.size()%2==1)
        flag=false;
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int a,b,c,d;
    cin>>a>>b>>c>>d;
    ll int z=max(a*c,max(a*d,max(b*c,b*d)));
    cout<<z<<endl;
}


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

long long res(long long a){
	long long b=0;
	while (a%2==0){
		a/=2;
		b++;
	}
	return b;
}
int main() {
	int n;
	long long ans=0,temp;
	cin>>n;
	long long a[n];
	for (int i=0;i<n;i++){
		cin>>a[i];
		ans=ans+res(a[i]);
		//cout<<"Power of "<<a[i]<<"="<<res(a[i])<<endl;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf LLONG_MAX

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

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

    ll test=1;
    //cin>>test;
    while(test--)
    {
        string str;
        cin>>str;

        string sub=str.substr(0,3);

        cout<<sub;
    }
}

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

int main(){
  int A,B;
  cin>>A>>B;
  int j=0;
  
  for(int i=A;i<=B;i++){
    if(i/10000==i-i/10*10&&i/1000-i/10000*10==i/10-i/100*10){
      j++;
    }
  }
  cout<<j<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;

	int h[n];
	int dp[n];

	for(int i=0;i<n;i++)
		dp[i]=INT_MAX;

	for(int i=0;i<n;i++)
		cin>>h[i];

	dp[0]=0;
	

	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(j+i<n)
				dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
		}
	}

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

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int D, G;
	vector<ll> P, C;
	cin >> D >> G;
	for(int i = 0; i < D; i ++){
		ll p, c;
		cin >> p >> c;
		P.pb(p);
		C.pb(c);
	}
	unsigned int bit = pow(2, D) - 1;
	int ans = 1005;
	while(bit <= pow(2, D) - 1){
		ll pointSum = 0, quesNum = 0;;
		for(int i = 0; i < D; i ++){
			if(bit & (1 << i)){
				pointSum += (i + 1) * 100 * P[i] + C[i];
				quesNum += P[i];
			}
		}
		for(int i = D - 1; i >= 0; i --){
			if(!(bit & (1 << i))){
				for(int j = 1; j < P[i] && pointSum < G; j ++){
					pointSum += (i + 1) * 100;
					quesNum ++;
				}
				break;
			}
		}
		if(pointSum >= G && ans > quesNum)ans = quesNum;
		bit --;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct Node { int p, l, r; };
Node *T;
int *D;

void print(int u) {
        cout << "node " << u << ": ";
        cout << "parent = " << T[u].p << ", ";
        cout << "depth = " << D[u] << ", ";

        if (T[u].p == -1)               cout << "root, ";
        else if (T[u].l == -1)  cout << "leaf, ";
        else                                    cout << "internal node, ";

        cout << "[";
        int ifs = 0;
        for (int c = T[u].l; c != -1; c = T[c].r) {
                if (ifs)
                        cout << ", ";
                cout << c;
                ifs = 1;
        }
        cout << "]" << endl;
}

void rec(int u, int p) {
        D[u] = p;
        if (T[u].r != -1) rec(T[u].r, p);
        if (T[u].l != -1) rec(T[u].l, p + 1);
}

int main() {
        int n;
        cin >> n;
        T = new Node[n];
        D = new int[n];

        for (int i = 0; i < n; i++)
                T[i].p = T[i].l = T[i].r = -1;

        for (int i = 0; i < n; i++) {
                int id, k, c, l;
                cin >> id >> k;
                for (int j = 0; j < k; j++) {
                        cin >> c;
                        if (j == 0) T[id].l = c;
                        else        T[l].r = c;
                        l = c;
                        T[c].p = id;
                }
        }

        int r;
        for (int i = 0; i < n; i++) {
                if (T[i].p == -1) {
                        r = i;
                        break;
                }
        }
        rec(r, 0);

        for (int i = 0; i < n; i++)
                print(i);

        delete T;
        delete D;
        return 0;
}

Measured memory_bytes: 7588
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

struct ST {
  int p;
  int i;
};
bool operator<(const ST& a, const ST& b){
  return a.p < b.p;
}


int main(){
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ST> P;
  rep(i,N){
    int a;
    cin >> a;
    a--;
    P.push_back((ST){a,i});
  }
  sort(ALLOF(P));
  
  vector<ll> A, B;
  rep(i,N){
    A.push_back((i+1)*25000LL);
    B.push_back((i+1)*25000LL);
  }
  reverse(ALLOF(B));
  rep(i,N){
    A[P[i].p] += P[i].i;
  }

  rep(i,N){
    if(i!=0) cout << " ";
    cout << A[i];
  }
  cout << endl;
  rep(i,N){
    if(i!=0) cout << " ";
    cout << B[i];
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 1444
#include<iostream>
#include<iomanip>
using namespace std;
long long n,k,x,i,a[100001];
int main()
{
	cin >>n>>k;
	
	for (i=1; i<=n; i++)
	cin >>a[i];
	
	for (i=1; i<=n; i++)
	if (a[i]>=k)
	x++;
	
	cout <<x<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define MAX  2000000
#define VMAX 10000

static int A[MAX];
static int B[MAX];

int main()
{
    int n;
    int C[VMAX + 1];

    scanf("%d", &n);
    for (int i = 0; i <= VMAX; i++) {
        C[i] = 0;
    }

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
        C[A[i]]++;
    }

    for (int i = 1; i <= VMAX; i++) {
        C[i] = C[i] + C[i - 1];
    }

    for (int i = 0; i < n; i++) {
        C[A[i]]--;
        B[C[A[i]]] = A[i];
    }

    for (int i = 0; i < n; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 17388
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  set<int>st;
  int a , c,b;
  cin>>a>>b>>c;
  st.insert(a);
 st.insert(b); st.insert(c);
 if(st.size()==2)
   cout<<"Yes\n";
  else
  {
    cout<<"No\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
import itertools

K = int(input())

# K = 2


def gcd(*numbers):
    return reduce(math.gcd, numbers)


ans = 0
for i in range(1, K + 1):
    # i = 1
    ans += gcd(i, i, i)

    for j in range(i + 1, K + 1):
        ans += gcd(i, i, j) * 3

    for j, k in itertools.product(range(i + 1, K + 1), range(i + 1, K + 1)):
        ans += gcd(i, j, k) * 3

print(ans)


Measured memory_bytes: 9656
n=int(input())
l=list(map(int,input().split()))
def solve(n,l):
     if n==1:
        return 0
     ans=0
     m=0
     for i in range(n):
         if l[i]>=m:
            m=l[i]
         else:
            ans+=max(0,m-l[i])
     return ans
print(solve(n,l))

Measured memory_bytes: 105172
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

const ll MOD = 1e9 + 7;

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

  reverse(s.begin(), s.end());
  int n = s.size();
  vector<ll> dp(13, 0);
  dp[0] = 1;

  ll keta = 1;
  rep(is, n){
    vector<ll> new_dp(13, 0);
    if (s[is] == '?'){
      rep(i, 10){
        int m = (keta * i) % 13;
        rep(j, 13){
          int ni = (j + m) % 13; 
          new_dp[ni] += dp[j];
          new_dp[ni] %= MOD;
        }
      }
    }else{
      ll idx = (s[is] - '0') * keta;
      rep(i, 13){
        new_dp[(i+idx) % 13] = dp[i];
      }
    }

    dp = new_dp;
    keta *= 10; keta %= 13;
  }
  cout << dp[5] << endl;
  return 0;
}

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

const int N = 200005;

int x;

int solve() {
  scanf("%d", &x);
  vector<long long> v;
  for (int i = -200; i < 200; ++i) {
    v.push_back(1LL * i*i*i*i*i);
  }

  for (int i = 0; i < v.size(); ++i) {
    if (binary_search(v.begin(), v.end(), x + v[i])) {
      return 0 * printf("%d %d\n", lower_bound(v.begin(), v.end(), x + v[i]) - v.begin() - 200, i - 200);
    }
  }

  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
#define PB push_back
using namespace std;
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int n,ans;
int main(void){
    cin>>n>>ans;
    for(int i=0;i<n-1;i++){
        int a;
        cin>>a;
        ans=gcd(ans,a);
    }
    cout<<ans<<endl;
}


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

struct Card{
    char M;
    int value;
};

void bubble(Card A[],int n){
    for(int i=0;i<n;i++){
        for(int s=n-1;s>i;s--){
            if(A[s].value<A[s-1].value){
                Card a=A[s];
                A[s]=A[s-1];
                A[s-1]=a;
            } 
        }
    }
    return;
}

void select(Card A[],int n){
    for(int i=0;i<n;i++){
        int min = i;
        for(int j=i+1;j<n;j++){
            if(A[j].value<A[min].value)min=j;
        }
        if(i != min){
            Card a=A[i];
            A[i]=A[min];
            A[min]=a;
        }
    }
    return;
}

int main(){
    int N;
    Card A[40],B[40];
    bool b=true;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i].M >> A[i].value;
        B[i]=A[i];
    }

    bubble(A,N);
    select(B,N);

    for(int i=0;i<N;i++){
        if(i== N-1)cout << A[i].M << A[i].value << endl;
        else cout << A[i].M  << A[i].value << " " ;
    }
    cout << "Stable" << endl;    

    for(int i=0;i<N;i++){
        if(i== N-1)cout << B[i].M << B[i].value << endl;
        else cout << B[i].M << B[i].value << " " ;
    }

    for(int i=0;i<N;i++){
       if(A[i].M != B[i].M)b=false;
    }
    if(b == true)cout << "Stable" <<endl;
    else cout << "Not stable" << endl;

    return 0;

}


Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() { ios_base::sync_with_stdio(0); cin.tie(0); }

static const int N = 10005;
vi p(N, -1);
vi d(N, 1);

void unite(int x, int y) {
	while (p[x] != -1) {
		x = p[x];
	}
	while (p[y] != -1) {
		y = p[y];
	}
	if (x == y) return;
	if (d[x] > d[y]) p[y] = x;
	else if (d[x] < d[y]) p[x] = y;
	else {
		p[y] = x;
		d[x]++;
	}
}

bool same(int x, int y) {
	while (p[x] != -1) {
		x = p[x];
	}
	while (p[y] != -1) {
		y = p[y];
	}
	if (x == y) return 1;
	else return 0;
}

int main() {
	fastios();
	int n, q;
	cin >> n >> q;
	Loop(i, q) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) unite(x, y);
		else cout << same(x, y) << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int digit;
	int a = 0, b = 0;
	string sum;

	while ( cin >> a >> b )
	{
	
		digit = log10( a + b ) + 1;
		cout << digit << endl;
	}

	return 0;

}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int count = 0;
    while (n != 0)
    {
        n /= k;
        count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256