akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = (int) 3e6 + 10;
const long long MOD = 998244353;

int n, m;
long long f[N], g[N];

long long fpow(long long x, long long y) {
	if (y == 0) {
		return 1LL;
	}
	if (y % 2 == 0) {
		return fpow(x * x % MOD, y / 2);
	} else {
		return x * fpow(x, y - 1) % MOD;
	}
}

long long choose(int n, int m) {
	if (n < 0 || m < 0 || m > n) {
		return 0LL;
	}
	/*memset(c, 0, sizeof c);
	c[0][0] = 1;
	for (int i = 0; i < 50; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			c[i][j] = c[i-1][j-1]+c[i-1][j];
		}
	}
	return c[n][m];*/
	long long ret = (f[n] * g[m] % MOD) * g[n - m] % MOD;
	//printf("dbg %d %d %lld\n",n,m,ret);
	return ret;
}

long long calc(int n, int s, int m) {
	long long res = 0;
	for (int i = 0; i <= n && i <= m; i++) {
		int j = s - i;
		if (j >= 0 && j % 2 == 0) {
			long long u = choose(n, i);
			long long v = choose(j / 2 + n - 1, n - 1);
			res = (res + u * v) % MOD;
		}
	}
	return res;
}

int main() {

	f[0] = 1;

	for (int i = 1; i < N; i++) {
		f[i] = f[i - 1] * i % MOD;
	}

	g[N - 1] = fpow(f[N - 1], MOD - 2);

	for (int i = N - 2; i >= 0; i--) {
		g[i] = g[i + 1] * (i + 1) % MOD;
	}

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

	long long res = calc(n, 3 * m, m) - (calc(n, m, m) - calc(n - 1, m, m)) * n % MOD;

	printf("%lld\n", (res % MOD + MOD) % MOD);

	return 0;

}

Measured memory_bytes: 50696
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int h,m,s;
  cin>>s;
  h=s/3600;
  m=(s%3600)/60;
  s=(s%3600)%60;
  cout<<h<<":"<<m<<":"<<s<<"\n";
  return(0);
}



Measured memory_bytes: 3120
// Problem : C - 4-adjacent
// Contest : AtCoder - AtCoder Beginner Contest 069
// URL : https://atcoder.jp/contests/abc069/tasks/arc080_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
vi v(n);cin>>v;
int cnt1=0,cnt2=0;
for(int i:v)
if(i%4==0)cnt1++;
else if(i%2==0)cnt2++;
if(cnt1+(cnt2/2)>=n/2)
cout<<"Yes";
else
cout<<"No";
}

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


Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
vector<pair<long long int,long long int> >a;
long long int b[1000],ans,c,d,h,w,n,m;

int main(){
    cin>>n>>m;

    for(int i=0;i<n;i++){
        cin>>h>>w;
        a.push_back(make_pair(h,w));
    }
    sort(a.begin(),a.end());
    int i=0;
    while(m){
        if(a[i].second>=m){ans+=a[i].first*m;m=0;break;}
        ans+=a[i].first*a[i].second;
        m-=a[i].second;
        i++;
    }
    cout<<ans<<endl;

}


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

