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

using namespace std;
#define MAX 3010
string a,b;
int dp[MAX][MAX];
int get(int i = 0 , int j = 0)
{
    if(i == a.size() || j == b.size())  return 0;
    int &ret = dp[i][j];
    if(ret + 1)return ret;

    ret = 0;
    if(a[i] == b[j])return ret = 1 + get(i+1,j+1);
    return ret = max(get(i+1,j),get(i,j+1));
}
void getPath(int i = 0 , int j = 0)
{
    if(i == a.size() || j == b.size()) {cout << '\n';return;}

    int ret = get(i,j);

    if(a[i] == b[j]){cout << a[i] ; getPath(i+1,j+1); return;}
    if(ret == get(i+1,j))getPath(i+1,j);
    else getPath(i,j+1);
}
int main()
{
    cin >> a >> b;
    memset(dp,-1,sizeof dp);

    getPath(0,0);
    return 0;
}


Measured memory_bytes: 36096
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        ArrayList<Apple> apples = new ArrayList<>(a + b + c);

        for (int i = 0; i < a; i++) {
            apples.add(new Apple(sc.nextLong(), Apple.RED));
        }
        for (int i = 0; i < b; i++) {
            apples.add(new Apple(sc.nextLong(), Apple.BLUE));
        }
        for (int i = 0; i < c; i++) {
            apples.add(new Apple(sc.nextLong(), Apple.NONE));
        }

        Collections.sort(apples, (ap1, ap2) -> {
            return Long.compare(ap2.tasty, ap1.tasty);
        });

        int red = 0;
        int blue = 0;
        int none = 0;
        long totalTasty = 0;

        for (int i = 0 ; i < apples.size() ; i++) {
            Apple apple = apples.get(i);
            switch (apple.color) {
                case Apple.RED:
                    if (red < x) {
                        totalTasty += apple.tasty;
                        red++;
                    }
                    break;

                case Apple.BLUE:
                    if (blue < y) {
                        totalTasty += apple.tasty;
                        blue++;
                    }
                    break;

                case Apple.NONE:
                    totalTasty += apple.tasty;
                    none++;
            }
            if (red + blue + none >= x + y) {
                break;
            }
        }

        System.out.println(totalTasty);
    }
}

class Apple {
    static final int RED = 0;
    static final int BLUE = 1;
    static final int NONE = 2;

    public long tasty;
    public int color;

    Apple(long tasty, int color) {
        this.tasty = tasty;
        this.color = color;
    }
}


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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;


int main() {

  int n,k;
  cin>>n>>k;
  Vec vec(n);
  for(int i=0;i<n;i++){
      cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  int ans=0;

  for(int i=0;i<k;i++){
      ans+=vec[i];
  }
  cout<<ans<<endl;
  }


  


Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=105;
int a[N];
int cnt[N];
int main()
{
    int n;
    scanf("%d",&n);
    int M=n,K=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        cnt[a[i]]++;
        M=min(a[i],M);
        K=max(a[i],K);
    }
    if(M!=(K+1)/2||cnt[M]>1+(K&1)){
        puts("Impossible");
        return 0;
    }
    for(int i=M+1;i<=K;i++)
        if(cnt[i]<2){
            puts("Impossible");
            return 0;
        }
    puts("Possible");
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

int find(vi& uf, int x) {
    return uf[x] = uf[x] == x ? x : find(uf, uf[x]);
}

int merge(vi& uf, vi& b, vi& w, int x, int y) {
    int xr = find(uf, x);
    int yr = find(uf, y);
    if (xr == yr)
        return 0;
    uf[xr] = yr;
    b[yr] += b[xr];
    w[yr] += w[xr];
    b[xr] = 0;
    w[xr] = 0;
    return 1;
}

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

    int n, m;
    cin >> n >> m;
    vector<string> grid(n);
    for (int i = 0; i < n; ++i) {
        cin >> grid[i];
    }

    vector<int> uf(n * m), b(n * m), w(n * m);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            uf[m * i + j] = m * i + j;
            b[m * i + j] = grid[i][j] == '#';
            w[m * i + j] = grid[i][j] == '.';
        }
    }
    
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i > 0 and grid[i - 1][j] != grid[i][j]) {
                merge(uf, b, w, m * (i - 1) + j, m * i + j);
            }
            if (j > 0 and grid[i][j - 1] != grid[i][j]) {
                merge(uf, b, w, m * i + j - 1, m * i + j);
            }
        }
    }
    
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (uf[m * i + j] != m * i + j)
                continue;

            int black = b[m * i + j];
            int white = w[m * i + j];
            ans += 1LL * black * white;
        }
    }

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


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

int sum(int x[]){
	int s=0;
	for (int i=1; i<10; i++) 
		s += x[i];
	return s;
}

