akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool is_bipartite_graph(int n, vector<vector<int>>& g, vector<int>& t){
    bool flg = false;
    t.assign(n, -1);
    queue<int> q; q.push(0); t[0] = 0;
    while(not q.empty()) {
        auto p = q.front(); q.pop();
        for (auto & elm : g[p]) {
            if(t[elm] == -1) t[elm] = not t[p];
            else {
                if(t[elm] == t[p]) {
                    flg = true; break;
                }
                continue;
            }
            q.push(elm);
        }
        if(flg) break;
    }

    return (not flg);
}

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

    vector<vector<int>> g(n, vector<int>(0));
    for (auto i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].push_back(b); g[b].push_back(a);
    }

    // 2部グラフかの判定はBFS/DFSで色を塗っていって、合わない箇所があるかで判定する
    vector<int> a;
    if(is_bipartite_graph(n, g, a)) {
        int64_t a_cnt = 0, b_cnt = 0;
        for (auto & elm : a) {
            if(elm == 0) a_cnt++;
            else b_cnt++;
        }
        // 2部グラフの場合には、異なる集合の頂点間に辺を作れる
        cout << a_cnt * b_cnt - m << endl;
    }
    // 2部グラフでない場合には、任意の頂点間に辺を作れる
    else cout << n * (n - 1) / 2 - m << endl;

    return 0;
}

Measured memory_bytes: 9148
#include <iostream>
#include<bits/stdc++.h>
#define ref(i,n) for(int i=1;i<=n;i++)
using namespace std;

int a[200002],b[200002];
int main()
{
    int n;
    cin>>n;
    ref(i,2*n-1) {
        cin>>a[i];
        b[a[i]]=i;
    }
    int low,high,r;

    if(a[n]>a[n+1]) {
        high=a[n];
        low=a[n+1];
        r=1;
        }
    else {
        r=-1;
        high=a[n+1];
        low=a[n];
    }
    ref(i,n-1){
        int x=pow(-1,i%2)*r,ju=0;
        if((a[n+i]-a[n+i-1])*x>0){
            if((x==1&&a[n+i]>low))
                high=min(high,a[n+i]);
            else if((x==-1&&a[n+i]<high))
                low=max(low,a[n+i]);

            else {
                if(x==-1) {
                    cout<<high;
                    return 0;
                }
                else {
                    cout<<low;
                    return 0;
                }
            }
        }
        else if(x==-1) {
                    cout<<high;
                    return 0;
                }
                else {
                    cout<<low;
                    return 0;
                }
        if((a[n-i]-a[n-i+1])*x>0){
            if((x==1&&a[n-i]>low))
                high=min(high,a[n-i]);
            else if((x==-1&&a[n-i]<high))
                low=max(low,a[n-i]);
            else {
                if(x==-1) {
                    cout<<high;
                    return 0;
                }
                else {
                    cout<<low;
                    return 0;
                }
            }
        }
        else if(x==-1) {
                    cout<<high;
                    return 0;
                }
                else {
                    cout<<low;
                    return 0;
                }

    }

    if(b[low]%2) cout<<low;
    else cout<<high;
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end(), greater<int>());

    int sum = accumulate(a.begin(), a.end(), 0);

    if (a.at(m-1) >= sum*(1.0/(4*m))) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h,n;
    while(scanf("%lld %lld",&h,&n)==2){
        long long ah[h],c=0;
        for(long long i=0;i<h;i++){
            scanf("%lld",&ah[i]);
        }
        sort(ah,ah+h);

            for(long long i=h-1;n>0;i--){
                ah[i]=0;
               n--;
            }

            for(long long i=0;i<h;i++){
                while(ah[i]>0){
                    c++;
                    ah[i]--;
                }
            }
            printf("%lld\n",c);
    }
}


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

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

typedef long long ll;
typedef pair<int,int> po;
int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
int H, W;
vector<string> board;
ll bfs(int i, int j) {
    vector<string> visited(board.size());
    copy(board.begin(),board.end(),visited.begin());
    queue<po> que;
    queue<int> dist;    
    visited[i][j] = '#';
    REP(k, 4){
        po next = po(i+dx[k],j+dy[k]);
        if (next.first>=0&&next.first<H&&next.second>=0&& next.second <W && visited[next.first][next.second] == '.') {
            visited[next.first][next.second] = '#';
            que.push(next);
            dist.push(1);
        }
    }
    ll d;
    while(!que.empty()){
        po cur = que.front(); que.pop();
        d = dist.front(); dist.pop();
        REP(k, 4){
            po cur_n = po(cur.first+dx[k],cur.second+dy[k]);
            if (cur_n.first>=0&&cur_n.first<H&&cur_n.second>=0&& cur_n.second <W && visited[cur_n.first][cur_n.second] == '.') {
                visited[cur_n.first][cur_n.second] = '#';
                que.push(cur_n);
                dist.push(d+1);
            }
        }
    }
    return d;
}
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cin >> H >> W;
    REP(i, H){
        string s; cin >> s;
        board.push_back(s);
    }
    ll res = 0;
    REP(i, H) {
        REP(j, W) {
            if (board[i][j]=='.')
            res = max(res, bfs(i,j));
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
     
    using namespace std;
    typedef long long ll;
    #define min(a, b) ((a) < (b)? (a):(b))
    #define abs(a) ((a) < (0)? -(a):(a))
    #define rep(i, n) REP(i, 0, (n))
    #define REP(i, a, n) for(typeof(n) i=(a); i<(n); i++)
     
    int N;
    int a[100010];
     
    int main() {
    	cin >> N;
    	int mini = 0, maxi = 0;
    	ll total = 0;
    	REP(i, 1, N+1) {
    	    cin >> a[i];
    	    mini = a[i] < a[mini]? i:mini;
    	    maxi = a[i] > a[maxi]? i:maxi;
    	    total += abs(a[i-1]-a[i]);
    	}
        total += abs(a[N]);
        REP(i, 1, N+1) {
            cout << total - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1])) << endl;
        }
    }