using namespace std;

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

    int x,y;
    cin>>x>>y;

    if(y%2==0){
        if(y<=x*4 && y>=x*2){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
    else{
        cout<<"No\n";
    }


    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;


long long extgcd(long long a)
{
	long long b = MOD;
	long long u = 1, v = 0, q; 
	while ( b > 0 ) {
		q = a / b; 
		a -= q * b; swap(a,b);
		u -= q * v; swap(u,v);
	}
	u %= MOD;
	while (u<0)
		u+=MOD;
	return u;
}
long long comb(long long n,long long k)
{
	long long t = 1;
	long long j = k;
	for(long long i = n; i  >= n-k+1; i--) {
		t *= i;
		t %= MOD;
		t *= extgcd(j);
		t %= MOD;
		j--;
	}  
  	while (t<0)
		t += MOD;
	return t;
}

int main(){
	int n,t;
	cin >> n;
  	vector<int> a(n);
  	rep(i,n-1) {
    	cin >> t;
    	a[t-1]++; 
    }
  	rep(i,n) {
    	cout << a[i] << endl;
    }
}


Measured memory_bytes: 3988
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*2 for i in range(n)]
infi=10**10
for i in reversed(range(n)):
  if i>=1:
    y=a[i-1]
    x=a[i-1]
  else:
    y=w
    x=z
  dp[i][0]=-infi
  dp[i][0]=max(dp[i][0],abs(y-a[n-1]))
  for j in range(i+1,n):
    dp[i][0]=max(dp[i][0],dp[j][1])
  dp[i][1]=infi
  dp[i][1]=min(dp[i][1],abs(x-a[n-1]))
  for j in range(i+1,n):
    dp[i][1]=min(dp[i][1],dp[j][0])
print(dp[0][0])

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

def cnt_yakusu(s):
    cnt = 0
    for i in range(1, s+1):
        if s % i == 0:
            cnt += 1
    return cnt
    
ans = 0
for i in range(1,n+1):
    if cnt_yakusu(i) == 8 and i % 2 == 1:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
typedef long long ll;

int n,a[maxn];

bool chk(ll x){
	for(int i=1;i<=n;++i){
		x=x-x%a[i];
	}
	if(x<2)return 0;
	return 1;
}

bool chk2(ll x){
	for(int i=1;i<=n;++i){
		x=x-x%a[i];
	}
	if(x<=2)return 1;
	return 0;
}

void solve(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	ll l=1,r=9e18,ans1,ans2;
	for(ll mid;l<=r;){
		mid=l+(r-l>>1);
		if(chk(mid))r=mid-1;
		else l=mid+1;
	}
	ans1=l;
	l=1,r=9e18; 
	for(ll mid;l<=r;){
		mid=l+(r-l>>1);
		if(chk2(mid))l=mid+1;
		else r=mid-1;
	}
	ans2=r;
	if(ans1>ans2)puts("-1");
	else cout<<ans1<<" "<<ans2<<endl;
}
int main(){
	solve();
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;

long long W, weight[110], value[110];
long long dp[110][100010];
int main(){
    cin >> N >> W;
    
    for (int i=0; i< N; ++i) cin >> weight[i] >> value[i];
    
    for(int i=0; i< N; ++i){
        for(int j=0; j<= W; ++j){
            if(j - weight[i] >= 0){
                chmax(dp[i+1][j], dp[i][j-weight[i]] + value[i]);
            }
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    
    cout << dp[N][W] << endl;
    
    return 0;
}

Measured memory_bytes: 79360
# include <iostream>
# include <cstdio>
using namespace std;
long long A,B,C,ans = 1e18;
int x,y;
int main()
{
  scanf("%lld %lld %lld %d %d",&A,&B,&C,&x,&y);
  for(int i = 0;i <= max(x,y);i++)
  ans = min(ans,2LL * i * C + A * max(x - i,0) + B * max(y - i,0));
  printf("%lld\n",ans);
}

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

using namespace std;
using namespace atcoder;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

using P = pair<ll,ll>;

ll extgcd(ll a, ll b, ll& x, ll& y) {

    if (a < b) return extgcd(b, a, y, x);
    // xとyを入れ替え忘れないように注意
    
    if (b > 0) {
        ll g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
        return g;
    } else {
        x = 1, y = 0;
        return a;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    map<ll,ll> mp;
    ll x = 2*N;
    for(ll i=2;i*i<=2*N;i++){
        while(x%i==0){
            mp[i]++;
            x /= i;
        }
    }
    if(x!=1) mp[x]++;
    vec<ll> primes;
    for(auto x:mp){
        ll v = 1;
        for(int i=0;i<x.second;i++) v *= x.first;
        primes.emplace_back(v);
    }
    int n = primes.size();
    ll inf = 2e18,ans = inf;
    for(int S=0;S<(1<<n);S++){
        ll a = 1,b = 1;
        for(int i=0;i<n;i++){
            if(S>>i&1) a *= primes[i];
            else b *= primes[i];
        }
        auto [y,z] = crt({0,b-1},{a,b});
//        cerr << res.first << " " << res.second << "\n";
        ll x = (a-y+z-1)/z;
        chmin(ans,z*x+y);
    }
    cout << ans << "\n";
}

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

int main() {
	vector <bool> prime(110000, false);
	prime[2] = true;
	for (int i = 3; i < 110000; i += 2) {
		prime[i] = true;
	}
	for (int i = 3; i < 110000; i += 2) {
		for (int j = i + i; j <= 110000; j += i) {
			prime[j] = false;
		}
	}
	int n;
	while (cin >> n && n > 0) {
		int sum = 2;
		int cnt = 1;
		for (int i = 3; cnt < n; i += 2) {
			if (prime[i]) {
				sum += i;
				cnt++;
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1208
n = int(input())
l = list(map(int,input().split()))
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]:
                    cnt += 1
print(cnt)

Measured memory_bytes: 68256
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
//const long long INF = 1LL << 60;
const int INF = 1e9;
using ll = long long;

int main()
{
    ll a, b, c, d;
    std::cin >> a >> b >> c >> d;

    ll ans = 0;

    ans = a * c;
    ans = std::max(ans, a * d);
    ans = std::max(ans, b * c);
    ans = std::max(ans, b * d);

    std::cout << ans;
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
// int n;
// int a[10005][10005];
// int solve(int i,bool k1,bool k2,bool k3)
// {
// 	if(i<0)
// 		return 0;
// 	if(i==0)
// 		return max(a[0][0],max(a[0][1],a[0][2]));
	
		

// 	//return max(solve(i-1,k1,k2,!k3)+a[i][2],max(solve(i-1,k1,!k2,k3)+a[i][1],solve(i-1,!k1,k2,k3)+a[i][0]));
// 	if(i==n-1){
// 		return max(solve(i-1,!k1,k2,k3)+a[n-1][0],max(solve(i-1,k1,!k2,k3)+a[n-1][1],solve(i-1,k1,k2,!k3)+a[n-1][2]));
// 	}
// 	else{
       
//         return !k1?max(solve(i-1,!k1,))

// 	}


// }

int main()
{
  
   int n;
   cin>>n;
  
 int a[n][3];
   for(int i=0;i<n;i++)
   {
      for(int j=0;j<3;j++)
      {
      	cin>>a[i][j];
      }
   }
   
   // bool k1=true;
   // bool k2=true;
   // bool k3=true;
   // cout<<solve(n-1,k1,k2,k3)<<endl;
   int dp[n][3]={0};
   for(int i=0;i<n;i++)
   {
   	for(int j=0;j<3;j++)
   	{
   		if(i==0)
   		{
   			dp[i][j]=a[0][j];
   		}
   	}
   }
 
   	for(int i=1;i<n;i++)
   {
   	for(int j=0;j<3;j++)
   	{
   		 if(j==0)
   			dp[i][j] =a[i][j]+max(dp[i-1][j+1],dp[i-1][j+2]);
   		else if(j==1)
   			dp[i][j]=a[i][j]+max(dp[i-1][j+1],dp[i-1][j-1]);
   		else
   			dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j-2]);
   	}
   }
  
   
   int ans=-1;
   for(int i=0;i<3;i++)
   {
   	ans=max(ans,dp[n-1][i]);
   }
   cout<< ans<<endl;

}

   



   


Measured memory_bytes: 2560
s=input()
n=len(s)
a0="01"*(n//2) + "0"*(n%2)
a1="10"*(n//2) + "1"*(n%2)
ans0=sum(s[i]!=a0[i] for i in range(n))
ans1=sum(s[i]!=a1[i] for i in range(n))
print(min(ans0,ans1))

Measured memory_bytes: 41840
#include "./bits/stdc++.h"

#include <vector>
#include <iostream>

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

using namespace std;

typedef long long ll;

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
    std::priority_queue<
      int,
      std::vector<int>,
      decltype(compare) // 比較関数オブジェクトを指定
    > que(comp);
*/
template <typename T> void debug(T arr);
template <typename T> void debug (T arr, int dim);



int main(void){
    ll x,y,z;
    cin >> x >> y >> z;
    x = x-z;
    cout << x/(y+z) << endl;
};


template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
};

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    ll n, m, cnt=0;
    cin >> n >> m;
    vector<ll> h(n), a(m), b(m);
    map<ll, ll> mp;
    rep(i, n){
        cin >> h[i];
        mp[i]=0;
    }
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    rep(i, m){
        chmax(mp[a[i]], h[b[i]]);
        chmax(mp[b[i]], h[a[i]]);
    }
    rep(i, n){
        if(h[i]>mp[i]){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 11968
#include<stdio.h>
int main(){
    int i,a[10000];
    for(i=1;;i+=1){
        scanf("%d",&a[i]);
        if(a[i]==0){
            break;
        }
    }
    for(i=1;;i+=1){
        if(a[i]==0){
            break;
        }
        printf("Case %d: %d\n",i,a[i]);
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=100010, inf=2e9;
int n, k;
ll ans=0;
int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>k;
	for(int b=k+1; b<=n; b++){
		ll x=n/b, r=n%b;
		ans+=x*(b-k) + max(0LL, r-k+1) - (k==0);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000002
#define MAX2 10000

int main(){
  unsigned int *A, *B;

  int arr[MAX2+1];
  int n, i, j;
  
  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);

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

  for ( i = 1; i <= MAX2; i++ ){
    arr[i] = arr[i] + arr[i - 1];
  }
  
  for ( j = 1; j <= n; j++ ){
    B[arr[A[j]]] = A[j];
    arr[A[j]]--;
  }

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

  return 0;
}

Measured memory_bytes: 16276
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main()
{
	ll num;
	int ans = 0;
	cin >> num;
	for (ll i = 2; i*i <= num; i++) {
        int count=0;
        int last_count=0;
		while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
            count++;
            if(count>last_count){
                ans++;
                last_count=count;
                count=0;
            }
			num /= i;
		}
        if(i>=3)i++;
	}

    if(num!=1)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;


int main(){
    int z;
    while(cin>>z,z){
        ll z3=z*z*z;
        ll ans=0;
        rep(i,z){
            rep(j,z){
                ll xy3=i*i*i+j*j*j;
                if(z3>=xy3) ans=max(ans,xy3);
            }
        }
        cout<<z3-ans<<endl;
    }
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll m,k;
    cin >> m >> k;
    if(m == 0){
        if(k == 0) cout << "0 0" << endl;
        else cout << -1 << endl;
        return 0;
    }else if(m == 1){
        if(k == 0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(k >= (1ll << m)){
        cout << -1 << endl;
        return 0;
    }
    for(i = 0;i < (1ll << m);++i){
        if(i != k) cout << i << endl;
    }
    cout << k << endl;
    for(i = (1ll << m) -1;i >= 0;--i){
        if(i != k) cout << i << endl;
    }
    cout << k << endl;

    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    
    LL n,a,b;
    while(cin>>n>>a>>b)
    {
        LL cnt=n/(a+b);
        LL ans=cnt*a;
        cnt=n%(a+b);
        ans+=cnt>a?a:cnt;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i = 0; i < m; i++){
        cin >> a[i];
        n -= a[i];
    }
    if(n >= 0) cout << n;
    else cout << -1;
    return 0;
}

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

int main()
{
    int n,p[30];
    int i;
    int ans=0;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
        scanf("%d",p+i);
    }
    for(i=0;i<n;i++)
    {
        if(i!=0&&i!=n-1)
        {
            //printf("%d %d %d\n",p[i-1],p[i],p[i+1]);
            if(((p[i-1]>p[i])&&(p[i]>p[i+1]))||((p[i-1]<p[i])&&(p[i]<p[i+1])))
            {
                ans++;
                //printf("%d\n",i);
            }
        }
    }

    printf("%d",ans);
}



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

int main(){
  int n,k,count=0;
  cin >> n >> k;
  vector<int> d(k),check(n+10,0);
  
  rep(i,k){
    cin >> d.at(i);
    vector<vector<int>> a(k, vector<int>(d.at(i)));
    rep(j,d.at(i)){
      cin >> a.at(i).at(j);
      check.at(a.at(i).at(j))++;
    }
  }

  for(int i=1; i<=n; i++){
    if(check.at(i) == 0){
      count++;
    }
  }
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>

using namespace std;
//debug

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

#define pb push_back

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;



#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()



int main() {
	ll n,m,d;
	cin >> n >> m >> d;
	printf("%.8f", double(m - 1) / n / n*(n*ll(d == 0) + 2*(n - d)*ll(d != 0)));


}



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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int h;cin >> h;
  int ans=0,a=0;
  while(h>0){
    ans+=pow(2,a++);
    h/=2;
  }
  //ans+=pow(2,a);
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <stack>
#include <ctime>
#include <bitset>
#include <map>
#include <queue>
#include <fstream>
using namespace std;


const int MAX_N = 92;
const int MAX_M = 92;
//typedef pair<int, pair<vector<bitset<MAX_M> >, pair<int, int> > >  P;



int rec(vector<bitset<MAX_M> > table, pair<int, int> p);

int main()
{
	//ifstream ifs("data.txt");

	int x, y;

	while( cin >> x >> y && x)
	{
		vector<bitset<MAX_M> > table(x + 2);
		for(int i = 0; i < x; i++){
			for(int j = 0; j < y; j++){
				int buf;
				cin >> buf;
				if(buf)
					table[i+1][j+1] = true;
			}
		}

		int res = 1;
		//clock_t start = clock();		
		
		
		for(int i = 1; i < x + 1; i++)
			for(int j = 1; j < y + 1; j++)
				if(table[i][j])
					res = max(res, rec(table, make_pair(i, j)));
		

		//cout << clock() - start << " " << res << endl;
		cout << res << endl;
		
	}
	//cin.sync(); cin.get();
}

int rec(vector<bitset<MAX_M> > table, pair<int, int> p)
{
	table[p.first][p.second] = false;

	int res = 1, dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};

	for(int i = 0; i < 4; i++)
		if(table[p.first + dx[i]][p.second + dy[i]])
			res = max(res, 1 + rec(table, make_pair(p.first + dx[i], p.second + dy[i])));
	
	return res;
}

Measured memory_bytes: 936
/**
 *   Author: Praveen Ojha
 *   Created: 27 January 2019
 *   Time: 00:59:53
**/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n],dp[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    memset(dp,0,sizeof dp);
    for(int i=n-2;i>=0;i--){
    	int mini=INT_MAX;
    	for(int j=1;j<=k;j++){
    		if(i+j<n){
    		mini=min(mini,abs(a[i]-a[i+j])+dp[i+j]);
    		}
    	}
    	dp[i]=mini;
    }
    cout<<dp[0]<<"\n";
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)
// コンパイル　g++ -std=c++17 a.cpp

int main() {
    ll n;
    cin >> n;
    vector<string> vec(n);
    rep(i,n){
        cin >> vec.at(i);
    }

    map<string, ll> mp;
    rep(i,n){
        mp[vec.at(i)]++;
    }

    ll max_num = 0;
    for(auto i: mp){
        if(max_num < i.second){
            max_num = i.second;
        }
    }


    for(auto i: mp){
        if(i.second == max_num){
            cout << i.first << endl;
        }
    }

}

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

int main(int argc, char const *argv[])
{
    int A,B,C;
    int ans=0;
    cin>>A>>B>>C;
    if(A+B>=C){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    /* code */
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  string s;
  cin >> s;
  int p = 0;
  int m = 0;
  rep(i,4) {
    if(s[i] == '+')p++;
    else m++;
  }
  int ans = p-m;
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main() {
    string s; cin >> s;
    bool fg = true;
    if(s.size()%2==1)fg = false;
    rep(i, s.size()){
        if(i%2==0 and s[i]!= 'h') fg = false;
        if(i%2==1 and s[i]!= 'i') fg = false;
    }
    if(fg) cout << "Yes" << ln;
    else cout << "No" << ln;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m = sc.nextInt();
        List<List<Integer>> a = new ArrayList<>();
        for(int i=0;i<100000;i++){
            a.add(new ArrayList<Integer>(){});
        }
        for(int i=0;i<n;i++){
            int p = sc.nextInt();
            int q = sc.nextInt();
            a.get(p-1).add(q);
        }
        int sal = 0;
        PriorityQueue<Integer> sub = new PriorityQueue<>(new MyComparator());
        for(int i=0;i<m;i++){
            sub.addAll(a.get(i));
            if(sub.isEmpty())continue;
            sal += sub.poll();
        }
        System.out.println(sal);
        return;
    }

    static class MyComparator implements Comparator<Integer> {
        @Override
        public int compare (Integer arg0, Integer arg1) {
            int x = (int) arg0;
            int y = (int) arg1;
            return y-x;
        }
    }
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int N; cin >>N;
    vector<int> L(N); cin >> L;

    sort(all(L));

    int ans = 0;
    int a, b;
    for (int ai = 0; ai < N - 2; ai++) {
        a = L[ai];
        for (int bi = ai + 1; bi < N - 1; bi++) {
            b = L[bi];
            auto it = lower_bound(L.begin() + bi + 1, L.end(), a + b);
            ans += distance(L.begin() + bi + 1, it);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
  int n, inf=1000000007,b;
  long long a,ans=0,tmp,oc[61]={},zc[61]={};
  std::cin>>n;
  for(int i=0;i<n;++i){
    std::cin>>a;
    b=0;
    while(true){(a>>b&1?++oc[b]:++zc[b]);if(a>>b==0)break;++b;}
  }
  for(int i=0;i<61;++i){
    tmp = (oc[i]*(n-oc[i]))%inf;
    for(int j=0;j<i;++j)tmp=tmp*2%inf;
    ans+=tmp%inf;
  }
  std::cout<<ans%inf<<"\n";
}

Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+:---test
3
2 5
---+/
/+:---test
2
3
---+/
/+---test
6
0 153 10 10 23
---+/

void main(string[] args) {
  readln;
  const B = readln.split.map!(to!long).array;

  if (B.length == 1) {
    (B[0]*2).writeln;
    return;
  }

  long ans = B[0] + B[$-1];
  foreach (i; 1..B.length) {
    ans += min(B[i-1], B[i]);
  }
  ans.writeln;
}


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

int main(){
  int a, p=0, q=9, flag=0;
  rep(i,5,0){
    cin >> a;
    if(a % 10 == 0) p += a;
    else{
      if(q > a % 10) q = a % 10;
      int x = a / 10;
      p += (x+1) * 10;
      flag = 1;
    }
  }
  long long int ans;
  if(flag == 0) ans = p;
  else ans = p - 10 + q;
  cout << ans << endl;
}

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

void query(char now) {
    //cerr << S << " " << now << endl;
    if(now == ('a' - 1)) {
        st.insert(S);
        return;
    }
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == now + 1) {
            return;
        }
        if(S[i] == now) {
            S[i]++;
            query(now - 1);
            S[i]--;
        }
    }
    query(now - 1);
}

int main() {
    while(true) {
        cin >> S;
        st.clear();
        if(S == "#") break;
        query('y');
        cout << st.size() << endl;
        if(st.size() <= 10) {
            for(auto itr = st.begin(); itr != st.end(); itr++) {
                cout << *itr << endl;
            }
        } else {
            auto itr = st.begin();
            for(int i = 1; i <= 5; i++) {
                cout << *itr << endl;
                itr++;
            }
            itr = st.end();
            for(int i = 1; i <= 5; i++) itr--;
            for(int i = 1; i <= 5; i++) {
                cout << *itr << endl;
                itr++;
            }
        }
    }
    return 0;
}


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

int main() {
	int X, out;
	cin >> X;
	for (int i = 1; ; i++) {
		if (i * (i - 1) / 2 < X && X <= i * (i + 1) / 2) {
			out = i;
			break;
		}
	}
	cout << out << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 1001001;
const int INF = 1001001001;
int n;
int a[MAX_N];
int dp[MAX_N];

int main() {
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }

    fill(dp, dp+n, INF);
    rep(i,n){
        *lower_bound(dp, dp+n, a[i]) = a[i];
    }

    cout << lower_bound(dp, dp+n, INF) - dp << endl;
    return 0;
}
 
 



Measured memory_bytes: 3908
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int k =sc.nextInt();
        String s=sc.next();
        if(k<s.length()){
            System.out.println(s.substring(0,k)+"...");
        }else{
            System.out.println(s);
        }

    }
}





Measured memory_bytes: 38380
N = int(input())

S = {}

A = [""]*N
for i in range(0, N):
    A[i] = A[i] + input()

for i in range(0, N):
    if not (A[i] in S.keys()):
        S[A[i]] = 1
    else:
        S[A[i]] = S[A[i]] + 1

max = 0
for value in S.values():
    if value > max:
        max = value

S0 = {}
n = 0
for key, value in S.items():
    if value == max:
        S0[key] = 0
        n += 1

T = [""]*n
i = 0
for key in S0.keys():
    T[i] = key
    i += 1

T.sort()
for p in range(0, n):
    print(T[p])


Measured memory_bytes: 53476
#include "bits/stdc++.h"

using namespace std;

int main(){
	
	int a,b,c;
	cin >> a >>b >> c;
	
	if(a+b < c){
		cout << "NA" << endl;
	}
	else{
		cout << max(0,c-a) << endl;
	}
	return 0;
}


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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int left = 0;
  int top = h;
  int right = w;
  int bottom = 0;
  rep(i,n){
    int x, y, a;
    cin >> x >> y >> a;
    if(a==1){
      left = max(left, x);
    }
    else if (a==2){
      right = min(right, x);
    }
    else if (a==3){
      bottom = max(bottom, y);
    }
    else{
      top = min(top, y);
    }
  }
  if(left < right && bottom < top) cout << (right-left)*(top-bottom) << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]

max_fee = 0
for i in range(1, n + 2):
    max_fee += abs(a[i] - a[i - 1])

for i in range(1, n + 1):
    if a[i - 1] <= a[i] <= a[i + 1] or a[i + 1] <= a[i] <= a[i - 1]:
        print(max_fee)
    else:
        res = max_fee - min(abs(a[i + 1] - a[i]) * 2, abs(a[i] - a[i - 1]) * 2)
        print(res)


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

int A[1048576],n;
void collide(int x,int y){
	if(A[x]!=A[y])
		if(A[x]>A[y])
			A[x]-=A[y];
		else
			A[x]=A[y]-A[x];
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<(1<<n);i++)
		scanf("%d",&A[i]);
	for(int i=1;i<=n;i++)
		for(int j=0;j<(1<<(n-i));j++)
			collide(j<<i,((j<<1)|1)<<(i-1));
	printf("%d\n",A[0]);
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h> 

int main(void)
{	
	int r, c, i, j;
	int hyo[101][101] = {0};

	scanf("%d %d", &r, &c);

	for(i=0; i<r; i++)
	{
		for(j=0; j<c; j++)
		{
			scanf("%d",&hyo[i][j]);
		}
	}

	for(i=0; i<r; i++)
	{
		for(j=0; j<c; j++)
		{
			hyo[i][c] = hyo[i][c] + hyo[i][j];
		}
	}

	for(i=0; i<c+1; i++)
	{
		for(j=0; j<r; j++)
		{
			hyo[r][i] = hyo[r][i] + hyo[j][i];
		}
	}

	for(i=0; i<r+1; i++)
	{
		for(j=0; j<c; j++)
		{
			printf("%d ",hyo[i][j]);
		}
		printf("%d\n",hyo[i][c]);
	}


	return 0;
}

Measured memory_bytes: 648
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
n,m,k=map(int,input().split())
w=998244353
t=0
c=1
b=m*((m-1)**(n-1))%w
g=power_func(m-1,w-2,w)
for i in range(k+1):
    t += c * b
    t %= w
    if i<k:
        c*=(n-1-i)
        c*=power_func(i+1,w-2,w)
        c%=w
        b*=g
        b%=w
if m==1 and k==n-1:
    print(1)
else:
    print(t)

Measured memory_bytes: 10636
#include <iostream>
#include <utility>
#include <algorithm>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> p;

ll n;
p arr[100005];

int main()
{
    ll t, a;
    t = a = 0;
    
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> arr[i].se.fi >> arr[i].se.se;

        arr[i].first = arr[i].se.fi + arr[i].se.se;
    }

    sort(arr, arr + n, greater<p>());
    for (ll i = 0; i < n; i++) {
        if (i & 1) {
            a += arr[i].se.se;
        } else {
            t += arr[i].se.fi;
        }
    }

    cout << t - a << endl;    
    
    return 0;
}


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

void dfs(int node, int father, vector<vector<int>>& ad, vector<int>& dist) {
    dist[node] = dist[father] + 1;
    for (int nghb : ad[node])
        if (nghb != father)
            dfs(nghb, node, ad, dist);
}

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

    int n, a, b;
    cin >> n >> a >> b;

    vector<vector<int>> ad(n + 1);
    for (int i = 1; i < n; i++) {
        int x, y; cin >> x >> y;
        ad[x].push_back(y);
        ad[y].push_back(x);
    }

    vector<int> distA(n + 1);
    dfs(a, 0, ad, distA);

    vector<int> distB(n + 1);
    dfs(b, 0, ad, distB);

    int best = 0;
    for (int i = 1; i <= n; i++)
        if (distA[i] <= distB[i])
            best = max(best, distB[i]);

    cout << best - 2 << '\n';
    return 0;
}


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

signed main(void){
    int n; cin >> n;
    int tmp;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0) tmp = i;
    }
    cout << tmp + n/tmp - 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

void call(int n){
    for(int i = 1; i <= n; i++){
        int x = i;

        if(x % 3 == 0){
            cout << " " << i;
        }else{
            while(x > 0){
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;

}
    

int main(){
    int n;
    cin >> n;
    call(n);
}


Measured memory_bytes: 3088
n,m = map(int,input().split())
ans = []
for _ in range(m):
    l,r = map(int,input().split())
    if ans:
        ans = [max(ans[0],l),min(ans[1],r)]
    else:
        ans = [l,r]
print(ans[1]-ans[0]+1 if ans[1]-ans[0]+1>0 else 0)

Measured memory_bytes: 3060
from sys import stdin
from collections import defaultdict
def main():
    n, k = map(int, stdin.readline().split())
    a = map(int, stdin.readline().split())
    mn = 1001001001
    p = 0
    d = defaultdict(int)
    for x in a:
        if mn > x:
            mn = x
        if p < x - mn:
            p = x - mn
        d[x] += 1
    ans = 0
    for x in reversed(a):
        if x not in d:
            continue
        if x - p in d:
            ans += min(d[x], d[x-p])
            d.pop(x-p)
        d[x] -= 1
    print ans
main()


Measured memory_bytes: 16540
function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

function Main(input) {
  var pick = Picker(input);
  var l = [pick.int(), pick.int(), pick.int(), pick.int(), pick.int()].sort(function(a, b){ return a - b;});
  var k = pick.int();
  
  var min = l[0];
  var max = l[l.length - 1];

	console.log(max - min <= k ? 'Yay!' : ':(');
}

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

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

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

const long long M = 1000000007;

int main(){
	long long n, t;
	cin >> n >> t;
	vector<long long> d(n);
	cin >> d;

	sort(all(d));
	long long ans = 1, j = 0;
	rep(i,n){
		while(d[i] - d[j] > t) j++;
		(ans *= i - j + 1) %= M;
	}
	cout << ans << endl;
}



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

int main() {
    int A, B, C;
    cin>>A>>B>>C;
    int M = max(A, max(B, C));
    vector<int> d;
    d.push_back(M-A);
    d.push_back(M-B);
    d.push_back(M-C);

    int ans = 0;
    sort(d.begin(), d.end());
    while (d[0] != d[1] || d[1] != d[2] || d[2] != d[1]) {
        sort(d.begin(), d.end());
        if (d[2]-d[0] > 1) d[2] = d[2]-2;
        else d[1] = d[1]-1, d[2] = d[2]-1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for(int i = 1; i <= N; i++){
        double this_ans = 1.0 / N;
        int tmp_i = i;
        while(tmp_i < K){
            tmp_i *= 2;
            this_ans /= 2;
        }
        ans += this_ans;
    }
    fcout << ans << endl;
}

Measured memory_bytes: 256
import itertools

n=int(input())

num=[0]*5
for i in range(n):
    s=input()
    if s[0]=='M':
        num[0]+=1
    elif s[0]=='A':
        num[1]+=1
    elif s[0]=='R':
        num[2]+=1
    elif s[0]=='C':
        num[3]+=1
    elif s[0]=='H':
        num[4]+=1

ans=0
for comb in itertools.combinations(num,3):
    ans+=comb[0]*comb[1]*comb[2]
print(ans)


Measured memory_bytes: 3064
n = int(input())
l = list(map(int, input().split()))

l_dic = {}
for i in l:
  if i in l_dic:
    l_dic[i] += 1
  else:
    l_dic[i] = 1
cnt_dic = {}
for i, j in l_dic.items():
  cnt_dic[i] = j*(j-1)//2
ans = 0
for i, j in cnt_dic.items():
  ans += j

for i in l:
  print(ans - cnt_dic[i] + (l_dic[i]-1)*(l_dic[i]-2)//2)


Measured memory_bytes: 31828
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   int a,b;
   cin>>a>>b;
   if(a*b%2==0)cout<<"Even"<<endl;
   else cout<<"Odd"<<endl;
}

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n,i,j,k;
  cin>>n>>k;
  long long int arr[n];
  long long int ans[n];
  for(i=0;i<n;i++){
    cin>>arr[i];
    ans[i] = INT_MAX;
  }
  ans[0] = 0;
  ans[1] = abs(arr[0]-arr[1]);
  for(i=2;i<n;i++){
    for(j=i-1;j>=0 && j>=i-k;j--){
      ans[i] = min(ans[i],ans[j] + abs(arr[j]-arr[i]));
    }
  }
  cout<<ans[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
#define N 100000
using namespace std;
struct node
{
	int to,next,v;
}e[310000];
int q[310000],in[310000],head,tail,g[310000],size,dis[310000],k,i;
void add(int o,int p,int q)
{
	e[++size].to=p;
	e[size].next=g[o];
	g[o]=size;
	e[size].v=q;
}
void bfs()
{
	q[++tail]=1;
	in[1]=1;
	while (head!=tail)
	{
		int x=q[++head];
		if (head==N) head=0;
		in[x]=0;
		for (int k=g[x];k;k=e[k].next)
		{
			int y=e[k].to;
			if (dis[y]>dis[x]+e[k].v)
			{
				dis[y]=dis[x]+e[k].v;
				if (!in[y])
				{
					q[++tail]=y;
					if (tail==N) tail=0;
					in[y]=1;
				}
			}
		}
	}
}
int main()
{
	///freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d",&k);
	memset(dis,0x7f,sizeof(dis));
	dis[1]=0;
	for (i=0;i<=k;i++)
	{
		add(i,(i+1)%k,1);
		if (i>0)add(i,i*10%k,0);
	} 
	bfs();
	printf("%d\n",1+dis[0]);
	return 0;
}

Measured memory_bytes: 7936
import copy

n = int(input())
x = list(map(int, input().split()))
x_sort = copy.deepcopy(x)
x_sort.sort()

x_max = x_sort[n - 1]
center = x_sort[0]
for i in range(1, n - 1):
    if abs(center - x_max / 2) > abs(x_sort[i] - x_max / 2):
        center = x_sort[i]

print(x_max, center)


Measured memory_bytes: 14732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

int N;
const int MAX_N = 2.0e5 + 100;
ll A[MAX_N];
const int MOD = 1.0e9 + 7;

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

    int A_sum[N+1];
    memset(A_sum, 0, sizeof(A_sum));
    A_sum[N] = 0;
    for (int i = N-1; i >= 0; i--) {
        A_sum[i] = (A_sum[i+1] + A[i]) % MOD;
    }

    ll sum = 0;
    for (int i = 0; i < N-1; i++) {
        sum = (sum + (A[i] * A_sum[i+1]) % MOD ) % MOD;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 5976