bool check(int x[], int j=1){
	if (sum(x)==0) return true;
	for (int i=j; i<10; i++){
		int y[10];
		for (j=0; j<10; j++) y[j]=x[j];
		if (y[i]>=3){
			y[i]-=3;
			if (check(y,i)) return true;
			y[i]+=3;
		}
		if (i<8 && y[i]>0 && y[i+1]>0 && y[i+2]>0){
			y[i]--;
			y[i+1]--;
			y[i+2]--;
			if (check(y,i)) return true;
		}
	}
	return false;
}

int main(void){
	while (true){
		int n[10];
		REP(i,10) n[i]=0;
		string line;
		getline(cin,line);
		if (cin.eof()) break;
		for (int i=0; i<line.size(); i++)
			n[line[i]-'0']++;

		bool f = false;
		for (int i=1;i<10;i++){
			int n1[10];
			REP(i1,10) n1[i1]=n[i1];
			if (n1[i]>=4) continue;
			else n1[i]++;
			vi atama;
			for (int j=1; j<10; j++)
				if (n1[j] >= 2){
					n1[j] -= 2;
					if (check(n1)){
						if (f) cout<<" ";
						else f = true;
						cout<<i;
						break;
					}
					n1[j] += 2;
				}
		}
		if (f) cout<<endl;
		else cout<<"0"<<endl;
	}
}

Measured memory_bytes: 1180
N = int(input())
ans = set()
for i in range(1, N+1):
  for j in range(i+1, N+1):
    ans.add((i, j))

if N % 2 == 1: # 奇数
  for i in range(1, N+1):
    j = N - i
    ans.discard((i, j))
else: # 偶数
  for i in range(1, N+1):
    j = N + 1 - i
    ans.discard((i, j))

print(len(ans))
for a in ans:
  print(*a)

Measured memory_bytes: 4028
# coding: utf-8
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
AB = []
heapify(AB)
d = {}
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a > M:
        continue
    if a not in d.keys():
        d[a] = [-b]
    else:
        d[a].append(-b)
ans = 0
ables = []
now = 1
while now <= M:
    if now in d.keys():
        for v in d[now]:
            heappush(ables, v)
    if len(ables) > 0:
        v = heappop(ables)
        ans += -1 * v
    now += 1
print(ans)

Measured memory_bytes: 26444
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL <class T = int> inline T IN() { T x; cin >> x; return x; }
TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> vector<T> make_v(size_t a) { return vector<T>(a); }
TPL<TNM T, TNM... Ts> auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }

TPL<TNM T> using vec2 = decltype(make_v<T>(0, 0));
TPL<TNM T> using vec3 = decltype(make_v<T>(0, 0, 0));
TPL<TNM T> using vec4 = decltype(make_v<T>(0, 0, 0, 0));
TPL<TNM T> using vec5 = decltype(make_v<T>(0, 0, 0, 0, 0));

