akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
const int maxn = 200005;
int N, p[maxn], q[maxn];
bool c(int x, int y, int z) {
	if(q[x] < q[y]) return q[z] < q[x] or q[y] < q[z];
	return q[y] < q[z] and q[z] < q[x];
}
int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i) scanf("%d", p + i);
	for(int i = 1; i <= N; ++i) q[p[i]] = i;
	int t = 0, f = -1;
	for(int i = N - 1; i; --i) {
		if(t == 0) {
			if(q[i] > q[i + 1]) t = 1, f = i + 1;
		} else {
			if(!c(i, i + 1, f)) t = t + 1, f = i + 1;
		}
	}
	printf("%d\n", t);
	return 0;
}

Measured memory_bytes: 1664
#C問題
N=int(input())
B=0
A=0
BA=0
count=0
for i in range(N):
    s=str(input())
    slist=list(s)
    slen=len(slist)
    flag=0
    abflag=0
    j=0
    for j in range(slen):
        if j == 0:
            if slist[0] == "B":
                flag=1
            elif slist[0] == "A":
                abflag=1
            else:
                pass
        elif j == slen-1:
            if slist[-1] == "A":
                if flag == 1:
                    flag=3
                else:
                    flag=2
            elif slist[-1] == "B":
                if abflag==1:
                    count+=1
            else:
                pass
        else:
            if slist[j] == "A":
                abflag=1
            elif slist[j] == "B":
                if abflag==1:
                    count+=1
                    abflag=0
                else:
                    abflag=0
            else:
                abflag=0
                
    if flag == 1:
        B+=1
    elif flag == 2:
        A+=1
    elif flag == 3:
        BA+=1
        
if BA>=1:
    count+=(BA-1)

if B>=1 and BA >= 1:
    count+=1
    if A >= 1:
        count+=1
        count+=min((A-1),(B-1))
elif A>=1 and BA >= 1:
    count+=1
elif A>=1 and B >= 1:
    count+=min(A,B)
print(count)
            

Measured memory_bytes: 3188
def getTableMP(Ss):
    lenS = len(Ss)
    table = [-1] * (lenS+1)
    j = -1
    for i in range(lenS):
        while j >= 0 and Ss[i] != Ss[j]:
            j = table[j]
        j += 1
        table[i+1] = j
    return table


Ss = input()
Ts = input()

lenS, lenT = len(Ss), len(Ts)
num = (lenT+lenS-1+lenS-1)//lenS
S2s = Ss * num

tableMP = getTableMP(Ts + '$' + S2s)

isFounds = [False] * lenS
for i in range(2*lenT+1, 2*lenT+lenS+1):
    if tableMP[i] >= lenT:
        isFounds[i-2*lenT-1] = True

ans = 0
numDone = 0
for i in range(lenS):
    if not isFounds[i]:
        i = (i+lenT)%lenS
        for num in range(lenS+1):
            if not isFounds[i]:
                ans = max(ans, num)
                numDone += num+1
                break
            i = (i+lenT)%lenS
        else:
            ans = -1
            break

if numDone < lenS:
    ans = -1
print(ans)


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


int main(){
	int n;
	string a;
	string b;
	int counta = 0;
	int countb = 0;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a >> b ;
		//cout << a <<' '<< b << endl;
		if (a==b)
		{
			counta += 1;
			countb += 1;

		}
		else if (a>b)
		{
			counta += 3;
		}
		else if (a<b)
		{
			countb += 3;
		}

	}

	cout << counta << ' ' << countb << endl;





	return 0;
}

