akhauriyash/Code-Regression huggingface dataset:
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b-1], s[b]]:
    for T in [t[d-1], t[d]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(res, d1, d2)
  print(res)

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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	int N,X,H(0),i;
	scin(N)
	scin(X)
	long int L[N];
	rep(i,0,N) scin(L[i])
	for(i = 0 ; H <= X ; i ++){
		H += L[i];
	}
	if(i < N + 1) anin(i) else anin(N + 1)
	return 0;
}

Measured memory_bytes: 128
a,b,x=map(int,input().split())
import math
if x<=a*a*b/2:
    c=2*x/a/b
    r=math.atan(b/c)
    print(math.degrees(r))
else:
    c=2*x/a/a-b
    r=math.atan((b-c)/a)
    print(math.degrees(r))

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

int main() {
  vector<string> day(4);
  day = { "Christmas Eve Eve Eve","Christmas Eve Eve","Christmas Eve","Christmas"};
  int d;
  cin >> d;
  for(int i=0;i<4;i++){
    if( d == i+22){
      cout << day.at(i) << endl;
      return 0;
    }
  }
  return 0; 
}


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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {	
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	int ans = a[2]-a[1];
	a[0] += ans;
	a[1] = a[2];
	if ((a[2]-a[0])%2!=0) {
		a[1] = a[2] = a[2] + 1;
		++ans;
	}
	ans += (a[2]-a[0])/2;
	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include<unordered_map>
#include<unordered_set>

using namespace std;
#define IO                 \
	ios::sync_with_stdio(0); \
cin.tie(0);              \
cout.tie(0);
#define forn(i, n) for (int i = 0; i < n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define mp make_pair
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define getcurrtime() \
	cerr << "Time = " << ((double)clock() / CLOCKS_PER_SEC) << endl

#define watch(x) cerr << (#x) << " is " << (x) << endl;

#ifndef LOCAL
#define cerr if(false)cerr
#endif
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll P=1e9+7;
double PI=3.141592653589793;
const int arrn = 2e5 + 1;


vector<int> adj[arrn];
int hei[arrn];
void solve(){
	int n,m;
	cin >> n >> m;
	forn(i,n) cin >> hei[i];
	forn(i,m){
		int u,v;
		cin >> u >> v;
		u--;v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int ans=0;
	forn(i,n){
		bool chk=1;
		for(auto j:adj[i]){
			if(hei[j]>=hei[i]) chk=0;
		}
		ans+=chk;
	}
	cout << ans;
}

int main() {
	IO;
	int T=1;
//	cin >> T;
	forn(c,T){
		solve();
	}
}



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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

// 2 1 | 2 1 | 2 1 -> 3 + 2 + 1
// 1 2 | 1 2 | 1 2 -> 2 + 1


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;

	vl a(n);
	FOR(i,0,n) cin >> a[i];

	ll res = 0;
	FOR(i,0,n) FOR(j,0,n) if (a[i] > a[j]) {
		ll cnt = k*(k+1)/2;
		if (i > j) cnt -= k;
		res = (res + cnt) % MOD;
	}
	cout << res << endl;

}



Measured memory_bytes: 256
// Never let them see you bleed...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

ll a[maxn], ans[maxn];

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

    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= q; i++){
	cin >> a[i];
    }
    a[0] = n;
    
    map<ll, ll> mp;
    mp[a[q]] = 1;
    
    for(int i = q-1; i >= 0; i--){
	while((mp.rbegin()->F) > a[i]){
	    pll p = *mp.rbegin();
	    mp.erase(p.F);
	    mp[a[i]]+= (p.F / a[i]) * p.S;
	    mp[p.F % a[i]]+= p.S;
	}
    }
    for(pll p : mp){
	ans[p.F]+= p.S;
    }
    for(int i = n-1; i >= 1; i--){
	ans[i]+= ans[i+1];
    }
    for(int i = 1; i <= n; i++){
	cout << ans[i] << "\n";
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  int ans=0;
  for(int i=0;i<=28;i++){
    vector<vector<int>> c(2,vector<int>());
    for(int j=0;j<n;j++) c[(b[j]&(1<<i))/(1<<i)].push_back(b[j]&((1<<i)-1));
    sort(all(c[0]));
    sort(all(c[1]));
    LL one=0;
    int dist;
    for(int j=0;j<n;j++){
      dist=distance(c[0].begin(),lower_bound(all(c[0]),(1<<i)-(a[j]&((1<<i)-1))));
      if(a[j]&(1<<i)) one+=dist;
      else one+=c[0].size()-dist;
      dist=distance(c[1].begin(),lower_bound(all(c[1]),(1<<i)-(a[j]&((1<<i)-1))));
      if(a[j]&(1<<i)) one+=c[1].size()-dist;
      else one+=dist;
    }
    ans+=(one%2)*(1<<i);
  }
  cout << ans << endl;
  return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  int n; cin >> n;
  vector<string> a, b, ab, o;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s[0] == 'B' && s.back() == 'A') ab.push_back(s);
    else if (s[0] == 'B') b.push_back(s);
    else if (s.back() == 'A') a.push_back(s);
    else o.push_back(s);
  }
  string t;
  if (a.size()) {
    t += a.back();
    a.pop_back();
  }
  for (auto &i : ab) t += i;
  if (b.size()) {
    t += b.back();
    b.pop_back();
  }
  int m = min(a.size(), b.size());
  for (int i = 0; i < m; i++) {
    t += a.back() + b.back();
    a.pop_back();
    b.pop_back();
  }
  for (auto &i : a) t += i;
  for (auto &i : b) t += i;
  for (auto &i : o) t += i;
  int ans = 0;
  for (int i = 0; i < (int)(t.size()) - 1; i++) {
    if (t.substr(i, 2) == "AB") ans++;
  }
  cout << ans << '\n';
}