int main(void) {
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> A(M);

	REP(i, M) {
		A[i] = IN();
	}

	vector<bool> F(N + 1, false);
	REP(i, M) {
		F[A[i]] = true;
	}

	int ansR = 0;
	for (int i = X + 1; i <= N; ++i) {
		if (F[i])ansR++;
	}

	int ansL = 0;
	for (int i = X - 1; i >= 0; --i) {
		if (F[i])ansL++;
	}

	OUT(min(ansL, ansR));

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi 3.14159265358979323846
#define INF 1LL<<60

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

int main(){

    ll n,w,sum=0;cin>>n>>w;
    vector<ll> weight(n),value(n);
    for(ll i=0;i<n;i++){
        cin>>weight[i]>>value[i];
        sum+=value[i];
    }

    vector<vector<ll>> dp(105,vector<ll>(100010,INF));

    dp[0][0]=0;

    for(ll i=0;i<n;i++){
        for(ll val=0;val<=sum;val++){
            if(val-value[i]>=0) chmin(dp[i+1][val],dp[i][val-value[i]]+weight[i]);
            chmin(dp[i+1][val],dp[i][val]);
        }
    }

    ll ans=0;
    for(ll val=0;val<=sum;val++){
        if(dp[n][val]<=w) ans=val;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 83328
import java.awt.geom.Point2D;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){		
		new AOJ0205();
	}

	class AOJ0205{
		public AOJ0205() {
			while(true){
				int[] janken = new int[5];
				int[] result = new int[5];
				int a = in.nextInt();
				if(a==0)break;
				janken[0]=a;
				boolean g=false,t=false,p=false;
				if(janken[0]==1)g=true;
				else if(janken[0]==2)t=true;
				else if(janken[0]==3)p=true;
				for(int i=1;i<5;i++){
					janken[i]=in.nextInt();
					if(janken[i]==1)g=true;
					else if(janken[i]==2)t=true;
					else if(janken[i]==3)p=true;
				}
				if((g&&t&&p)||(g&&!t&&!p)||(!g&&t&&!p)||(!g&&!t&&p))for(int i=0;i<5;i++)result[i]=3;//あいこ
				else if(g&&t&&!p)for(int i=0;i<5;i++){
					if(janken[i]==1)result[i]=1;
					else result[i]=2;
				}else if(g&&!t&&p)for(int i=0;i<5;i++){
					if(janken[i]==3)result[i]=1;
					else result[i]=2;
				}else if(!g&&t&&p)for(int i=0;i<5;i++){
					if(janken[i]==2)result[i]=1;
					else result[i]=2;
				}
				for(int i=0;i<5;i++)System.out.println(result[i]);
			}
			
			
		}
	}

	class AOJ2503{
		int MAX = 0;
		public AOJ2503() {
			Scanner in = new Scanner(System.in);
			int n = in.nextInt();
			int m = in.nextInt();

			int[][] cost = new int[n][n];

			int[] dp = new int[n];
			for(int i=0;i<n*n;i++){
				cost[i/n][i%n]=MAX;
			}
			for(int i=0;i<m;i++){
				int a = in.nextInt();
				int b = in.nextInt();
				cost[a][b]=in.nextInt();
			}	
			//			TODO 一番大きいパスを0のポイントからn-1のポイントまでの

			for(int s=1;s<n;s++){
				for(int i=0;i<=s;i++){
					if(cost[i][s]==MAX)continue;
					dp[s]=Math.max(dp[s],dp[i]+cost[i][s]);
				}
			}
			for(int s=0;s<n;s++)for(int i=0;i<n;i++){
				if(cost[s][i]==MAX)continue;
				dp[i]=Math.max(dp[s]+cost[s][i],dp[i]);
			}
			for(int i=0;i<n;i++)System.out.print(dp[i]+" ");
			System.out.println();
			System.out.println(dp[n-1]);
		}
	}
}

Measured memory_bytes: 20800
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define mem(a) memset(a, 0, sizeof(a))
using namespace std;
const int MAXN = 105;
char s1[MAXN], s2[MAXN], s3[MAXN];
int main()
{
    while(~scanf("%s %s %s", s1, s2, s3))
    {
        int len=strlen(s1);
        int len1=strlen(s2);
        if(s1[len-1]==s2[0]&&s2[len1-1]==s3[0])
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector <int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  sort(L.begin(), L.end(),
       [](const int&x, const int&y){return x > y;});

  int ans = 0;
  for (int i = 0; i < N-2; i++) {
    int a = L[i];
    for (int j = i+1; j < N-1; j++) {
      int b = L[j];
      if (b >= a) continue;
      for (int k = j+1; k < N; k++) {
        int c = L[k];
        if (c >= b) continue;
        if (a < (b+c)) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  string S;
  cin >> S;
  if(S == "AAA" || S == "BBB"){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

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

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

  int N, M;
  scanf("%d%d", &N, &M);

  vector<tuple<int, int, int>> pref_year_id(M);
  for (int i = 0; i < M; i++) {
    int pid, year;
    scanf("%d%d", &pid, &year);
    pref_year_id.at(i) = make_tuple(pid, year, i);
  }

  sort(pref_year_id.begin(), pref_year_id.end());

  vector<int> pids(M), x(M), cnt(N + 1);
  for (auto pyi : pref_year_id) {
    int pid, id;
    tie(pid, ignore, id) = pyi;
    pids.at(id) = pid;
    cnt[pid]++;
    x.at(id) = cnt[pid];
  }

  for (int i = 0; i < M; i++) {
    cout << setfill('0') << setw(6) << pids.at(i);
    cout << setfill('0') << setw(6) << x.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
#define MAX_LOG 30
vector<int>G[MAX];
int depth[MAX];
int parent[MAX_LOG][MAX];
int root;
void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<G[v].size();i++)
    if(G[v][i]!=p)dfs(G[v][i],v,d+1);
}
void init(int V){
  //parent??¨dfs??????????????????
  dfs(root,-1,0);
  //parent??????????????????
  for(int k=0;k+1<MAX_LOG;k++)
    for(int v=0;v<V;v++)
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
}
int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(int k=0;k<MAX_LOG;k++)
    if((depth[v]-depth[u])>>k&1)
      v=parent[k][v];
  if(u==v)return u;
  for(int k=MAX_LOG-1;k>=0;k--)
    if(parent[k][u]!=parent[k][v]){
    u=parent[k][u];
    v=parent[k][v];
  }
  return parent[0][u];
}
int main(){
  root=0;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int p=0;
    cin>>p;
    while(p--){
      int t;
      cin>>t;
      G[i].push_back(t);
    }
  }
  init(n);
  int p;
  cin>>p;
  while(p--){
    int q,w;
    cin>>q>>w;
    cout<<lca(q,w)<<endl;
  }
}

Measured memory_bytes: 25328
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a+b,min(b+c,c+a));
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>

int main() {
  int alpha, pos;
  char count[26];

  for (alpha = 0; alpha < 26; alpha++) {
    count[alpha] = 0;
  }

  char ch;
  while (scanf("%c", &ch) != EOF) {
    if (isalpha(ch)) {
      alpha = tolower(ch) - 'a';
      count[alpha]++;
    }
  }

  for (alpha = 0; alpha < 26; alpha++) {
    char alpha_char = alpha + 'a';
    printf("%c : %d\n", alpha_char, count[alpha]);
  }

  return 0;
}



Measured memory_bytes: 2560
while true do
  n = gets.chomp
  break if n == '0000'
  if n.chars.all?{|x|x == n[0]} then
    puts 'NA'
    next
  end

  i = 0
  while true do
    if n == '6174' then
      puts i
      break
    end
    arr = n.chars.sort
    n = (arr.reverse.join.to_i - arr.join.to_i).to_s
    n = '0' * (4 - n.size) + n
    i += 1
  end

end

Measured memory_bytes: 6112
using System;
namespace ABC146A
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] arr = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
            for (int i = 0; i < arr.Length; i++)
            {
                if(arr[i] == s)
                {
                    Console.WriteLine(Math.Abs(7 - i));
                }
            }
        }
    }
}