Measured memory_bytes: 3140
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        List<Integer>[] list=new ArrayList[n];
        for(int i=0;i<n;i++){
            list[i]=new ArrayList<>();
        }
        int tmpu;
        int tmpv;
        int tmpw;
        for(int i=0;i<n-1;i++){
            tmpu=sc.nextInt()-1;
            tmpv=sc.nextInt()-1;
            tmpw=sc.nextInt();
            list[tmpu].add(tmpv*(tmpw%2==0?1:-1));
            list[tmpv].add(tmpu*(tmpw%2==0?1:-1));
        }
        boolean[] ans=new boolean[n];
        Queue<Integer> queue=new ArrayDeque<>();
        queue.add(0);
        ans[0]=true;
        int visited=1;
        boolean[] visit=new boolean[n];
        visit[0]=true;
        int stmp;
        int qtmp;
        while(true){
            stmp=queue.size();
            for(int j=0;j<stmp;j++){
                qtmp=queue.poll();
                for(int k=0;k<list[qtmp].size();k++){
                    if(visit[Math.abs(list[qtmp].get(k))])continue;
                    visit[Math.abs(list[qtmp].get(k))]=true;
                    queue.add(Math.abs(list[qtmp].get(k)));
                    if(list[qtmp].get(k)>0){
                        ans[Math.abs(list[qtmp].get(k))]=ans[qtmp];
                    }else{
                        ans[Math.abs(list[qtmp].get(k))]=!ans[qtmp];
                    }
                    visited++;
                }
            }
            if(visited==n){
                break;
            }
        }
        for(boolean a:ans){
            System.out.println(a?1:0);
        }
 
    }

}

Measured memory_bytes: 109664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=jp

int n;
int S[1000005];

static bool bin(int x) {
    int l = 0, r = n;
    while(l < r) {
        int m = (l+r) / 2;
        if (S[m] == x) {
            return true;
        }

        if (x < S[m]) {
            r = m;
        }
        else {
            l = m + 1;
        }
    }

    return false;
}

int main() {
    int ans = 0;
    cin >> n;
    REP(i, n) cin >> S[i];
    int q; cin >> q;
    REP(i, q) {
        int x; cin >> x;
        if (bin(x)) ans ++;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3376
# coding: utf-8
# Your code here!

seikai = 'CODEFESTIVAL2016'
matigai_count = 0

s = input()

for i in range(16):
    # print(s[i])
    # print(seikai[i])
    if s[i] == seikai[i]:
        # print('〇')
        pass
    else:
        # print('×')
        matigai_count += 1

print(matigai_count)

Measured memory_bytes: 2940
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N; cin >> N;
  set<int> S;
  rep(i,N){
    int a; cin >> a;
    S.insert(a);
  }
  int l=S.size();
  cout << l << endl;

  
}

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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

    int ans = -1e9;

    for(int left = 0; left <= n; left++){
        for(int right = 0; right <= n; right++){

            if(left + right > n || left + right > k) continue;

            vector<int> s(n);
            for(int i = 0; i < left; i++) s.push_back(v[i]);
            for(int j = 0; j < right; j++) s.push_back(v[n-1-j]);

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

            int sum = 0;
            for(int i = 0; i < s.size(); i++){
                sum += s[i];
            }

            int cnt = k - (left + right);

            for(int i = 0; i < s.size(); i++){
                if(s[i] > 0) break;

                if(cnt > 0){
                    cnt--;
                    sum -= s[i];
                }
            }

            ans = max(ans, sum);
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> c(n);
    vector<int> v(n);
    vector<int> profit(n);
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        profit[i] = c[i] - v[i];
    }

    int ans = 0;

    for (int i = 0; i < n; i++)
    {
        if (profit[i] > 0)
        {
            ans += profit[i];
        }
    }

    cout << ans << endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c<<endl;
	return 0;
}


Measured memory_bytes: 896
/*
    Author: MEHXM
*/
#include <bits/stdc++.h>
using namespace std;

#define cp_io ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long int
#define oo 1000000010
#define MAX 1000000
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define nl "\n"

int main()
{
    cp_io;
    #ifndef ONLINE_JUDGE
    freopen("z_input.txt","rt",stdin);
    freopen("z_output.txt","wt",stdout);
    #endif
    int n,k;
    cin >> n >> k;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];
    
    sort(a, a+n);
    ll ans = 0;
    for(int i=0; i<k; i++)
        ans += a[i];
    
    cout << ans << nl;
    
    return 0;
}

Measured memory_bytes: 3640
# cook your dish here
import sys
 
sys.setrecursionlimit(100005)
MOD = 1000000007
 
 
def dfs(v, a):
    w, b = 1, 1
    # print(w,b,v);
    for u in links[v]:
        if u == a:
            continue
        cw, cb = dfs(u, v)
        w *= cw + cb
        b *= cw
        w %= MOD
        b %= MOD
        # print(w,b,u,cw,cb);
    return w, b
 
 