Measured memory_bytes: 1664
N,A,B,C = gets.split.map(&:to_i)
L = Array.new(N)
N.times {|i|  L[i] = gets.to_i}
INF = 10 ** 9

def dfs(cur, a,b,c)
  if cur == N
    return [a,b,c].min > 0  ? (a-A).abs + (b-B).abs + (c-C).abs - 30 : INF
  end
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + L[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + L[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10
  [ret0, ret1, ret2, ret3].min
end

puts dfs(0,0,0,0)

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

using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];

//vは現在の頂点 
int dfs(int v, int n, bool visited[nmax]){
    
    bool all_visited = true;
    
    for (int i = 0; i < n; i++){
        if (visited[i] == false) all_visited = false;
    }
    
    
    if(all_visited) return 1;
    
    int ret = 0;
    
    for (int i = 0; i < n; i++){
        if (graph[v][i] == false) continue; //道がない
        if (visited[i]) continue; //すでに一度以上訪問した頂点であった
        
        visited[i] = true;
        ret += dfs(i, n, visited);
        visited[i] = false;
    }
    
    return ret;
}
int main(void){
    int n, m;
    cin >> n >> m;
    
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        
        //隣接リストを作る
        graph[a-1][b-1] = true;
        graph[b-1][a-1] = true;
    }
    
    bool visited[nmax];
    
    for (int i = 0; i < n; i++){
        visited[i] = false; //すべての頂点を未訪問にする
    }
    
    visited[0] = true; //頂点１よりスタートする
    cout << dfs(0, n, visited) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int i, j, score[6] = {0}, max;
    for(i = 0;i < 5;i++){
        scanf("%d",&score[i]);
        if(score[i] < 40){
            score[i] = 40;
        }
    }
    for(i = 0;i < 5;i++){
        score[5] += score[i];
    }
    printf("%d\n",score[5] / 5);


    return 0;
}

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

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

using namespace std;
using ll = long long;
using ushort = unsigned short;
using uint = unsigned int;
using ulong = unsigned long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

bool is_palindrome(string s);

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

  int n, n1, n2;
  n = s.length();
  n1 = (n - 1) / 2;
  n2 = (n + 3) / 2;

  if (is_palindrome(s))
    if (is_palindrome(s.substr(0, n1)))
      if (is_palindrome(s.substr(n2 - 1))) {
        cout << "Yes" << endl;
        return 0;
      }

  cout << "No" << endl;

  return 0;
}

bool is_palindrome(string s) {
  for (int l=0; l < s.length(); l++) {
    if (s[l] != s[s.length() - 1 - l]) {
      return false;
    }
  }

  return true;
}


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

#define MAX 10000

void initialize();
int isEmpty();
int isFull();
void  push(int x);
int pop();

int top;
int S[10000];

int main()
{
  int i,n,ans,n1,n2,n3;
  char c[10000];

  initialize();

  while(1){
    if(scanf("%s",c)==EOF) break;

    if(c[0]=='+' || c[0]=='-' ||c[0]=='*'){
      n1 = pop();
      n2 = pop();
      if(c[0]=='+') n3 = n1 + n2;
      if(c[0]=='-') n3 = n2 - n1;
      if(c[0]=='*') n3 = n1 * n2;
      push(n3);
    }
      else{
	n = atoi(c);
	push(n);
      }
    }

    printf("%d\n",pop());
    return 0;
  }

  void initialize(){
    top = 0;
  }

  int isEmpty(){
    return top == 0;
  }

  int isFull(){
    return top >= MAX - 1;
  }

  void  push(int x){
    if (isFull()) fprintf(stderr,"overflow\n");
    top++;
    S[top] = x;
  }

  int pop(){
    if (isEmpty()) fprintf(stderr,"underflow\n");
    top--;
    return S[top+1];
  }

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

using namespace std;
using ll = long long;
using P = pair<int, uint>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