Measured memory_bytes: 11220
stack = []

for s in input().split():
  if s in '+-*':
    res = 0
    b = stack.pop(-1)
    a = stack.pop(-1)
  
    if s == '+': 
      res = a + b
    elif s == '-':
      res = a - b
    elif s == '*':
      res = a * b
  
    stack.append(res)
  else:
    stack.append(int(s))

print(stack[0])



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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  int n;
  cin >> n;
  ll res = 0;
  for(ll i = 1;i <= n;i++){
    if(i%3 && i%5)res += i;
  }
  cout << res << endl;


  return 0;
}


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

int main(){
  int n,a,b; cin>>n>>a>>b;
  string s; cin>>s;
  
  int cnt1, cnt2;
  cnt1 = cnt2 = 0;
  for(auto e:s){
    if(e == 'a'){
      if(cnt1 < a+b){
        puts("Yes");
      	cnt1++;
      }else{
        puts("No");
      }
    }else if(e == 'b'){
      if(cnt1 < a+b && cnt2 < b){
        puts("Yes");
        cnt1++;
        cnt2++;
      }else{
        puts("No");
      }
    }else{
      puts("No");
    }
  }
  return 0;
}


Measured memory_bytes: 896
from collections import deque


def nearlist(N, LIST):
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR):
    que, frag = deque([0]), set([0])
    while que:
        q = que.popleft()
        for i in NEAR[q]:
            if i in frag:
                continue
            ans[i] += ans[q]
            que.append(i), frag.add(i)
    return

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

ans = [0] * n
for p, x in px:
    ans[p - 1] += x

near = nearlist(n, ab)
bfs(near)
print(*ans)


Measured memory_bytes: 230824
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str1 = br.readLine();
      String str2[] = str1.split(" ");
      int a = Integer.parseInt(str2[0]);
      int b = Integer.parseInt(str2[1]);
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );

    }
}

Measured memory_bytes: 24056
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>