n = int(input())
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    links[x].add(y)
    links[y].add(x)
 
print(sum(dfs(0, None)) % MOD)

Measured memory_bytes: 112448
#include<stdio.h>

int main(void)
{
    int W;//長方形右x
    int H;//長方形右y
    int x;//中心x
    int y;//中心y
    int r;//半径

    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

    if ((x - r < 0) || (y - r < 0)|| (x + r > W) || (y + r > H)) {
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }
    
    return 0;
}

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

int main()
{
    int sum=0;
    int bell[3];
    for(int i=0;i<3;i++){
        cin >> bell[i];
        sum += bell[i];
    }
    cout << sum - max(bell[0],max(bell[1],bell[2])) << endl;
    return 0;
}



Measured memory_bytes: 256
N=int(input())
S=list(input())
 
ans=[]
for i in S:
    if ord(i)+N>90:
        temp=chr(ord(i)+N-26)
        ans.append(temp)
    else:
        temp=chr(ord(i)+N)
        ans.append(temp)
 
f=''.join(ans)
 
print(f)

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

int main(){
  int N,K;
  cin >> N >> K;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int ans= INT_MAX;
  for(int l=0, r=K-1; r<N; l++, r++){
    int dist= (data.at(r) <= 0) ? -data.at(l)
             :(data.at(l) >= 0) ?  data.at(r)
                                : min(-data.at(l), data.at(r))+ (data.at(r)- data.at(l));
    ans= min(ans, dist);
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int main(){
  int N;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    int x,y,b,p,ans = INF;
    cin >> x >> y >> b >> p;
    for(int j = b ; j <= 10 ; j++ ){
      for(int k = p ; k <= 10 ; k++ ){
        int money = (x * j + y * k) * (j>=5&&k>=2?0.8:1);
        ans = min(ans,money);
      }
    }
    cout << ans << endl;
  }
}

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

#define MAXN (100010)

int n;
char str[MAXN];
char ans[MAXN];

bool check(char fst, char snd){
	for(int i = 0; i < MAXN; ++ i) ans[i] = 2;
	ans[0] = fst;
	ans[1] = snd;
	if((ans[0] == 0 && str[0] == 'o') || (ans[0] == 1 && str[0] == 'x')) ans[n - 1] = ans[1];
	else ans[n - 1] = !ans[1];
	for(int i = 1; i < n; ++ i){
		int pre = i - 1, sec = (i + 1) % n;
		if((ans[i] == 0 && str[i] == 'o') || (ans[i] == 1 && str[i] == 'x')){
			if(ans[sec] != 2 && ans[sec] != ans[pre]) return false;
			ans[sec] = ans[pre];
		}
		else{
			if(ans[sec] != 2 && ans[sec] == ans[pre]) return false;
			ans[sec] = !ans[pre];
		}
	}
	for(int i = 0; i < n; ++ i){
		ans[i] = ans[i] ? 'W' : 'S';
	}
	ans[n] = 0;
	return true;
}

int main(){
	scanf("%d%s", &n, str);
	if(check(0, 0)) return printf("%s\n", ans), 0;
	if(check(0, 1)) return printf("%s\n", ans), 0;
	if(check(1, 0)) return printf("%s\n", ans), 0;
	if(check(1, 1)) return printf("%s\n", ans), 0;
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[24];
	int i;
	
	scanf("%s", str);
	
	for (i = strlen(str) - 1; i >= 0; i--){
		printf("%c", str[i]);
	}
	printf("\n");
	
	return (0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for (int num = 1; num <= n; num++)
    {
        double tmp = 1.0 / n;
        int now = num;
        while (now < k)
        {
            now *= 2;
            tmp /= 2;
        }
        ans += tmp;
    }
    cout << fixed;
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main(){
  int n;
  cin>>n;
  vector<P> v(n);
  rep(i,n){
    int a,b;
    cin>>a>>b;
    v[i].F=a+b;
    v[i].S=a;
  }

  sort(all(v));
  reverse(all(v));

  ll ans=0;
  rep(i,n){
    if(i%2)
      ans-=v[i].F-v[i].S;
    else
      ans+=v[i].S;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int N;
  if(b<10){
    N=a*10+b;
  }
  else if(b<100){
    N=a*100+b;
  }
  else{
    N=a*1000+b;
  }
  bool flag=false;
  for(int i=0;i<N;i++){
    if(i*i==N){
      flag=true;
    }
  }
  if(flag==true){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,W,H,a[100001],c,po,m;
struct page{
	int b,x1[100],y1[100],x2[100],y2[100];
	string name,link[100];
};

int main(){
	while(cin>>n&&n){
		fill(a,a+100001,-1);
		a[0]=0;c=0;po=0;
		cin>>W>>H;
		page p[100];
		rep(i,n){
			cin>>p[i].name>>p[i].b;
			rep(j,p[i].b)cin>>p[i].x1[j]>>p[i].y1[j]>>p[i].x2[j]>>p[i].y2[j]>>p[i].link[j];
		}
		cin>>m;
		rep(i,m){
			string s;
			cin>>s;
			if(s=="click"){
				int x,y;
				cin>>x>>y;
				rep(j,p[c].b)if(p[c].x1[j]<=x&&x<=p[c].x2[j]&&p[c].y1[j]<=y&&y<=p[c].y2[j]){
					string st=p[c].link[j];
					rep(k,n)if(st==p[k].name)c=(a[++po]=k);
					fill(a+po+1,a+100001,-1);
					break;
				}
			}
			if(s=="back"&&po)c=a[--po];
			if(s=="forward"&&a[po+1]!=-1)c=a[++po];
			if(s=="show")cout<<p[c].name<<endl;
		}
	}
}

Measured memory_bytes: 1504
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def dfs(n,seq):
    if seq[n:] in ['dreamer', 'dream', 'erase', 'eraser']:
        return True

    if seq[n:n+7] == 'dreamer':
        if dfs(n+5, seq):
            return True
        elif dfs(n+7, seq):
            return True
        else:
            return False

    elif seq[n:n+5] == 'dream':
        return dfs(n+5, seq)

    elif seq[n:n+6] == 'eraser':
        return dfs(n+6, seq)

    elif seq[n:n+5] == 'erase':
        return dfs(n+5, seq)
    else:
        return False


def run():
    S = input()
    if dfs(0,S):
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    run()

Measured memory_bytes: 23044
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string & str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	int x;
	vector<vector<bool>> p(n, vector<bool>(3));
	scanf("%d", &x);
	rep(i, x) {
		int a;
		scanf("%d", &a);
		p[--a][0] = true;
	}
	scanf("%d", &x);
	rep(i, x) {
		int a;
		scanf("%d", &a);
		p[--a][1] = true;
	}
	scanf("%d", &x);
	rep(i, x) {
		int a;
		scanf("%d", &a);
		p[--a][2] = true;
	}
	int ans = 0;
	rep(i, n) {
		if ((not p[i][0] and p[i][2]) or (p[i][1] and p[i][2]))++ans;
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 3220
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N int
	var S string

	ans := ""
	al := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)
	for index := 0; index < len(S); index++ {
		t := S[index : index+1]
		at := strings.Index(al, t)
		targetJ := (at + N) % 26
		target := al[targetJ : targetJ+1]
		ans = ans + target
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/



int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
      string s,t;
      cin>>s>>t;
      int ans=t.size();
      for(int i=0;i<=s.size()-t.size();i++){
        int k=0;
        int sum=0;
         for(int j=i;j<i+t.size();j++){
           if(t[k]!=s[j])sum++;
           k++;
         }
         ans=min(ans,sum);
      }
      cout<<ans<<endl;
      
    }
}












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

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

    int ans = 0, num[3] = {9,999,99999};
    
    ans += min(num[0], n);
    if(n >= 100) ans += min(num[1],n)-99;
    if(n >= 10000) ans += min(num[2],n)-9999;
    cout<<ans<<endl;
}

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

int main()
{
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--, B--, C--, D--;
    string S;
    cin >> S;
    bool ans = true;
    for (int i = A; i < C; i++)
        if (S[i] == '#' and S[i + 1] == '#')
            ans = ans and false;
    for (int i = B; i < D; i++)
        if (S[i] == '#' and S[i + 1] == '#')
            ans = ans and false;
    if (ans and C > D)
    {
        int flag = false;
        for (int i = B - 1; i <= D-1; i ++)
            if (S[i] == '.' and S[i+1] == '.' and i + 2 <= N-1 and S[i+2] == '.')
                flag = true;
        ans = ans and flag;
    }
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

   	return 0;
}

Measured memory_bytes: 640
import Control.Applicative
import Data.Bool (bool)

main :: IO ()
main = getLine >> solve <$> f >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve = bool "DENIED" "APPROVED" . all f
  where
    f x = odd x || x `mod` 3 == 0 || x `mod` 5 == 0


Measured memory_bytes: 892
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int deg[110000];
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;
	UF[a]+=UF[b];UF[b]=a;
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)UF[i]=-1;
		for(int i=0;i<a;i++)deg[i]=0;
		for(int i=0;i<b;i++){
			int p,q;
			scanf("%d%d",&p,&q);
			p--;q--;
			UNION(p,q);
			deg[p]++;
			deg[q]++;
		}
		bool ok=true;
		for(int i=0;i<a;i++)if(deg[i]>2)ok=false;
		
		int rk=0;
		for(int i=0;i<a;i++)if(UF[i]<0)rk++;
		if(rk!=a-b)ok=false;
		if(ok)printf("yes\n");
		else printf("no\n");
	}
}

Measured memory_bytes: 1796
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n, m;
	cin >> n >> m;
	vi a(m), b(m);
	rep(i, 0, m) {
		cin >> a[i] >> b[i];
	}
	erep(i, 1, n) {
		int cou = 0;
		rep(j, 0, m) {
			if (a[j] == i || b[j] == i) cou++;
		}
		cout << cou << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

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

void insertionSort(int A[],int N){
  int j,i,v;
  for(i=1;i<N;i++){
    v = A[i];
    j = i -1;
    while( j>=0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A,N);
  }
}


int main(){
  int N, i, j;
  int A[100];
  scanf("%d", &N);
  for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);
  trace(A, N);
  insertionSort(A,N);
  return 0;
}


Measured memory_bytes: 2144
#ABC093C
abc=list(map(int,input().split()))
check=[x%2 for x in abc]
z=check.count(0)
ans=0
if z!=0 and z!=3:
	ans+=1
	for i in range(3):
		if check[i]==2-z:
			abc[i]+=1
m=max(abc)
for x in abc:
	ans+=(m-x)//2
print(ans)

Measured memory_bytes: 3064
/*input
5
5 5 5 5 1

*/
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 

using namespace std;
long long mod=1e9+7;
typedef long long int lld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define Error(x) cerr << #x << " = " << (x) <<endl;
#define Error2(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define popcount __builtin_popcountll
typedef pair<lld,lld> PA;
#define lim 1000010
#define lim2 3003
// inline lld sqr(lld x) { return x * x; }
// map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

lld A[lim],Fen[lim];

lld n,m,p,q;

lld P[lim];


lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}