signed main() {
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 4000
def solve(D):
    ans = []
    tmp = 0
    for d in D:
        if d[0] == d[1]:
            tmp += 1
        else:
            ans.append(tmp)
            tmp = 0
    ans.append(tmp)

    return 'Yes' if max(ans) >= 3 else 'No'


if __name__ == "__main__":
    N = int(input())
    D = [list(map(int, input().split())) for _ in range(N)]
    print(solve(D))


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int n,m,fa[200010],sz[200010],ans;
inline int Find(int x){
	if(x==fa[x])
		return x;
	fa[x]=Find(fa[x]);
	return fa[x];
}
inline void Merge(int x,int y){
	int fx=Find(x),fy=Find(y);
	if(fx==fy)
		return;
	fa[fx]=fy;
	sz[fy]+=sz[fx];
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		fa[i]=i;
		sz[i]=1;
	}
	while(m--){
		int x,y;
		cin>>x>>y;
		Merge(x,y);
	}
	for(int i=1;i<=n;i++)
		ans=max(ans,sz[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5116
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1, n - 1):
    if (p[i - 1] < p[i]) and (p[i] < p[i + 1]):
        cnt+=1
    elif (p[i - 1] > p[i]) and (p[i] > p[i + 1]):
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,k;
int oblicz(int a,int b){return n - (a - b);}
int main(){
    int w1,pop;
    cin >> n >> k;
    vector <int> vec;
    for(int i = 0;i < k;i++){
        int a; cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end());
    w1 = oblicz(vec[1],vec[0]);
    pop = vec[1];
    for(int i = 2;i < k;i++){
        w1 = min(w1,oblicz(vec[i],pop));
        pop = vec[i];
    }
    cout << min(w1,vec[k-1] - vec[0]);
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<queue>
typedef long long ll;
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> jobs(M);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        if (a > M) continue;
        jobs[M-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for (int i = M-1; i >= 0; --i) {
        for (int b : jobs[i]) {
            q.push(b);
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

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

int chk(string a, string b){
    int ans = 0;
    for(char c = 'a'; c <= 'z'; c++){
        bool founda = false, foundb = false;
        for(int i = 0; i < a.length(); i++){
            if(a[i] == c){
                founda = true;
            }
        }
        for(int j = 0; j < b.length(); j++){
            if(b[j] == c){
                foundb = true;
            }
        }
        if(founda && foundb) ans++;
    }
    return ans;
}

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

    int ans = 0;
    for(int i = 0; i <= n; i++){
        int num = chk(s.substr(0, i), s.substr(i));
        ans = max(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;

/*int nCr(int n,int r)
{
    if(r==1)
    {
        return n;
    }
    if(r==n)
    {
        return 1;
    }
    if(r==0)
    {
        return 1;
    }

    if(r>n)
    {
        return -1;
    }

    if(dp[n][r]!=0)
    {
        return dp[n][r];
    }
    dp[n][r]=nCr(n-1,r-1)+nCr(n-1,r);
    return dp[n][r];
}*/

int main()
{
    long long int dp[100005],h[100005];
    cin>>a;
    //h[0]=0;
    for(int i=1; i<=a; i++)
    {
        cin>>h[i];
    }
    //dp[0]=0;
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3; i<=a; i++)
    {
         dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[a]<<endl;
}


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

int main() {
	int x, a, b;cin >> x >> a >> b;
	if (b <= a) {
		cout << "delicious" << endl;
	} else if (b <= a + x) {
		cout << "safe" << endl;
	} else {
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

n=int(input().rstrip())
a=[int(i) for i in input().split()]

mod=10**9+7

csum=[0]
for i in a:
    csum.append((csum[-1]+i)%mod)

ans=0
c=n-1
for i in range(n-1):
    ans+=a[i]*(csum[-1]-csum[i+1])
    ans%=mod

print(ans)

Measured memory_bytes: 31388
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r=0,b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R')r++;
        else b++;
    }
    if(r>b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  while(1){
    int N,M;
    cin>>N>>M;
    if(!(N|M))return;
    vector<int> dp(256,1<<29);
    dp[128]=0;
    vector<int> C(M);
    rep(i,M) cin >> C[i];
    
    rep(i,N){
      int x;
      cin>>x;
      vector<int> newdp(256,1<<29);
      rep(j,256){
        if(dp[j]==(1<<29))continue;
        for(int k=0;k<M;k++){
          int a=min(255,j+C[k]);chmax(a,0);
          chmin(newdp[a],dp[j]+(a-x)*(a-x));
        }
      }
      dp=newdp;
    }
    int res=1<<29;
    rep(i,256)
      chmin(res,dp[i]);
    cout<<res<<endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 3124
N = int(input())
A = list(map(int, input().split()))
S = sum(map(abs, A))
 
cnt = 0
 
for a in A:
    if a > 0:
        cnt += 1
        
if (len(A)-cnt)%2==0 or 0 in A:
    print(S)
else:
    print(S-2*min(map(abs, A)))

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

int main() {
  char a,b; cin >> a >> b;
  if ( a == 'H' && b == 'H') cout << 'H' << endl;
  else if ( a == 'D' && b == 'H') cout << 'D' << endl;
  else if ( a == 'H' && b == 'D') cout << 'D' << endl;
  else if ( a == 'D' && b == 'D') cout <<  'H' << endl;
  
  return 0;
}


Measured memory_bytes: 256
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int T = (A + D - 1) / D;
    int AO = (C + B - 1) / B;

    if (T >= AO) {
        cout << "Yes";
        return;
    }
    cout << "No";
}

#pragma region main
main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3664
def frog():
    n = int(input())
    h_list = list(map(int, input().split()))

    dp = [0] * 10 ** 5

    for n_element in range(n):
        if n_element >= 2:
            dp[n_element] = min(dp[n_element - 1] + abs(h_list[n_element] - h_list[n_element - 1]),
                                dp[n_element - 2] + abs(h_list[n_element] - h_list[n_element - 2]))
        elif n_element == 1:
            dp[n_element] = abs(h_list[n_element] - h_list[n_element - 1])
        else:
            dp[n_element] = 0

    print(dp[n - 1])


if __name__ == "__main__":
    frog()


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : (x))
#define all(x) x.begin(), x.end() // sort(all(x))
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair((x), (y))

typedef long long ll;

typedef double T;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<T> vt;
typedef vector<vt> vvt;
typedef vector<pii> vpi;
typedef vector<pii> vpl;
typedef vector<vpi> graph;
typedef complex<T> Pt;
typedef pair<Pt, Pt> Line;

const ll MOD = 1e9 + 7; // 998244353;
const T EPS = 1e-10;
const int INF = 1e9 + 1;

/* Mod Library */

struct Mod {
    ll x;
    Mod (ll x = 0) : x(x) {}
    Mod operator+(Mod b) { return Mod((x + b.x)%MOD); }
    Mod operator-(Mod b) { return Mod((x - b.x + MOD)%MOD); }
    Mod operator*(Mod b) { return Mod((x * b.x)%MOD); }
    Mod operator/(Mod b) { return *this * inverse(b); }
    Mod operator%(Mod b) { return Mod(x % b.x); }

    static ll euclid(ll a, ll b, ll &x, ll &y) {
        if (b) {
            ll d = euclid(b, a%b, y, x);
            y -= a/b*x;
            return d;
        }
        x = 1; 
        y = 0;
        return a;
    }
    
    Mod inverse(Mod a) {
        ll x, y, g = euclid(a.x, MOD, x, y);
        assert(g == 1);
        return Mod((x + MOD)%MOD);
    }

    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this^(e/2);
        r = r*r;
        return e&1 ? *this*r : r;
    }
};

/* Input Library */
template <typename A, typename B>
istream& operator>>(istream &in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template <typename A, typename B>
ostream& operator<<(ostream &out, pair<A, B> &p) {
    out << p.first << " " << p.second;
    return out;
}

template <typename I>
istream& operator>>(istream &in, vector<I> &a) {
    trav(i, a) in >> i;
    return in;
}

template <typename I>
ostream& operator<<(ostream &out, vector<I> &a) {
    rep(i, 0, sz(a)) {
        if (i) out << " ";
        out << a[i];
    }
    return out;
}

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);
    cin.exceptions(cin.failbit);
} 

void solve_test() {
  string s;
  cin >> s;
  cout << s.substr(0, 3) << endl;
}

void setup() {
}

int main() {
    setup();
    srand(time(0));
    fast_io();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve_test();
    }
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
int main(){
    map<long long, long long> m;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        long long a;
        cin >> a;
        m[a]++;
    }
    long long ans = 0;
    for(auto v: m){
        if(v.second < v.first) ans += v.second;
        else ans += v.second - v.first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9372
import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
	public static void main(String[] args) throws ParseException{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      	int m = sc.nextInt();
      	int key[] = new int[m];
      	int key_b[] = new int[m];
      	int stack;
      	int count = 0;
      	int k;
      	
      
      	for(int i = 0; i < m;i++) {
          key[i] = 0;
          key_b[i] = 0;
        }
      
      
     
      	for(int i = 0; i < n;i++){
          	k = sc.nextInt();
      		for(int j = 0; j < k;j++){
          		key_b[sc.nextInt()-1]++;           		             	
          	}
        }
      
      	for(int i = 0; i < m;i++){
        	if(key_b[i] == n) count++;
        }
      	
      
      	System.out.println(count);
      	
        
	}
}

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

int main() {
    int n, a, b, x;
    scanf("%d %d %d", &n, &a, &b);
    if (a > b)
        printf("0");
    else
        if (a == b)
            printf("1");
        else
            if (n < 2)
                printf("0");
            else
                if (n == 2)
                    printf("1");
                else {
                    n = n - 2;
                    x = b - a;
                printf("%lld", 1LL * (n - 1) * x + x + 1); }

    return 0; }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static int num1;
    public static int num2;
    public static int[][] array;
    public static int flag;

    public static void main(String[] args){

        Scanner scn = new Scanner(System.in);

        while(true){

            num1 = scn.nextInt();
            num2 = scn.nextInt();

            if(num1 == 0 && num2 == 0) break;

            array = new int[num2][num1];


            for(int i = 0; i < num2; i++){
                for(int j = 0; j < num1; j++){
                    array[i][j] = scn.nextInt();
                }
            }
            int ans = 0;
            for(int i = 0; i < num2; i++){
                for(int j = 0; j < num1; j++){
                    flag = 1;
                    ans += solve(i,j);
                }
            }
            System.out.println(ans);

        }
    }
    public static int solve(int m, int n){

        if( m >= num2 || n >= num1 || m < 0 || n < 0) return 0;

        if( array[m][n] == 1 ){
            array[m][n] = 0;
            if(flag == 1){
                flag = 0;
                int tmp = solve(m + 1, n) + solve(m, n+ 1)  + solve(m + 1, n + 1) + solve(m + 1, n - 1)  + solve(m -1, n - 1)
                        +  solve(m - 1, n + 1) + solve(m - 1, n) + solve(m, n - 1);
                return 1;
            }
            else {
                return solve(m + 1, n) + solve(m, n + 1) + solve(m + 1, n + 1) + solve(m + 1, n - 1) + solve(m -1, n - 1)
                        +  solve(m - 1, n + 1) + solve(m - 1, n) + solve(m, n - 1);
            }
        }
        else return 0;
    }


}


Measured memory_bytes: 48140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,res,co;
    int a[10004];
    cin>>n;
        co=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        while(a[i]%2==0)
        {
            a[i]=a[i]/2;
            co++;
        }
    }
    cout<<co<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int s[1000],f[1000],c[1000];//c,s,f
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		scanf("%d%d%d",&c[i],&s[i],&f[i]);
	}
	for(i=1;i<n;i++)
	{
		x=0;
		for(j=i;j<n;j++)
		{
			x=max(s[j],int((x+f[j]-1)/f[j])*f[j])+c[j];
		}
		printf("%d\n",x);
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 256
def calc(x, p)
    min = 102
    ret = 102
    (0..101).each do |num|
        unless p.include?(num) then
            distance = (x - num).abs
            if min > distance then
                ret = num
                min = distance
            end
        end
    end

    return ret
end

X, N = gets.split.map(&:to_i)
if N == 0 then
    p = []
else
    p = gets.split.map(&:to_i)
end

puts calc(X, p)


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

using namespace std;

int main(){
  char C,a,s,d,f,g,h,j,k,l,q,w,e,r,t,y,u,i,o,p,z,x,c,v,b,n,m;
  cin>>C;

if(C=='a'){
  cout<<'b';
}
if(C=='b'){
  cout<<'c';
}
if(C=='c'){
  cout<<'d';
}
if(C=='e'){
  cout<<'f';
}
if(C=='d'){
  cout<<'e';
}
if(C=='f'){
  cout<<'g';
}
if(C=='g'){
  cout<<'h';
}
if(C=='h'){
  cout<<'i';
}
if(C=='i'){
  cout<<'j';
}
if(C=='j'){
  cout<<'k';
}
if(C=='k'){
  cout<<'l';
}
if(C=='l'){
  cout<<'m';
}
if(C=='m'){
  cout<<'n';
}
if(C=='n'){
  cout<<'o';
}
if(C=='o'){
  cout<<'p';
}
if(C=='p'){
  cout<<'q';
}
if(C=='q'){
  cout<<'r';
}
if(C=='r'){
  cout<<'s';
}
if(C=='s'){
  cout<<'t';
}
if(C=='t'){
  cout<<'u';
}if(C=='u'){
  cout<<'v';
}
if(C=='v'){
  cout<<'w';
}
if(C=='w'){
  cout<<'x';
}
if(C=='x'){
  cout<<'y';
}
if(C=='y'){
  cout<<'z';
}


 return 0;
}


Measured memory_bytes: 256
//C343, this program implements BFS approach for shortest path problem (unweighted graph)

import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;
import java.util.*;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1; //-1, index
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1; //-1, index
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public int[] computeDistDFS(int vertex) {
		LinkedList<Integer> lList = new LinkedList<Integer>();
		lList.add(vertex);
		int[] yoYouBeenThere = new int[totalVertex];
		int[] distance = new int[totalVertex];
		
		for(int i = 0; i < totalVertex; i ++) {
			yoYouBeenThere[i] = 0; 
			distance[i] = -1; 
		}
		distance[vertex] = 0;
		yoYouBeenThere[vertex] = 1;
		int j;
		while(!lList.isEmpty()) {
			j = lList.remove(0); 
			Iterator<Integer> it = adjList.get(j).iterator();
			int k;
			while(it.hasNext()) {
				k = it.next();
				if(yoYouBeenThere[k] == 0) {
					lList.add(k); 
					distance[k] = distance[j] + 1;
					yoYouBeenThere[k] = 1;
				}
			}
		}
		return distance;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjList();
		int[] dist = g.computeDistDFS(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println((i+1) + " " + dist[i]);
		}
	}
}



Measured memory_bytes: 28412
# -*- coding: utf-8 -*-

S = str(input())

l = len(S)
answer = "Yes"
for i in range(l):
    if i%2 == 0 and S[i] == "L":
        answer = "No"
    elif i%2 == 1 and S[i] == "R":
        answer = "No"
    
print(answer)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

int n;
vi adj[2005];

vi runBFS(int v) {
    qii q;
    vi dst(n);
    bool vis[n];
    memset(vis, false, sizeof vis);
    q.push({v, 0});
    while (q.size() > 0) {
        ii ns = q.front();
        q.pop();
        int vt = ns.first;
        if (vis[vt]) {
            continue;
        }
        int ds = ns.second;
        dst[vt] = ds;
        vis[vt] = true;
        for (int a : adj[vt]) {
            if (vis[a]) {
                continue;
            }
            q.push({a, ds + 1});
        }
    }
    return dst;
}

void solve() {
    int n;
    cin >> n;
    set<string> si;
    int ct = 0;
    while (n--) {
        string s;
        cin >> s;
        if (si.count(s)) {
            continue;
        }
        si.insert(s);
        ct++;
    }
    cout << ct << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    //querySolve();
    solve();
}


Measured memory_bytes: 19296
import java.util.Scanner;

//ABC117A
//Main

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		double T = sc.nextInt();
		double X = sc.nextInt();


		System.out.println(T/X);

	}

}

Measured memory_bytes: 25300
KNlist = list(map(int, input().split()))
Alist = list(map(int, input().split()))
K = KNlist[0]
N = KNlist[1]
northMiddleS = K - (Alist[-1]-Alist[0])
distances = []
for i in range(N-1):
    difference = Alist[i+1]-Alist[i]
    distances.append(difference)
distances.append(northMiddleS)
maxDistanceS = max(distances)
shortest = K-maxDistanceS
print(shortest)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n,b,sum=0;
  cin>>n;
  int a[n];
  rep(i,n) {
    cin>>a[i];
    a[i]-=i;
  }
  sort(a,a+n);
  b=a[n/2];
  rep(i,n) sum+=abs(a[i]-b);
  cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    while(1){
        int n;
        cin>>n;if(n==0)return 0;
        int sw[31];
        for(int i=0;i<=n;++i)sw[i]=0;
        sw[0]=1;
        for(int i=0;i<n;++i){
            if(i<n)sw[i+1]+=sw[i];
            if(i<n-1)sw[i+2]+=sw[i];
            if(i<n-2)sw[i+3]+=sw[i];
        }
        cout<<(sw[n]/3650)+1<<endl;
    }
}

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

string memo[51][51];

string max(string const& a, string const& b) {
    if(a == "invalid") {
        return b;
    }
    if(a.size() > b.size()) {
        return a;
    } else if(a.size() < b.size()) {
        return b;
    } else {
        return (a < b ? b : a);
    }
}

string number(int l, int r, string const& s) {
    if(l < r && s[l] == '0') {
        return "invalid";
    }
    string res;
    for(int i=l; i<=r; ++i) {
        if(s[i] != '?' && !isdigit(s[i])) {
            return "invalid";
        }
        res += s[i] == '?' ? '9' : s[i];
    }
    return res;
}

string solve(int l, int r, string const& s) {
    string& res = memo[l][r];
    if(res != "") {
        return res;
    }
    res = number(l, r, s);
    if(res != "invalid") {
        return res;
    }
    if(s[l+1] != '(' && s[l+1] != '?') {
        return "invalid";
    }
    if(s[r] != ')' && s[r] != '?') {
        return "invalid";
    }
    for(int i=l+3; i<=r-2; ++i) {
        if(s[i] != ',' && s[i] != '?') {
            continue;
        }
        string l_max = solve(l+2, i-1, s),
               r_max = solve(i+1, r-1, s);
        if(l_max == "invalid" || r_max == "invalid") {
            continue;
        }
        if(s[l] == 'L' || s[l] == '?') {
            res = max(res, l_max);
        }
        if(s[l] == 'R' || s[l] == '?') {
            res = max(res, r_max);
        }
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    cout << solve(0, s.size()-1, s) << endl;
}


Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,a,b;
    cin>>n>>a>>b;
    long long ans=0;
    long long int x=n/(a+b);
    ans+=x*(a);

   long long  int y=n%(a+b);
    if(y<=a){
        ans+=y;
    }
    else{
        ans+=a;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2584&lang=jp
string Chiper(int& x, string& S);
char Letter(int& x, string& S);

string Chiper(int& x, string& S) {
	string ret = "";
	for (; x < S.length();x++) {
		if (S[x] == ']')return ret;
		if (S[x] == '[') {
			x++;
			string temp = Chiper(x, S);
			reverse(temp.begin(), temp.end());
			ret += temp;
		}
		else {
			ret += Letter(x, S);
		}
	}
	return ret;
}

char Letter(int& x, string& S) {
	int cnt = 0;
	char ret = '\n';
	for (;x < S.length();x++) {
		if (S[x] == '+') { cnt++; continue; }
		if (S[x] == '-') { cnt--; continue; }
		if (S[x] == '?') { return 'A'; }
		ret = (S[x] - 'A' + cnt + 26 * 5) % 26 + 'A';
		return ret;
	}
	return ret;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	string S;
	while (cin >> S) {
		if (S == ".")break;
		int x = 0;
		cout << Chiper(x, S) << endl;
	}
}

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

int main(){
  int n;cin>>n;
  string s;cin>>s;
  int max_x=0,x=0;
  for(int i=0;i<n;i++){
    if(s[i]=='I')x++;
    if(s[i]=='D')x--;
    max_x=max(max_x,x);
  }
  cout<<max_x<<endl;
  return 0;
}


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

#define int long long

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

using namespace std;

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

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
	COMinit();
	int n;
	int k;
	cin>>n>>k;
	int a[110000];
	rep(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	vector<int> b;
	b.push_back(1);
	vector<int> c;
	c.push_back(a[0]);
	rep(i,1,n){
		if(a[i]!=a[i-1]){
			b.push_back(1);
			c.push_back(a[i]);
		}
		else {
			b[b.size()-1]++;
			
		}
	}
	int m=b.size();
	int ans=0;
	int bs=0;
	rep(i,m){
		bs+=b[i];
		int cn=0;
		rep(j,min(b[i],k)){
			cn+=COM(b[i],j+1)*COM(bs-b[i],k-1-j)%MOD;
			cn%=MOD;
		}
		ans+=c[i]*cn%MOD;
		ans%=MOD;
	}
	cerr<<ans<<endl;
	bs=0;
	for(int i=m-1;i>=0;i--){
		bs+=b[i];
		int cn=0;
		rep(j,min(k,b[i])){
			cn+=COM(b[i],j+1)*COM(bs-b[i],k-1-j)%MOD;
			cn%=MOD;
		}
		//cout<<cn<<endl;
		ans-=c[i]*cn%MOD;
		ans%=MOD;
	}
	
	
	while(ans<0)ans+=MOD;
	cout<<ans<<endl;
}


Measured memory_bytes: 14708
#pragma GCC optimize("Ofast")
#include<stdio.h>
int x;
char c;
inline int read()
{
	x=0; c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return x;
}
int main()
{
	long n = read() + 1, ans = n - 1;
	for (int i = 2; i < n; ++i)
	{
        int u = read(), v = read();
		if (u > v) ans += i * (n - i) - v * (n - u);
        else ans += i * (n - i) - u * (n - v);
	}
	printf("%ld", ans);
  
    return 0;
}


Measured memory_bytes: 1604
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int Q = sc.nextInt();
    int[] T = new int[Q];
    int[] F = new int[Q];
    char[] C = new char[Q];
    for (int i = 0; i < Q; i++) {
      T[i] = sc.nextInt();
      if (T[i] == 2) {
        F[i] = sc.nextInt();
        C[i] = sc.next().charAt(0);
      }
    }
    sc.close();

    StringBuilder pre = new StringBuilder();
    StringBuilder suf = new StringBuilder();
    boolean rev = false;
    for (int i = 0; i < Q; i++) {
      if (T[i] == 1) {
        rev = !rev;
      } else {
        if (rev ^ F[i] == 1) {
          pre.insert(0, C[i]);
        } else {
          suf.append(C[i]);
        }
      }
    }

    StringBuilder ans = new StringBuilder()
        .append(pre)
        .append(S)
        .append(suf);
    if (rev) ans.reverse();
    System.out.println(ans);
  }
}

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

int main()
{
  vector<int> a,b;
  int a_sum,b_sum;
  int n;
  for(int i=0;i<10;i++){
    cin >> n;
    a.push_back(n);
  }
  for(int i=0;i<10;i++){
    cin >> n;
    b.push_back(n);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  a_sum=a[7]+a[8]+a[9];
  b_sum=b[7]+b[8]+b[9];
  cout << a_sum << " " << b_sum << endl;
  return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x = i;
		if(x % 3 == 0){
			cout << " " << i;
			continue;
		}
		
		while(x){
			if(x % 10 == 3){
				cout << " " << i;
				break;
			}
			x /= 10;
		}
		
	}
	cout << endl;
}





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

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

    int n,Max = 0;
    cin >> n;
    int a[n][2];
    for(int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1];

    for(int i = 0; i < n; i++){
        int cnt = 0;
        while(a[i][0] == a[i][1] && i < n){
        cnt++;
        i++;
        }
        if(cnt > Max) Max = cnt;
    }

    cout << (Max > 2 ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3608
n, m, c = map(int, input().split()) 
B = list(map(int, input().split())) 

num = 0
for i in range(0,n):
	A = list(map(int, input().split()))
	sum = 0 
	for j in range(0, m):
		sum += A[j]*B[j]
	
	sum += c	
	if(sum>0):
		num += 1
	
print(num)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int N, A, B; cin >> N >> A >> B;
    string s; cin >> s;
    vector<bool> ans(N, false);
    int cnt = 0;
    int bcnt = 0;

    for (int i = 0; i < N; i++)
    {
        if(cnt>=A+B) break;

        if(s[i]=='a') {
            cnt++;
            ans[i] = true;
        } else if(s[i]=='b'&& bcnt<B){
            cnt++; bcnt++;
            ans[i] = true;
        }
    }
    

    for(bool is_pass : ans){
        if(is_pass) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }    
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=998244353;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n,k;
    cin>>n>>k;
    vector<pair<ll,ll>> a(k);
    for(ll i=0;i<k;i++)
        cin>>a[i].first>>a[i].second;
    vector<ll> dp(n+1,0),pref(n+1,0);
    dp[1]=1;
    pref[1]=1;
    for(int i=2;i<=n;i++){
        for(ll j=0;j<k;j++){
            ll v=a[j].first, u=a[j].second;
            //cout<<u<<" "<<v<<" ";
            if(i-v<1) continue;
            dp[i]=(dp[i]+pref[i-v])%mod;
            if(i-u>=1) dp[i]=(dp[i]-pref[i-u-1]+mod)%mod;
        }
        //cout<<dp[i]<<"\n";
        pref[i]=(pref[i-1]+dp[i])%mod;
    }
    cout<<dp[n];


    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 6420
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	if(a*b*c==5*5*7){
		cout<<"YES\n";
	}
	else cout<<"NO\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
//cout << fixed << setprecision(12);
string s;
cin>>s;
reverse(all(s));
ll ca=0;
ll a[2030]={};
ll n=s.size();
ll ten=1;
rep(i,n){
ca +=((s.at(i)-'0')*ten);
ca %=2019;
//cout << ca << endl;  
a[ca]++;
ten*=10;
ten%=2019;}
ca=0;
ten=1;
a[0]++;
repl(i,0,2019){
ca+=a[i]*(a[i]-1)/2;}
cout << ca << endl;}


Measured memory_bytes: 3784
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

int keta_sum(int n) {
    if (n < 10) {
        return n;
    }
    return n % 10 + keta_sum(n / 10);
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        int v = keta_sum(i);
        if (a <= v && v <= b) {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import std.bigint;
import core.bitop;


void main() {
  auto s = readln.split.map!(to!int);
  auto N = s[0];
  auto M = s[1];
  auto C = readln.split.map!(to!int).array.sort();
  auto dp = new long[](N+1);
  foreach (i; 0..N+1) dp[i] = 10^^9+7;
  foreach (c; C) if(c <= N) dp[c] = 1;

  foreach (i; 1..N+1)
    foreach (c; C)
      if (i - c >= 0 && dp[i-c] > 0)
        dp[i] = min(dp[i-c]+1, dp[i]);

  dp[N].writeln;
}

Measured memory_bytes: 2648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main() {
  int n;
  cin >> n;
  ll ans = 1;
  rep (i, n) {
    ans = (ans * i) % mod;
  }
  P(ans);
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
sa=sum(a)
a.sort()
b=sa/(4*m)
flag=0
for i in range(m):
    if a[n-i-1]<b:
        flag=1
        break

if flag==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
A = int(input())#500
B = int(input())#100
C = int(input())#50
X = int(input())
count = 0
for i in range(C + 1):
    for j in range(B + 1):
        for k in range(A + 1):
            if i + j + k != 0:
                if X == (50*i + 100*j + 500*k):
                    count += 1
print(count)


Measured memory_bytes: 9156
main :: IO ()
main = do
  (n:x:_) <- fmap (map read . words) getLine :: IO [Int]
  xs <- fmap (map read . words) getLine :: IO [Int]
  print $ solve x xs

solve :: Int -> [Int] -> Int
solve x xs = foldr1 gcd abss
  where
    abss = map (\y -> abs (y - x)) xs


Measured memory_bytes: 36220