ll rec(ll n, ll x) {
    if (n == 0) return 1;
    ll len = (1LL << (n+1)) - 3;
    ll num = (1LL << n) - 1;

    if (x == 1) return 0;
    else if (x <= len + 1) return rec(n-1, x-1);
    else if (x == len + 2) return num + 1;
    else if (x <= (len + 1) * 2) return num + 1 + rec(n-1, x-len-2);
    else return num * 2 + 1;
}

void solve(){
    ll N, X; cin >> N >> X;
    cout << rec(N, X) << endl;
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



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

int main(){
    int N, K;
    cin>>N>>K;
    int arr[N];
    for(int i=0; i<N; i++)cin>>arr[i];
    int dp[N];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    if(N>K){
        for(int i=2; i<K; i++){
            dp[i]=INT_MAX;
            int x;
            for(int j=1; j<=i; j++){
                x = dp[i-j]+abs(arr[i-j]-arr[i]);
                if(x<dp[i])dp[i]=x;
            }
        }
        for(int i=K; i<N; i++){
            dp[i]=INT_MAX;
            int x;
            for(int j=1; j<=K; j++){
                x = dp[i-j]+abs(arr[i-j]-arr[i]);
                if(x<dp[i])dp[i]=x;
            }
        }
        cout<<dp[N-1]<<endl;
    }
    else{
        cout<<abs(arr[0]-arr[N-1])<<endl;
    }
    // for(int i=2; i<N; i++){
    //     dp[i]=min(dp[i-2]+abs(arr[i-2]-arr[i]), dp[i-1]+abs(arr[i-1]-arr[i]));
    // }
    
}

Measured memory_bytes: 1024
n = int(input())
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))

tmp = 100000
for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < tmp:
        tmp = abs(a - (t - h[i] * 0.006))
        ans = i + 1

print(ans)

Measured memory_bytes: 3060
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int x = 0, y = 0;
        int ans1= 0, ans2= 0, adv1 = 0, adv2 = 0;
        for(int i = 0; i < n; i++){
            char c = s.charAt(i);
            if(c == '(') adv1++;
            else if(c == ')'){
                if(adv1 <= 0) ans1++;
                adv1 = Math.max(0, adv1-1);
            }
        }
        for(int i = n-1; i >= 0; i--){
            char c = s.charAt(i);
            if(c == ')') adv2++;
            else if(c == '('){
                if(adv2 <= 0) ans2++;
                adv2 = Math.max(0, adv2-1);
            }
        }
        for(int i = 0; i < ans1; i++) System.out.print('(');
        System.out.print(s);
        for(int i = 0; i < ans2; i++) System.out.print(')');
    }
}

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

using namespace std;
 
int T,card[10];
string str;
 
bool check1(int a,int b,int c){
    if(a == b && b == c) return true;
    return false;
}
 
bool check2(int a,int b,int c){
    if(a+2 == b+1 && b+1 == c) return true;
    return false;
}
 
bool check3(int a,int b,int c){
    return check1(a,b,c) || check2(a,b,c);
}
 
bool check4(int card[10]){
    return check3(card[0],card[1],card[2])&&check3(card[3],card[4],card[5])
	&&check3(card[6],card[7],card[8]);
}
 
int judge(){
    sort(card,card+9);
    do{
        if(check4(card)) return 1;
         
    }while(next_permutation(card,card+9));
    return 0;
}
 
int main(){
    cin >> T;
    while(T--){
        for(int i = 0 ; i < 9 ; i++){
            cin >> card[i];
        }
        for(int i = 0 ; i < 9 ; i++){
            cin >> str;
            if(str == "G") card[i] += 10;
            else if(str == "B") card[i] += 20;
        }
        cout << judge() << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3008
while True:
    m, f, r = map(int, raw_input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print "F"
    elif m + f >= 80:
        print "A"
    elif m + f >= 65:
        print "B"
    elif m + f >= 50:
        print "C"
    elif m + f >= 30 and r >= 50:
        print "C"
    elif m + f >= 30:
        print "D"
    else:
        print "F"

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-a)<abs(x-b)) cout << "A" << endl;
  else cout << "B" << endl;
  return 0;

}


Measured memory_bytes: 256
import sys
from collections import deque


def main():
    n, m = map(int, sys.stdin.readline().split())

    to = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = map(int, sys.stdin.readline().split())
        to[a].append(b)
        to[b].append(a)
    INF = float("inf")

    dist = [INF] * (n + 1)
    dist[1] = 0
    pre = [0] * (n + 1)
    que = deque([])
    que.append(1)

    while que:
        p = que.popleft()
        for i in to[p]:
            if dist[i] > dist[p] + 1:
                dist[i] = dist[p] + 1
                pre[i] = p
                que.append(i)

    print("Yes")
    for i in range(2, n + 1):
        print(pre[i])


if __name__ == "__main__":
    main()