int main(){
    lld T,i,j,h,l,r,k,s,b,c,a,d,w,x,y,v,z,t,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    sc(n);
    rep(i,1,n) sc(A[i]);
    sum=0;
    rep(i,1,n) if(A[A[i]]==i) sum++;
    prL(sum/2);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
bool bo[30],boo[30];
signed main(){
	int a,b,c,d,ans=0;
	cin>>a>>b;
	f(i,a){
		cin>>c;
		f(i,c){
			cin>>d;
			bo[d-1]=true;
		}
		f(i,b){
			if(!bo[i]) boo[i]=true;
			bo[i]=false;
		}
	}
	f(i,b){
		if(!boo[i]) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	long long int a, b, k;
	scanf("%lld%lld%lld", &a, &b, &k);
	if(a<k){
		k -= a;
		a=0;
		if(b<k){
			b=0;
		}else{
			b -= k;
		}
	}else{
		a -= k;
	}
	printf("%lld %lld", a, b);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int i, j, n, dummy; //nは持っているトランプの枚数
    char mark;
    int num; //numは持っているトランプのランク（トランプ上の数字）
    char marks[4] = {'S', 'H', 'C', 'D'};
    int cards[4][13] = {0};

    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        scanf("%d", &dummy);
        scanf("%c %d ", &mark, &num);
        if(mark == 'S') j = 0;
        if(mark == 'H') j = 1;
        if(mark == 'C') j = 2;
        if(mark == 'D') j = 3;

        cards[j][num - 1] = 1;
    }

    for(i = 0; i < 4; i++){
        for(j = 0; j < 13; j++){
            if(cards[i][j] == 0){
                if(i == 0) printf("S %d\n", j + 1);
                if(i == 1) printf("H %d\n", j + 1);
                if(i == 2) printf("C %d\n", j + 1);
                if(i == 3) printf("D %d\n", j + 1);
            }
        }
    }
    return 0;
}


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

void solve()
{
	int s, w;
	cin >> s >> w;
	if(w >= s) cout << "unsafe\n";
	else cout << "safe\n";
	
}

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


Measured memory_bytes: 3620
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int N=2005;
///Code begin..................................................................
inline LL Scan() {
    LL x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int main()
{
    int n, Y;
    scanf("%d%d",&n,&Y);
    if (Y%1000) puts("-1 -1 -1");
    else {
        Y/=1000;
        Y-=n;
        if (Y<0) puts("-1 -1 -1");
        else {
            FOR(i,0,Y/9) {
                if ((Y-9*i)%4==0&&n-i-(Y-9*i)/4>=0) {
                    printf("%d %d %d\n",i,(Y-9*i)/4,n-i-(Y-9*i)/4);
                    return 0;
                }
            }
            puts("-1 -1 -1");
        }
    }
    return 0;
}


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

// Disjoint Set
template<typename T>
class UnionFind {
 private:
  T _size;
  vector<T> _parent; // 親の番号（親自身はー（マイナス）集合要素の個数）

 public:
  // n要素で生成
  explicit UnionFind(T n) : _size{n}, _parent{vector<T>(n, -1)} {}

  // 木の根を求める
  T find(T x) {
    if (x < 0 || x >= _size) {
      return x;
    }

    if (_parent[x] < 0) {
      return x;
    }

    return _parent[x] = find(_parent[x]);
  }

  // xとyの属する集合を併合する
  bool unite(T x, T y) {
    if (x < 0 || x >= _size || y < 0 || y >= _size) {
      return false;
    }

    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    }

    if (size(x) > size(y)) {
      _parent[x] += _parent[y];
      _parent[y] = x;
    } else {
      _parent[y] += _parent[x];
      _parent[x] = y;
    }

    return true;
  }

  // xとyが同じ集合に属するか
  bool same(T x, T y) {
    return find(x) == find(y);
  }

  // xの属する集合の個数を求める
  T size(T x) {
    if (x < 0 || x >= _size) {
      return 1;
    }

    return -_parent[find(x)];
  }

  // 全体の個数を求める
  T size() {
    return _size;
  }
};

constexpr int MAX_N = 1e5;
constexpr int MAX_M = 1e5;
long A[MAX_M];
long B[MAX_M];
long dp[MAX_N + 1];

int main() {
  long N, M;
  cin >> N >> M;
  for (long i{}; i < M; ++i) {
    cin >> A[i];
    --A[i];
    cin >> B[i];
    --B[i];
  }
  UnionFind<long> uf(N);

  dp[M - 1] = N * (N - 1) / 2;
  for (long i{M - 1}; i >= 1; --i) {
    dp[i - 1] = dp[i];
    if (uf.find(A[i]) != uf.find(B[i])) {
      dp[i - 1] -= uf.size(A[i]) * uf.size(B[i]);
      uf.unite(A[i], B[i]);
    }
  }

  for (int i{}; i < M; ++i) {
    cout << dp[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4480
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	string s;
	cin >> s;
	
	int max = 0;
	for (int i = 0; i < s.size(); i++)
	{
		int length = 0;
		for (int j = i; j < s.size(); j++)
		{
			if ((s[j] == 'A') || (s[j] == 'C') || (s[j] == 'G') || (s[j] == 'T'))
			{
				length++;
			}
			else
			{
				break;
			}
		}
		
		if (length > max)
		{
			max = length;
		}
	}
	
	cout << max << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int D = cin.nextInt();
        long N = cin.nextLong();

        long ret = 1;
        for (int i = 0; i < D; i++)
        {
            ret *= 100;
        }

        if (N == 100)
        {
            Console.WriteLine(ret * 101);
        }
        else
        {
            Console.WriteLine(ret * N);
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 11220
n, m = map(int, input().split())
A = set([int(input()) for _ in range(m)])

MOD = 10 ** 9 + 7
dp = [0] * (n + 1)

dp[0] = 1
if 1 not in A:
  dp[1] = 1

for i in range(2, n + 1):
  if i not in A:
    dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[-1])

Measured memory_bytes: 13216
#include <bits/stdc++.h>
#define ll long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf llONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
using namespace std;

const int N = 2e5 + 10;

pair < ll, ll > a[N], tmp;
ll c[N];
ll dp[100];

bool cmp(pair < ll, ll > a, pair < ll, ll > b) {
    return a.first * (b.second + 1) > b.first * (a.second+ 1);
}

void solve() {

    int n; ll t;
    scanf("%d %lld", &n, &t);
    int cnt1 = 0, cnt2 = 0;
    rep(i, 1, n) {
      ll x , y ;
        scanf("%lld %lld", &x, &y);
        if(x == 0) c[++ cnt2] = y + 1;
        else a[cnt1++] = {x , y};
    }

    sort(c + 1 , c + cnt2 + 1);
    sort(a, a + cnt1, cmp);

    rep(i, 1, 30) dp[i] = t + 1;
    dp[0] = 0;
    rep(i, 1, cnt2 ) c[i] += c[i - 1];

    rep(i, 0, cnt1 - 1) {
        dep(j, 1, 30) {
            dp[j] = min(dp[j], (a[i].first + 1) * (dp[j - 1] + 1) + a[i].second);
        }
    }

    int ans = 0;

    for(int i = 0 ;i <= 30 ;i ++)
     {
       if(dp[i] > t) continue ;
       int j = 0 ;
       if(cnt2)
        j = upper_bound(c + 1 , c + cnt2 + 1 , t - dp[i]) - c - 1;
       ans = max(ans , i + j) ;
     }
    printf("%d\n", ans);
    return ;
}
int main() {
    solve();

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
int r, d, x_2000;
int main() {
    std::vector<int> vec(11, 0);
    std::cin >> r >> d >> x_2000;
    vec[0] = x_2000;
    for (int i = 1; i <= 10; i++) {
        vec[i] = r * vec[i-1]-d;
    }
    for (int i = 1; i <= 10; i++) {
        std::cout << vec[i] << std::endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define all(v) (v).begin(),(v).end()

int main(){
  	int N, T, A;
  	cin >> N >> T >> A;
  	double H_id = (T - A) / 0.006;
    vector<double> H_i(N);
  	for (int i = 0; i < N; i++){
      	cin >> H_i[i];
      	H_i[i] = abs(H_i[i]-H_id);
    }
  	vector<double>::iterator iter = min_element(all(H_i));
  	cout << distance(H_i.begin(), iter)+1 << endl;
}

Measured memory_bytes: 3760
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

x = INT()

a = x // 500
b = x - a * 500
c = b // 5
print(a * 1000 + c * 5)


Measured memory_bytes: 5968
import collections
n=int(input())
s=input()

cnt=0
def excludeRGB(c1,c2,c3):
  cnt=0
  for a in range(len(s)-2):
    if s[a] != c1:
      continue
    for b in range(1,len(s)):
      if a+b*2 >= n or a+b >= n:
        break
      if s[a+b] == c2 and s[a+b*2] == c3:
        cnt+=1
  return cnt

ans=0
def rgb(c1,c2,c3):
  ans,c1num,c2num=0,0,0
  for i in s[::-1]:
    if i == c1:
      c1num+=1
    elif i == c2:
      c2num+=c1num
    elif i == c3:
      ans+=c2num
  return ans
cnt+=excludeRGB("R","G","B")
cnt+=excludeRGB("R","B","G")
cnt+=excludeRGB("B","G","R")
cnt+=excludeRGB("B","R","G")
cnt+=excludeRGB("G","B","R")
cnt+=excludeRGB("G","R","B")

ans+=rgb("R","G","B")
ans+=rgb("R","B","G")
ans+=rgb("B","G","R")
ans+=rgb("B","R","G")
ans+=rgb("G","B","R")
ans+=rgb("G","R","B")
print(ans-cnt)

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

int main() {
	// your code goes here
	long N,A,B;
	cin >> N >> A >> B;
	long X[N];
	long tired=0;
	for(int i=0;i<N;i++){
		cin >> X[i];
	}
	for(int i=0;i<N-1;i++){
		if(A*(X[i+1]-X[i]) < B) tired += A*(X[i+1]-X[i]);
		else tired += B;
	}
	cout << tired;
	return 0;
}

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

int main() {
  int64_t N,K,Q,tmp;
  cin >> N >> K >> Q;
  vector<int64_t> vec(N+1);
  for(int i = 0; i < Q; i++){
    cin >> tmp;
    vec.at(tmp) += 1;
  }
  for(int i = 1; i <= N; i++){
    if((Q-vec.at(i))<K) cout << "Yes" << endl;
    else cout << "No" << endl;
  }  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
// K - Stones

using namespace std;

int N;
int a[105];
bool dp[100005];

int main() {
    int K,i,j;

    scanf("%d%d",&N,&K);

    for (i = 0;i < N;i++)
        scanf("%d",&a[i]);

    sort(a,a + N);

    for (i = 0;i <= K;i++) {
        for (j = 0;j < N;j++) {
            if (i - a[j] < 0)
                break;

            if (!dp[i - a[j]]) {
                dp[i] = true;
                break;
            }
        }
    }

    if (dp[K])
        printf("First\n");
    else
        printf("Second\n");

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }
    long long sum=0;
    for(int i=1;i<=(n-1);i++)
    {
        sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import heapq
class HeapDict:
    def __init__(self):
        self.h = []
        self.d = {}

    def insert(self,x):
        if x not in self.d or self.d[x] == 0:
            heapq.heappush(self.h, x)
        self.d.setdefault(x,0)
        self.d[x] += 1


    def erase(self,x):
        if x not in self.d or self.d[x] == 0:
            return
        else:
            self.d[x] -= 1

        while self.h:
            if self.d[self.h[0]] == 0:
                heapq.heappop(self.h)
            else:
                break


    def get_min(self):
        if not self.h:
            return None
        else:
            return self.h[0]


    def pop(self):
        poped_val = self.h[0]
        self.erase(poped_val)
        return poped_val


    def exist(self, x):
        return (x in self.d and self.d[x] > 0)


    def show_h(self):
        elems = [v for v in self.h if self.d[v] > 0]
        print(elems)


    def show_d(self):
        print(self.d)



# def main():
n,q = map(int, input().split())
eventl = []

for _ in range(n):
    s,t,x = map(int, input().split())
    eventl.append((s-x, 'a-stop', x)) 
    eventl.append((t-x, 'b-start', x))

for i in range(q):
    d = int(input())
    eventl.append((d,'c-go', i))

eventl.sort()

ans = [0]*q
hd = HeapDict()
for e in eventl:
    if e[1] == 'a-stop':
        hd.insert(e[2])
    elif e[1] == 'b-start':
        hd.erase(e[2])
    else:
        min_x = hd.get_min()
        if min_x is not None:
            ans[e[2]] = min_x
        else:
            ans[e[2]] = -1

for a in ans:
    print(a)


# if __name__ == "__main__":
#     main()

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

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto D = s[0];
    auto G = s[1].to!long;
    auto PC = D.iota.map!(_ => readln.split.map!(to!long).array).array;
    int ans = 1 << 29;

    foreach (mask; 0..(1<<D)) {
        long tmp = 0;
        int cnt = 0;
        foreach (i; 0..D) {
            if (mask & (1 << i)) {
                tmp += PC[i][0] * (i + 1) * 100 + PC[i][1];
                cnt += PC[i][0];
            }
        }
        for (int i = D-1; i >= 0 && tmp < G; --i) {
            if (mask & (1 << i)) continue;
            long hoge = (G - tmp - 1) / ((i + 1) * 100) + 1;
            hoge = min(hoge, PC[i][0]);
            tmp += hoge * (i + 1) * 100;
            cnt += hoge;
        }
        ans = min(ans, cnt);
    }

    ans.writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    vector<int> b(n - 1), a(n);

    REP(i, n - 1) cin >> b[i];

    a[0] = b[0]; a[n - 1] = b[n - 2];

    for (int i = 1; i <= n - 2; i++) {
        a[i] = min(b[i - 1], b[i]);
    }

    ll ans = 0;
    REP(i, n) ans += a[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256