#define REP(i, n) for(int i = 0;i < (n); i++)
#define REP2(i, x, n) for(int i = (x); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int A, B;
	while (cin >> A >> B) cout << (int)log10(A + B) + 1 << "\n";
	return 0;
}

Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
struct ZFunc{
    vector<int> z;
    ZFunc(const vector<int> & v): z(v.size()){
        int n = v.size(), a = 0, b = 0;
        if(!z.empty()) z[0] = n;
        for(int i = 1; i < n; ++i) {
            int end = i; if(i < b) end = min(i + z[i-a], b);
            while(end < n && v[end] == v[end-i]) ++end;
            z[i] = end - i; if(end > b) a = i, b = end;
        }
    }
};
const int mod = 1'000'000'007;
const int maxn = 2200000, lg = 24;
int p[lg][maxn];
int main(){
	string s, t; cin >> s >> t;
	int lens = s.size(), lent = t.size();
	while(lens < 2 * lent){
		lens = lens + lens;
		s = s + s;
	}
	lens = lens;
	s = s + s;
	vector<int> alp;
	for(auto c : t) alp.push_back(c);
	alp.push_back(-1);
	for(auto c : s) alp.push_back(c);
	ZFunc z(alp);
	for(int i = lent + 1; i < lent + 1 + lens; i++){
		int from = i - (lent + 1);
		if(z.z[i] >= lent){
			int to = i + lent - (lent + 1);	
			p[0][from] = to % lens;
		} else {
			p[0][from] = -1;	
		}
	}
	int ans = 0;
	for(int i = 1; i < lg; i++){
		for(int j = 0; j < lens; j++){
			if(p[i - 1][j] != -1){
				p[i][j] = p[i - 1][p[i - 1][j]];
			} else {
				p[i][j] = -1;
			}
		}
	}
	for(int j = 0; j < lens; j++){
		int now = j, val = 0;
		for(int i = lg - 1; i >= 0; i--){
			if(p[i][now] != -1){
				now = p[i][now];
				val += 1<<i;
			}
		}
		ans = max(ans, val);
	}
	if(ans >= lens) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 249236
import sys

N = int(raw_input())
A = [0] * N
for i in range(N):
  A[i] = [0] * N

for line in sys.stdin:
  values = line.split()
  u = int(values[0]) - 1
  k = int(values[1])
  nodes = values[2:]
  for i in range(int(k)):
    v = int(nodes[i]) - 1
    A[u][v] = 1

for i in range(N):
  print " ".join([str(x) for x in A[i]])

Measured memory_bytes: 6448
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main() {
  string s;
  int w;
  cin>>s>>w;
  REP(i,s.size()){
    if(i%w==0){
      cout<<s[i];
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt(), w = scanner.nextInt();
        long[][] dp = new long[n + 1][w + 1];
        for (int i = 1; i <= n; i++) {
            int w1 = scanner.nextInt(), u1 = scanner.nextInt();
            for (int j = 0; j <= w; j++)
                dp[i][j] = Math.max(j >= w1 ? dp[i - 1][j - w1] + u1 : 0, dp[i - 1][j]);
        }
        System.out.println(dp[n][w]);
    }
}

Measured memory_bytes: 129748
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

ll digit_sum(ll n) {
	ll s = 0;
	while (n != 0) s += n % 10, n /= 10;
	return s;
}

vector<ll> eratos(int N) {

	vector<ll> result;
	result.reserve(sqrt(N) + 1);
	vector<bool> f(N + 1);

	for (int i = 2; i <= N; i++) {
		if (!f[i]) {
			result.push_back(i);
			for (int k = 1; i * k <= N; k++) f[k*i] = true;
		}
	}

	return result;
}

int main(void) {

	int N;
	cin >> N;

	auto v = eratos(55555);
	
	for (int i = 0; i < v.size() && N > 0; i++) {
		if (v[i] % 10 == 1) {
			N--;
			cout << v[i] << ( N == 0 ? "\n" : " ");
		}
	}

	return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<int> A;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	int N, i = 1, j, l, r;
	long long ans = 0;
	cin >> N;
	A.resize(N);
	j = N - 2;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	ans = (r = A.back()) - (l = A[0]);
	while (i <= j) {
		if (max(abs(A[i] - l), abs(A[i] - r)) < max(abs(A[j] - l), abs(A[j] - r))) {
			if (abs(A[j] - l) < abs(A[j] - r)) {
				ans += abs(A[j] - r);
				r = A[j--];
			}
			else {
				ans += abs(A[j] - l);
				l = A[j--];
			}
		}
		else {
			if (abs(A[i] - l) < abs(A[i] - r)) {
				ans += abs(A[i] - r);
				r = A[i++];
			}
			else {
				ans += abs(A[i] - l);
				l = A[i++];
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n;cin>>n;
	ll a,b;cin>>a>>b;
	vector<ll> d(n);

	for(int i = 0; i < n; i++) {
		cin>>d[i];
	}
	ll ans = 0;
	for(int i = 0; i < n - 1; i++) {
		ll x = d[i + 1] - d[i];
		x *= a;
		ans += min(x,b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <numeric>
using namespace std;

typedef long long LL; typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

#define MOD 1000000007
#define int LL

long long pow_(long long a, long long n){
    if(n==0) return 1;
    long long re=pow_((a*a)%MOD,n/2)%MOD;
    if(n%2==1) re= (re*a)%MOD;
    return re%MOD;
}

LL nck(LL n, LL k){
    LL re=1;
    for(LL i = 1; i<=k; ++i){
        re=(re*(n-i+1))%MOD;
        re=(re*pow_(i,MOD-2))%MOD;
    }
    return re%MOD;
}

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

    LL h,w,a,b;
    cin >> h>>w>>a>>b;

    LL ans= nck(h+w-2,w-1);
    LL bef,aft;
    for(LL k=1 ; k <= b ; ++k){
        if(k==1){
            bef=1;
            aft=nck(a+w-2,w-1);
        }else{
            bef=(bef*(h+k-a-2))%MOD;
            bef=(bef*pow_(k-1,MOD-2))%MOD;
            aft=(aft*(a+w-k-a+1))%MOD;
            aft=(aft*pow_(a+w-k,MOD-2))%MOD;
        }
        ans=(ans-(bef*aft)%MOD+MOD)%MOD;

    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
 
    try {
      // 標準入力受け取り
      Scanner scan = new Scanner(System.in);      
      Long   tax1    = Long.parseLong(scan.next());
      Long   tax2    = Long.parseLong(scan.next());
      double price1  = tax1/0.08;
      double price2  = tax2/0.1;
      double result  = -1.0;
      
      if (price1 >= price2 && Math.ceil(price1) < (tax2+1)/0.1) {
        result = Math.ceil(price1);
      }
      
      if (price2 >= price1 && Math.ceil(price2) < (tax1+1)/0.08) {
        result = Math.ceil(price2);
      }
      
      System.out.println((int)result);
      
    } catch (Exception e) {     
      System.out.print("error");
    }
  }
}

Measured memory_bytes: 35564
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <regex>

typedef long long ll;
using namespace std;

string s;

int main()
{
	cin >> s;
	if (regex_match(s, regex("(dream|dreamer|erase|eraser)*")))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 39808
/*input
ABAABBBAABABAAABBAA
AABBBABBABBAAABABABAAB
BABAABAABABABBAAAB
AABABAAABBAABBBABAA
AAAAAAAAAAA
ABBBBBBBBBB
0
*/

macro_rules! input_vec {
    () => {
        input!()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    ($delimiter:expr) => {
        input!()
            .split($delimiter)
            .map(|x| x.parse().unwrap())
            .collect()
    };
}

macro_rules! input {
    () => {{
        let mut return_ = String::new();
        std::io::stdin().read_line(&mut return_).ok();
        return_.pop();
        return_
    }};
}

fn main() {
    let (mut inp, mut a, mut b);
    loop {
        a = 0;
        b = 0;
        inp = input!();
        if &inp[..] == "0" {
            break;
        }
        for i in inp.chars().skip(1) {
            match i {
                'A' => {
                    a += 1;
                }
                'B' => {
                    b += 1;
                }
                _ => {}
            }
        }
        if a > b {
            a += 1;
        } else {
            b += 1;
        }
        println!("{} {}", a, b);
    }
}



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

int main() {
  int Tc;
  cin>> Tc;
  for(int tc = 0; tc < Tc; ++tc) {
    vector<int> v(3);
    for(int i = 0; i < 3; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    if(v[0]*v[0]+v[1]*v[1] == v[2]*v[2]) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int res = 0;
    vector<string> s(n);
    vll t(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    bool f = false;
    for (int i = 0; i < n; i++) {
        if (s[i] == x) {
            f = true;
        } else {
            if (f) {
                res += t[i];
            }
        }
    }
    cout << res << endl;
}


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

int main(){
	int x,y,res;
	cin >> x >> y;
	while(1){
		if(x >= y){
			x = x%y;
			if(x == 0){
				res = y;
				break;
			}
		}
		else{
			y = y%x;
			if(y == 0){
				res = x;
				break;
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1164
S = input()
s = S.replace('RL', 'RxL')
s = s.split('x')
ans = []
for i in range(len(s)-1):
    r = s[i].count('R')
    l = s[i+1].count('L')
    rl = r+l
    ans += ['0'] * (r-1)
    if rl % 2 == 0:
        rl = rl//2
        ans += [str(rl),str(rl)]
    else:
        rl =  rl//2
        if r%2 != 0:
            ans += [str(rl+1),str(rl)]
        else:
            ans += [str(rl),str(rl+1)]
    ans += ['0'] * (l-1)
print(' '.join(ans))

Measured memory_bytes: 49924
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
  vector<int> x(5);
  int ans = 0;
  for (int i = 0; i < 5; ++i)
  {
    cin >> x[i];
    if (x[i] == 0) ans = i + 1;
  }

  cout << ans << endl;
}

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

int main() {
	int n;
	cin >> n;
	int d[n];
	for(int i = 0;i<n;i++)
		cin >> d[i];
	sort(d, d+n);
	int sum =0;
	for(int i = 0;i<n-1;i++)
		sum+=d[i];
	sum+=d[n-1]/2;
	cout << sum << endl;
	return 0;
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}



char name[100005];
int main(void){
    char s[15];
    int n;
    char march[10] = {'M', 'A', 'R', 'C', 'H'};
    long long candi[5] = {0};
    long long ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf(" %s", s);
        for (int j = 0; j < 5; j++){
            if (march[j] == s[0]) candi[j]++;
        }
    }
    for (int i = 0; i < 5; i++){
        for (int j = i + 1; j < 5; j++){
            for (int k = j + 1; k < 5; k++){
                ans += candi[i] * candi[j] * candi[k];
            }
        }
    }
    printf("%lld\n", ans);

    


    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(dead_code)]
pub const M: i64 = 1_000_000_007;

fn main() {
    input! {
        nn: usize, mm: usize,
        x: [i64; nn],
        y: [i64; mm]
    }
    let n = nn as i64;
    let m = mm as i64;
    let mut xr = 0i64;
    for k in 1..n+1 {
        xr += (2 * k - 1 - n) * x[k as usize - 1];
        xr %= M;
        if xr < 0 {
            xr += M;
        }
    }
    let mut yr = 0i64;
    for k in 1..m+1 {
        yr += (2 * k - 1 - m) * y[k as usize - 1];
        yr %= M;
        if yr < 0 {
            yr += M;
        }
    }
    println!("{}", xr * yr % M);
}


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

using namespace std;

using ll = long long;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> grid(h, vector<int>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      char x;
      cin >> x;
      if(x == '#') grid[i][j] = 1;
      else grid[i][j] = 0;
    }
  }
  vector<int> row(h, 0);
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      row[i] += grid[i][j];
    }
  }
  vector<int> col(w, 0);
  for(int j = 0; j < w; j++){
    for(int i = 0; i < h; i++){
      col[j] += grid[i][j];
    }
  }
  for(int i = 0; i < h; i++){
    bool space = false;
    for(int j = 0; j < w; j++){
      if(!row[i] || !col[j]) continue;
      cout << (grid[i][j] ? '#' : '.');
      space = true;
    }
    if(space) cout << "\n";
  }
  return 0;
}



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

long long int a,b,c,x;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>a>>b>>c>>x;
	if (a+b>=x) cout<<min(x,a);else cout<<a-(x-a-b);
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <functional>
#include <iterator>
using namespace std;
using VI = vector<long>;

int cnt(int n) {
    if (n % 2 == 0) {
        return 0;
    }
    
    VI d(100);
    for (int i = 3; i < 100; i += 2) {
        while (n % i == 0) {
            d[i]++;
            n /= i;
        }
    }
    int ans = 1;
    for (int i = 0; i < 100; i++) {
        if (d[i]) {
            ans *= d[i] + 1;
        }
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (cnt(i) == 8) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll w[105],v[105],dp[100005],a[100005];

int main()
{
    ll W,n,i,j;
    cin>>n>>W;
    for(j=0;j<100005;j++)
    {
        dp[j]=1e18;
        a[j]=1e18;
    }
    dp[0]=0;
    a[0]=0;
//    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(i=1;i<=n;i++)
    {
        for(j=0;j<100005;j++)
        {
            if((j-v[i-1])>=0)
            {
                dp[j]=min(a[j],w[i-1]+a[j-v[i-1]]);
            }
        }
        for(j=0;j<100005;j++)
        {
            a[j]=dp[j];
        }
    }
    ll c=100004;
    while(a[c]>W && c>=0)
        c--;
    cout<<c<<endl;
}


Measured memory_bytes: 1920
from heapq import heappop, heappush
from collections import defaultdict


def solve(string):
    n, m, *ab = map(int, string.split())
    dd = defaultdict(list)
    for a, b in zip(*[iter(ab)] * 2):
        dd[a].append(-b)
    hq, ans = [], 0
    for d in range(1, m + 1):
        if d in dd:
            for _b in dd[d]:
                heappush(hq, _b)
        if hq:
            ans += heappop(hq)
    return str(-ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 33848
#include <bits/stdc++.h>
#define INF 1023456789
#define sacnf scanf
#define CRLF <<'\n';
#define PRPAIR(x) x.first << x.second
#define DEBUG(x) do { std::cerr <<(x)<<'\n'; } while (0)
#define rep(i,a,b) for(int i=(a);i!=(int)b-((a)>(b));(a)>(b)?--i:++i)
#define trav(it,v) for(typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> pip;
typedef vector<int> vi;
typedef long long ll;

int main(){
    int a;
    scanf("%d",&a);
    printf("%d",a+a*a+a*a*a);

}


Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long a, b, c;

int main()
{
	scanf("%lld%lld%lld", &a, &b, &c);
	
	//此处需要预先判断一下
	if ((a + b) >= c) {
		printf("No\n");
		return 0;
	} 
	
	//平方会产生增根！，这里要预先判断一下 
	long long rVal2 = c - a - b;	//都带平方 
	
	
	rVal2 = rVal2 * rVal2;
	
	long long lVal2 = 4 * a * b;
	
	if (lVal2 < rVal2) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	
	
	return 0;
}

//两次平方取得值


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

int main(){
  int N;
  cin >> N;
  int x;
  int y = 30;
  int sum;
  int A;
  for(int i = 0; i < N; i++){
    cin >> A;
    x = A;
    sum = 0;
    for(int j = 0; j >=0; j++){
      if(x%2 == 0){
        sum +=1;
        x = x/2;
      }
      else{
        break;
      }
    }
    if(sum <= y){
      y = sum;
    }
  }
  cout << y << endl;
}


Measured memory_bytes: 256
#include <stdio.h>


main ()
{
	char str [100000];
	char alf [26] ;
	char ans ;
	int count ;
	
	count = 0 ;
	while ( count < 26 )
	{
		alf [ count ] = 0 ;
		count++;
	}
	
	scanf ( "%s", str );

	count = 0 ;
	while ( str [ count ] != 0 )
	{
		alf [ str [ count ] - 0x61 ] = 1 ;
		count++;
	}

	count = 0 ;
	while ( count < 26 )
	{
		if ( alf [ count ] == 0 )
		{
			ans = 0x61 + count ;
			printf ( "%c\n", ans );
			return 0 ;
		}
		count++;
	}

	printf ( "None\n" );
	return 0 ;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] d = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int result = 0, sum = 0, r = Math.min(n, k);
			SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
			for (int i = 0; i <= r; i++) {
				// iは左側から取り出す数
				if (i > 0) {
					sum += d[i - 1];
					map.put(d[i - 1], map.getOrDefault(d[i - 1], 0) + 1);
				}
//				System.out.println("i=" + i + ", map=" + map);
				if (0 == (i & 1)) {
					// jは右側から取り出す数
					for (int j = 0; j <= r - i; j++) {
						if (j > 0) {
							sum += d[n - j];
							map.put(d[n - j], map.getOrDefault(d[n - j], 0) + 1);
						}
//						System.out.println("i=" + i + ",j=" + j + ", map=" + map);
						result = Math.max(result, checkRemove(sum, map, k - i - j));
//						System.out.println("sum=" + sum + ", result=" + result);
					}
					if (r - i > 0) {
						sum -= d[n - r + i];
						remove(map, d[n - r + i], 1);
					}
				} else {
					// jは右側から取り出す数
					for (int j = r - i; j >= 0; j--) {
						if (j < r - i) {
							sum -= d[n - 1 - j];
							remove(map, d[n - 1 - j], 1);
						}
//						System.out.println("i=" + i + ",j=" + j + ", map=" + map);
						result = Math.max(result, checkRemove(sum, map, k - i - j));
//						System.out.println("sum=" + sum + ", result=" + result);
					}
				}
			}
			System.out.println(result);
		}
	}

	/**
	 * mapからkeyをamount分削除
	 * 
	 * @param map
	 * @param key
	 * @param amount
	 * @return 削除された数
	 */
	private static int remove(SortedMap<Integer, Integer> map, int key, int amount) {
//		System.out.println("key=" + key + ", amount=" + amount);
		int value = map.get(key);
		if (value <= amount) {
			map.remove(key);
			return value;
		} else {
			map.put(key, value - amount);
			return amount;
		}
	}

	/**
	 * 手持ちの宝石の捨てる作業を実施する
	 * 
	 * @param sum    手持ちの宝石の価値の合計
	 * @param map    手持ちの宝石を保存するマップ
	 * @param remain 捨てる宝石の最大値
	 * @return 宝石を捨てた後の手持ちの宝石の価値の合計
	 */
	private static int checkRemove(int sum, SortedMap<Integer, Integer> map, int remain) {
		Map<Integer, Integer> tempMap = new HashMap<>();
//		System.out.println("map=" + map + ", sum=" + sum + ", remain=" + remain);
		while ((!map.isEmpty()) && (remain > 0)) {
			int firstKey = map.firstKey();
//			System.out.println("firstKey=" + firstKey);
			if (firstKey >= 0) {
				break;
			}
			int diff = remove(map, firstKey, remain);
			tempMap.put(firstKey, diff);
			remain -= diff;
//			System.out.println("diff=" + diff + ", map=" + map);
			sum -= firstKey * diff;
		}
		tempMap.entrySet()
				.forEach(entry -> map.put(entry.getKey(), map.getOrDefault(entry.getKey(), 0) + entry.getValue()));
//		System.out.println("map=" + map + ", sum=" + sum);
		return sum;
	}
}


Measured memory_bytes: 42268
#include<iostream>
using namespace std;
int main()
{
	int l,r,d;
	cin>>l>>r>>d;
	int count=0;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)
			count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long X, long long Y) {
  if (abs(X - Y) <= 1) {
    print("Brown");
  } else {
    print("Alice");
  }
}

int main() {
  long long X;
  scanf("%lld", &X);
  long long Y;
  scanf("%lld", &Y);
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 256