Measured memory_bytes: 34940
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if (a < b) {
        printf("a < b\n");
    } else if (a > b) {
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	string S;
	cin >> S;
	auto result = 0;
	auto l = 0; 
	auto r = 0;
	while (l < S.length())
	{
		for (; r < S.length() && S[r] == S[l]; ++r);
		result = max(result, min(r, (int)S.length() - l));
		l = r;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f[100000],g[100000],h,i,j,k,z;
	scanf("%d %d %d",&a,&s,&d);
	for(i=0;i<d;i++)
		scanf("%d %d",&f[i],&g[i]);
	for(i=0;i<d-1;i++){
		z=0;
		h=f[i]-f[i+1];
		k=g[i]-g[i+1];
		if(h<0&&k>0)	z=1;
		if(k<0&&h>0)	z=1;
		if(h<0)	h*=-1;
		if(k<0)	k*=-1;
		if(h==k&&z==0)	j+=h;
		if(h<k&&z==0)	j+=h+(k-h);
		if(h>k&&z==0)	j+=k+(h-k);
		if(z==1)	j+=h+k;
		//printf("%d,%d   %d\n",h,k,j);
	}
	printf("%d\n",j);
	return 0;
}

Measured memory_bytes: 2720
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  // ÅÉ8!ÊèÌÅZè(<=28)ðßéB
  map<vector<int>, int> mp;
  queue<pair<vector<int>, int> > Q;
  vector<int> v(8);
  REP(i,8) v[i] = i;
  Q.push(make_pair(v,1));
  int x = 0;                    // 0 ÌÊu
  while(!Q.empty()) {
    v = Q.front().first;
    int n = Q.front().second;
    if (n >= 38) break;
    Q.pop();
    if (mp[v]) continue;
    else mp[v] = n;
    REP(i,8)
      if (v[i] == 0)
        x = i;
    //cout << n << endl;
    if (x != 0 && x != 4) {
      vector<int> vv = v;
      swap(vv[x], vv[x-1]);
      Q.push(make_pair(vv, n+1));
    }
    if (x <= 3) {
      vector<int> vv = v;
      swap(vv[x], vv[x+4]);
      Q.push(make_pair(vv, n+1));
    }
    if (x >= 4) {
      vector<int> vv = v;
      swap(vv[x], vv[x-4]);
      Q.push(make_pair(vv, n+1));
    }
    if (x != 3 && x != 7) {
      vector<int> vv = v;
      swap(vv[x], vv[x+1]);
      Q.push(make_pair(vv, n+1));
    }
  }
  //cout << "ok" << endl;
  vector<int> a(8);
  while(cin >> a[0]) {
    REP(i,7)
      cin >> a[i+1];
    cout << mp[a]-1 << endl;
  }
  
}

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

int main(){
    int m,h;
    string x,y,z;
    while(1){
        cin>>x;
        if(x=="-")break;
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>h;
            y=x.substr(0,(h));
            z=x.erase(0,(h));
            x=z+y;
        }
        cout<<x<<endl;
    }
}


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

int main(){
    string ss;
    cin >> ss;
    int tm = ss.size();
    set<char> sets;
    for(int i=0;i<tm;i++){
        sets.insert(ss[i]);
    }
    for(char s='a';s<='z';s++){
        if(sets.find(s) == sets.end()){
            cout << s << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	ll n;
	cin >> n;
	string ans;
	while (n) {
		n--;
		ans += n % 26 + 'a';
		n /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j;
	long long int n,k,gain=0;
	scanf("%lli",&n);
	long long int c[6];
	for(i=0;i<6;++i)
	{
		scanf("%lli",&c[i]);
	}
	bool check1=false,check2=false,check3=false;
	if(c[0]<c[3])		check1=1;
	if(c[1]<c[4])		check2=1;
	if(c[2]<c[5])		check3=1;
	if(check1&&check2&&check3)
	{
		for(i=0;i<=n/c[0];++i)
		{
			for(j=0;j<=(n-i*c[0])/c[1];++j)
			{
				k = (n-i*c[0]-j*c[1])/c[2];
				gain = max(gain,i*(c[3]-c[0])+j*(c[4]-c[1])+k*(c[5]-c[2]));
			}
		}
		n+=gain;
	}
	else if(check1&&check2)
	{
		for(i=0;i<=n/c[0];++i)
		{
			gain = max(gain,i*(c[3]-c[0])+(n-i*c[0])/c[1]*(c[4]-c[1]));
		}
		n+=gain;
		n=n+(n/c[5])*(c[2]-c[5]);
	}
	else if(check1&&check3)
	{
		for(i=0;i<=n/c[0];++i)
		{
			gain = max(gain,i*(c[3]-c[0])+(n-i*c[0])/c[2]*(c[5]-c[2]));
		}
		n+=gain;
		n=n+(n/c[4])*(c[1]-c[4]);
	}
	else if(check2&&check3)
	{
		for(i=0;i<=n/c[1];++i)
		{
			gain = max(gain,i*(c[4]-c[1])+(n-i*c[1])/c[2]*(c[5]-c[2]));
		}
		n+=gain;
		n=n+(n/c[3])*(c[0]-c[3]);
	}
	else if(check1)
	{
		n=n+(n/c[0])*(c[3]-c[0]);
		for(i=0;i<=n/c[4];++i)
		{
			gain = max(gain,i*(c[1]-c[4])+(n-i*c[4])/c[5]*(c[2]-c[5]));
		}
		n+=gain;
	}
	else if(check2)
	{
		n=n+(n/c[1])*(c[4]-c[1]);
		for(i=0;i<=n/c[3];++i)
		{
			gain = max(gain,i*(c[0]-c[3])+(n-i*c[3])/c[5]*(c[2]-c[5]));
		}
		n+=gain;
	}
	else if(check3)
	{
		n=n+(n/c[2])*(c[5]-c[2]);
		for(i=0;i<=n/c[3];++i)
		{
			gain = max(gain,i*(c[0]-c[3])+(n-i*c[3])/c[4]*(c[1]-c[4]));
		}
		n+=gain;
	}
	else
	{
		for(i=0;i<=n/c[3];++i)
		{
			for(j=0;j<=(n-i*c[3])/c[4];++j)
			{
				k = (n-i*c[3]-j*c[4])/c[5];
				gain = max(gain,k*(c[2]-c[5])+i*(c[0]-c[3])+j*(c[1]-c[4]));
			}
		}
		n+=gain;
	}
	printf("%lli\n",n);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define df 0
#define MAX 10000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define max(a,b) (((a)>(b))?(a):(b))


int main(){
  int a,b; cin >>a >>b;
  printf("%d",max(a-2*b,0));

}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    double r;
    cin >> r;
    dcout << r * 2 * M_PI;

    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
	std::string s;
	int k;

	std::cin >> s >> k;

	int n = int(s.length());
	std::vector<std::string> dat;

	for (int len = 1; len <= k; len++) {
		for (int i = 0; i + len <= n; i++) {
			dat.push_back(s.substr(i, len));
		}
	}

	std::sort(dat.begin(), dat.end());

	dat.erase(unique(dat.begin(), dat.end()), dat.end());

	std::cout << dat[k - 1] << '\n';

	return 0;
}

Measured memory_bytes: 4336
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int n;
    cin >> n;

    int count = 0;
    for (int i = 1; i <= n; i++) {
        string tmp = to_string(i);
        if (tmp.size() % 2)
            count++;
    }

    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <unordered_map>
#include <assert.h>
using namespace std;

#define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++)
#define rep(i, a) ran ((i), 0, (a))
#define rep1(i, a) ran ((i), 1, (a)+1)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define _0 first
#define _1 second
#define _pb(x) push_back(x)
#define _mp(x, y) make_pair(x, y)
#if defined(SHIROKO1_LOCAL) && !defined(NDEBUG)
#define DEBUG(...) fprintf(stderr, "[DEBUG] " __VA_ARGS__)
#else
#define DEBUG(...) ((void)0)
#endif



int main()
{
	int N;
	static int A[100100];
	static int f[100100];
	static const int ofs = 3;
	cin >> N;
	int i;
	rep (i, N) {
		cin >> A[i];
		A[i] += ofs;
	}
	rep (i, N) {
		f[A[i]-1]++;
		f[A[i]]++;
		f[A[i]+1]++;
	}
	int ans = -1;
	rep (i, 100100)
		ans = max(ans, f[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, n, func, init=float('inf')):
        '''
        n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.init = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        値の初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.init
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret

N = int(input())
S = input()
Q = int(input())
Seg = SegmentTree(N, lambda x, y: x | y, 0)

def a2n(a):
    return ord(a) - ord('a')

def createBit(a):
    return 1 << a2n(a)

for i, s in enumerate(S):
    Seg.set(i, createBit(s))
Seg.build()

for _ in range(Q):
    t, l, r = input().split()
    if int(t) == 1:
        Seg.update(int(l)-1, createBit(r))
    else:
        print(bin(Seg.query(int(l)-1, int(r))).count('1'))

# N = int(input())
# S = input()
# Q = int(input())
# queries = [list(input().split()) for _ in range(Q)]


# def a2n(a):
#     return ord(a)-ord("a")


# def createInp(a):
#     return 1 << a2n(a)


# Seg = SegmentTree(len(S), lambda x, y: x | y, init=0)
# for i, s in enumerate(S):
#     Seg.set(i, createInp(s))
# Seg.build()

# for q, l, r in queries:
#     if q == "1":
#         Seg.update(int(l)-1, createInp(r))
#     else:
#         print(bin(Seg.query(int(l)-1, int(r))).count('1'))

Measured memory_bytes: 43440
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 100003

using namespace std;

int main() {
	int a, b, c, d, ans = 0;
	sfd(a);
	sfd(b);
	sfd(c);
	sfd(d);
	if( a<c ) {
		if( c<b ) {
			if( b>=d ) {
				ans = d-c;
			}else {
				ans = b-c;
			}
		}
	}else{
		if( d>a ) {
			if( b>=d ) {
				ans = d-a;
			}else {
				ans = b-a;
			}
		}
		
	}
	pfd(ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vvll A(N-1,vll(2));
    for(ll i=0;i<N-1;i++){
        cin>>A[i][0];
        A[i][1]=i;
    }
    
    vll c(N);
    for(ll i=0;i<N-1;i++){
        c[A[i][0]-1]++;
    }
    for(ll i=0;i<N;i++){
        printf("%d\n",c[i]);
    }
    
    return 0;
}


Measured memory_bytes: 15952
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_V 5000000
int heap[MAX_V]{0};
int heap_size=0;

int left(int i){return 2*i+1;}
int right(int i){return 2*i+2;}
int parent(int i){return (i-1)/2;}
bool has_left(int i){return heap_size>left(i);}
bool has_right(int i){return heap_size>right(i);}

void max_heapify(int i){
  int l,r,largest;
  l=left(i); r=right(i);
  if(has_left(i)&&heap[l]>heap[i])
    largest=l;
  else
    largest=i;
  if(has_right(i)&&heap[r]>heap[largest])
    largest=r;
  if(largest!=i){
    swap(heap[i],heap[largest]);
    max_heapify(largest);
  }
}
void heap_increase_key(int i,int key){
  if(key<heap[i])
    return;
  heap[i]=key;
  while(i>0&&heap[parent(i)]<heap[i]){
    swap(heap[i],heap[parent(i)]);
    i=parent(i);
  }
}
void max_heap_insert(int key){
  heap[heap_size]=0x80000000;
  heap_size++;
  heap_increase_key(heap_size-1,key);
}
int heap_extract_max(){
  if(heap_size<1)
    return -1;
  int max=heap[0];
  heap[0]=heap[--heap_size];
  max_heapify(0);
  return max;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  for(;;){
    string str; cin>>str;
    if(str=="end")
      break;
    else if(str=="insert"){
      int key; cin>>key;
      max_heap_insert(key);
    }
    else if(str=="extract"){
      int item=heap_extract_max();
      cout<<item<<"\n";
    }
  }
}

Measured memory_bytes: 5308
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int s, w;
	cin >> s >> w;
	if (w >= s)cout << "unsafe";
	else cout << "safe";
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    string s ;
    cin >> s   ;

    cout << s[0]<<s[1] <<s[2]<< endl ;

    return 0 ;
}

Measured memory_bytes: 3624
def check_max_coin(a,b):
  max_coin = 0
  for i in range(1,3):
    if a < b :
      max_coin += b 
      b-=1 
    else:
      max_coin += a  
      a-=1    
  print(max_coin)
  
a, b = map(int, input().split())
check_max_coin(a,b)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int main() {
	int N; cin >> N;
	string s; cin >> s;
	int re = 0, rw = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'W') rw += 1;
		else re += 1;
	}
	int le = 0, lw = 0;
	int mdelta = N;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'E') re -= 1;
		else rw -= 1;
		mdelta = min(mdelta, re + lw);
		if (s[i] == 'E') le += 1;
		else lw += 1;
	}
	cout << mdelta << endl;
}

Measured memory_bytes: 900
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#define Tpair pair <int, int>
using namespace std;

typedef long long ll;
const int   oo = 1e9 + 1;
const int  mod = 1e9 + 7;
const int maxn = 2e5 + 5;

int n, cnt[maxn], f[maxn];
map <int, int> mp;
string s;

void Init()
{
    cin >> s; n = s.length();
    s.insert (0, " ");
    for (int i = 1; i <= n; ++i)
    {
        cnt[i] = cnt[i - 1];
        cnt[i] ^= (1 << (s[i] - 'a'));
    }
}

void Solve()
{
    mp[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        f[i] = i;
        if (mp.count(cnt[i])) f[i] = min (f[i], mp[cnt[i]] + 1);

        for (int j = 0; j < 26; ++j)
        {
            int x = cnt[i] ^ (1 << j);
            if (mp.count(x)) f[i] = min (f[i], mp[x] + 1);
        }
        if (!mp.count(cnt[i])) mp[cnt[i]] = f[i];
        else mp[cnt[i]] = min (mp[cnt[i]], f[i]);

        //cout << f[i] << " " << cnt[i] << endl;
    }
    cout << f[n];
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("D - Yet Another Palindrome Partitioning.inp", "r", stdin);
    //freopen(".out", "w", stdout);

	Init();
	Solve();
}
//Date 29 Month 10 Year 2017




Measured memory_bytes: 11412
#include<stdio.h>
int main(void){
	int N;
	int num,sum;
	int i,j,x,y;
	while(1){
		scanf("%d",&N);
		num=0;
		if(N==0){
			break;
		}
		
		for(i=2;i<=44;i++){
			x=0;
			for(j=1;j<=i;j++){
				x=x+j;
			}
			sum=x-i;
			for(y=0;sum<=N;y++){
				sum=sum+i;
				if(sum==N){
					num++;
					break;
				}
			}
		}
		printf("%d\n",num);
	}
	return 0;
}

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

int main(int argc, char *argv[]) {
  int N, K;
  cin >> N >> K;
  int A[N];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int amari = (N - 1) % (K - 1);
  if(amari == 0) {
    cout << (N - 1) / (K - 1) << endl;
  } else {
    cout << (N - 1) / (K - 1) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	double n, k; CI n >> k;

	double ans = 0;
	double memo = 0;
	double memo2 = 1;
	for (int i = 1; i <= n; i++) {
		double tmp = i;
		int j = 1;
		double kaku = n;

		for (;tmp<k; tmp*=2,j++) {
			kaku *= 2;
		}
		if (i == 1)memo = kaku;
		else memo2 += memo / kaku;
	}

	ans = memo2 / memo;

	CO setprecision(12)<<ans EN;

	return 0;
}

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

int main(){
	int n, p;
	int type[10];

	while(cin >> n, n){
		fill(type, type+10, 0);
		for(int i=0; i < n; i++){
			cin >> p;
			type[p]++;
		}
		for(int i=0; i < 10; i++){
			if(type[i] != 0){
				for(int j=0; j < type[i]; j++) cout << '*';
				cout << endl;
			}
			else cout << '-' << endl;
		}
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

bool check(int n){
  stringstream ss;
  ss << n;
  string a = ss.str();
  reverse(a.begin(), a.end());
  REP(i, a.length()) if(a[i] != ss.str()[i]) return false;
  return true;
}

int main() {
  int N; cin >>N;
  int a = N, b = N;
  while(a >= 0 && !check(a)) --a;
  while(b < 100000 && !check(b)) ++b;
  if(N - a < b - N) cout <<a <<endl;
  else if(b - N < N - a) cout <<b <<endl;
  else cout <<a <<endl;
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int dp[101010];

int rec(int v, Graph &G){
    if(dp[v] != -1) return dp[v];
    vector<int> tmp;
    repe(i, G[v]){
        tmp.push_back(rec(i, G));
    }
    if(tmp.empty()){
        return dp[v]=0;
    }
    sort(all(tmp));
    reverse(all(tmp));
    rep(i, tmp.size()) tmp[i]+=i;
    return dp[v]=*max_element(all(tmp))+1;
}

int main(){
    fastcin();
    int n;
    cin >> n;
    Graph G(n);
    rep1(i, n){
        int a;
        cin >> a;
        a--;
        G[a].push_back(i);
    }

    memset(dp, -1, sizeof(dp));
    cout << rec(0, G) << endl;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  vector<int> s,t;
  for(int i=0;i<a;++i) s.push_back(b);
  for(int i=0;i<b;++i) t.push_back(a);
  
  if(s>t){
  for(int i=0;i<b;++i) cout<<t[i];
  }
  else{
  for(int i=0;i<a;++i) cout<<s[i];
  }

}

Measured memory_bytes: 256
void main() {
	auto S = rs.to!(dchar[]);
	S[3] = '8';
	S.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String[] str = scan.nextLine().split(" ");
			int length = str[0].length();
			int tarlenI = 0;
			int tarcouI = 0;
			for(int i = 1;i < str.length;i++){
				if(length < str[i].length()){
					tarlenI = i;
					length = str[i].length();
				}
			}
			int mcount  = 0;
			for(int i = 0;i < str.length-1;i++){
				int count = 0;
				for(int j = i + 1;j < str.length;j++){
					if(str[i].equals(str[j])){
						count++;
					}
				}
				if(mcount < count){
					mcount = count;
					tarcouI = i;
				}
			}
			System.out.println(str[tarcouI] + " " + str[tarlenI]);
		}
	}
}

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

void solve()
{
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n) cin >> s[i];
    sort(all(s));
    int ans = 0;
    rep(i, n) ans += s[i];
    if (ans % 10 == 0)
    {
        rep(i, n)
        {
            if (s[i] % 10 != 0)
            {
                ans -= s[i];
                cout << ans << endl;
                return;
            }
        }
        cout << 0 << endl;
    }
    else
        cout << ans << endl;
}

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

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		do {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			while (true) {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
				x /= 10;
				if (x != 0)
					continue;
				else
					break;
			}
		} while (++i <= n);
		System.out.println();
	}
}

Measured memory_bytes: 28624
#include <stdio.h>
  int main(){
/*(^(^(^(^(^o^)^)^)^)^) &#9602;&#9605;&#9607;&#9608;&#9619;&#9618;&#9617;('ω')&#9617;&#9618;&#9619;&#9608;&#9607;&#9605;&#9602; */
	  int m;
	  while(scanf("%d",&m)){
		  if(m==0) break;
		  int n[100],b=0,i;
		  while(m>=8){
			  n[b]=m%8;
			  m /= 8;
		      b++;
		  }
		  n[b]=m;
		  for(i=0;i<=b;i++){
			  if(n[i]==4){
				  n[i]=5;
			      continue;
			  }
			  if(n[i]==5){
				  n[i]=7;
			      continue;
			  }if(n[i]==6){
				  n[i]=8;
			      continue;
			  }
			  if(n[i]==7){
				  n[i]=9;
			      continue;
			  }}
		  for(i=b;i>=0;i--){
			  printf("%d",n[i]);
		  }
		  printf("\n");
	  }
		  return 0;
	  }

Measured memory_bytes: 1032
N = int(input())
a = [int(i) for i in input().split()]

rate_map = [0] * 9
for i in a:
    rate_map[8 if i // 400 > 8  else i // 400] += 1
base = len(list(filter(lambda x: bool(x), rate_map[:8])))
# print(rate_map)
print("{} {}".format(min(rate_map[8], 1) if not bool(base) else base, base+rate_map[8]))


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;



int main()
{
 int n;
 scanf("%d",&n);
 printf("%d\n",n*n);
}


Measured memory_bytes: 256
def f(L, i, j):
  h = len(L)
  w = len(L[0])
  if L[i][j] != ".":
    return L[i][j]
  else:
    around = [L[i-1][j-1], L[i-1][j], L[i-1][j+1], L[i][j-1], L[i][j+1], L[i+1][j-1], L[i+1][j], L[i+1][j+1]]
    return str(around.count("#"))

H, W = list(map(lambda x: int(x), input().split(" ")))
A = []
A.append(["X"] * (W + 2))
for i in range(H):
  A.append(["X"])
  A[i + 1].extend(list(input()))
  A[i + 1].extend(["X"])
A.append(["X"] * (W + 2))

for i in range(len(A)):
  for j in range(len(A[0])):
    A[i][j] = f(A, i, j)

print("\n".join(["".join(a[1:-1]) for a in A[1:-1]]))

Measured memory_bytes: 9148
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n,m,x;
	cin>>n>>m>>x;
	vector<int> c(n);
	vector<vector<int>> t(n, vector<int>(m));
	for(int i=0;i<n;++i) {
		cin>>c[i];
		for(int j=0;j<m;++j) {
			cin>>t[i][j];
		}
	}
	int ans=1e9;
	for(int i=0;i<(1<<n);++i) {
		vector<int> van(m);
		int cans=0;
		for(int j=0;j<n;++j) {
			if(i&(1<<j)) {
				cans+=c[j];
				for(int k=0;k<m;++k) {
					van[k]+=t[j][k];
				}
			}
		}
		
		
		
		
		bool ok=*min_element(all(van))>=x;
		//~ LOG(cans);
		//~ LOG(ok);
		if(ok) ans=min(ans, cans); 
	}
	
	cout<<(ans==(int)1e9?-1:ans)<<"\n";
	
	return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;



int main() {
    string S,T;
    cin >> S >> T;
    bool ans = true;

    for ( char c = 'a'; c <= 'z'; c++ ) {
        char t = '0';
        for ( int i = 0; i < S.length(); i++ ) {
            if ( S[i] == c ) {
               if ( t != '0' && t != T[i] ) { ans = false; }
               t = T[i];
            }
        }

        t = '0';
        for ( int i = 0; i < S.length(); i++ ) {
            if ( T[i] == c ) {
               if ( t != '0' && t != S[i] ) { ans = false; }
               t = S[i];
            }
        }

    }      



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

    return 0;
}

Measured memory_bytes: 776
#include <iostream>

using namespace std;

int main () {
  	long a, b, n, x, ans;
    cin >> a >> b >> n;
  	x = b-1;
  	if (n < x) x = n;
  	ans = (a * x) / b;
  	
    cout << ans << endl;
    
	return 0;
}

Measured memory_bytes: 3616
n,k,q=map(int,input().split())
fr=[0]*n
for _ in range(q):
  fr[int(input())-1]+=1
for i in range(n):
  fr[i]=k-q+fr[i]
for i in fr:
  if i<=0:
    print("No")
  else:
    print("Yes")


Measured memory_bytes: 7844
#include <iostream>

using namespace std;
string S, T, U;
int A, B;

void Solve()
{
  if (S == U) --A; else --B;
  cout << A << " " << B << endl;
}

void Init()
{
  cin >> S >> T >> A >> B >> U;
}

void Clean(){}

int main(){ Init(); Solve(); Clean(); return 0; }


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

using namespace std;

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

	int64_t N, K;
	cin >> N >> K;

	if(N > K)
	{
		N %= K;
	}

	int64_t res{N};
	N = K - N;
	res = min(res, N);
	cout << res << "\n";

	return 0;
}


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

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() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = a[n-1];
	rep(i, n - 1) {
		if (a[i] == 1) ans = 1;
		else ans = gcd(ans, a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    import math
    input = stdin.readline

    # import random

    n, m = map(int, input().split())
    """
    a = random.randint(1, 10**6)
    b  = random.randint(1, 10**6)
    n = random.randint(1, 10**12)
    """
    # print(a, b, n)
    
    for i in range(1,m+1):
        if (m-i)%2 == 1:
            print((m+1-i)//2, (m+1-i)//2+i)
        else:
            print(m+(m+2-i)//2, m+(m+2-i)//2+i)



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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main(){
    int N;
    cin >> N;
    int ans = 0;
    int a[N + 1];
    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= N; i++){
            if(a[a[i]] == i){
                ans++;
            }
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 640