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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> p(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> p[i];
    }
    Int res = 0;
    sort(all(p));
    for (Int i = 0; i < (Int)k; i++) {
        res += p[i];
    }
    print(res);
    return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	#A, B, Q = map(int, input().split(" "))
	n = int(input())
	p = list(input().split(" "))
	
	ans = 0
	for i, val in enumerate(p):
		if i == 0:
			continue
		if i+1 > n-1:
			continue
		fst = int(p[i-1])
		snd = int(p[i])
		srd = int(p[i+1])
		if snd != max(fst,snd,srd) and snd != min(fst,snd,srd):
			ans += 1
	
	
	print(ans)	
	
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3444
#include <iostream>
using namespace std;
constexpr int MOD = 998244353;

template <int N>
struct Eratosthenes
{
    int w[N + 1];
    bool is_not_prime[N + 1];
    constexpr Eratosthenes() : w(), is_not_prime()
    {
        w[0] = 0;
        w[1] = 1;
        for (int i = 2; i <= N; i++)
        {
            w[i] = MOD - 1LL * w[MOD % i] * (MOD / i) % MOD;
        }
        for (int p = 2; p <= N; p++)
        {
            if (!is_not_prime[p])
            {
                for (int k = N / p; k > 1; --k)
                {
                    is_not_prime[k * p] = true;
                    w[k * p] -= w[k];
                    if (w[k * p] < 0)
                    {
                        w[k * p] += MOD;
                    }
                }
                w[p] -= w[1];
            }
        }
    }
};

int main()
{
    constexpr int M = 1000000;
    constexpr auto prime = Eratosthenes<M>();
    long long N, ans = 0;
    int a[1000001] = {};
    cin >> N;
    for (int i = 0, j; i < N; i++)
    {
        cin >> j;
        a[j] += j;
        if (a[j] >= MOD)
        {
            a[j] -= MOD;
        }
        ans -= j;
        if (ans < 0)
        {
            ans += MOD;
        }
    }
    for (int p = 2; p <= M; p++)
        if (!prime.is_not_prime[p])
            for (int k = M / p; k > 0; --k)
                if ((a[k] += a[k * p]) >= MOD)
                    a[k] -= MOD;
    for (int i = 1; i <= M; i++)
    {
        ans += 1LL * a[i] * a[i] % MOD * prime.w[i] % MOD;
    }
    ans %= MOD;
    if (ans & 1)
        ans = (ans + MOD) >> 1;
    else
        ans = ans >> 1;
    cout << ans << endl;
}


Measured memory_bytes: 9596
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define LL long long
#define M 1020
using namespace std;
namespace IO{
	const int BS=(1<<20)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout);}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush(),OS=OT;}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
int n,m,k,tt;
LL s[M],p[M],t[M*M],ans;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),tt=read();
	for(int i=1;i<=n;i++){
		p[i]=read(),s[i]=s[i-1]+p[i];
		for(int j=0;j<i;j++) t[++m]=s[i]-s[j];
	}
	for(int k=60;k>=0;k--){
		int cnt=0;
		for(int i=1;i<=m;i++){
			if((t[i]&ans)==ans&&(t[i]>>k)&1) cnt++;
		}
		if(cnt>=tt) ans|=(1ll<<k);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6400
using System;

namespace AOJ.Volume0
{
    public class WhatIsTheBottommost
    {
        private static string Calc(string input)
        {
            string ret = "";
            if (input.Length == 1) { return input; }
            for (int i = 0; i < input.Length - 1; i++)
            {
                int mod = (int.Parse(input.Substring(i, 1)) + int.Parse(input.Substring(i + 1, 1))) % 10;
                ret += mod.ToString();
            }

            return ret;
        }

        public static void Main()
        {
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                while (input.Length > 1)
                {
                    input = Calc(input);
                }
                Console.WriteLine(input);
            }
        }
    }
}

Measured memory_bytes: 9208
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    rep(i, H) cin >> v[i];

    rep(i, H)
    {
        cout << v[i] << endl;
        cout << v[i] << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define N 3
#define N2 9

struct Puzzle{
	int f[N2];
	int space;
	string path;
	
	bool operator < (const Puzzle &p)const {
		for(int i=0;i < N2;++i){
			if(f[i] == p.f[i]) continue;
			return f[i] > p.f[i];
		}
		return false;
	}
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
	for(int i=0;i < N2;++i)
		if(p.f[i] != (i+1)) return false;
	return true;
}

string bfs(Puzzle s){
	queue<Puzzle> Q;
	map<Puzzle, bool> V;
	Puzzle u, v;
	s.path = "";
	Q.push(s);
	V[s] = true;
	
	while(!Q.empty()){
		u = Q.front(), Q.pop();
		if(isTarget(u)) return u.path;
		int sx = u.space / N;
		int sy = u.space % N;
		for(int r=0;r < 4;++r){
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			v = u;
			swap(v.f[u.space], v.f[tx*N+ty]);
			v.space = tx*N + ty;
			if(!V[v]){
				V[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}
	return "unsolvable";
}

int main(){
	Puzzle in;
	
	for(int i=0;i < N2;++i){
		cin >> in.f[i];
		if(in.f[i] == 0){
			in.f[i] = N2;
			in.space = i;
		}
	}
	string ans = bfs(in);
	cout << ans.size() << endl;
	
	return 0;
}


Measured memory_bytes: 30580
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    unordered_map<string, int> cnt;
    LL ans = 0;
    while (n--) {
        string s; cin >> s;
        sort(s.begin(), s.end());
        cnt[s]++;
        ans += cnt[s] - 1;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 10660
A = []
B = []
for i in range(5):
    x = input()
    if int(x[-1]) != 0:
        A.append(10 - int(x[-1]))
    B.append(int(x))

if A == []:
    print(sum(A) + sum(B))
else:
    print(sum(A) + sum(B) - max(A))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        double A;
        double B;
        double X;


        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextDouble();
            B = sc.nextDouble();
            X = sc.nextDouble();
        }
        double C = X / A;
        double result=0;
        if(C <= ((A*B)/2)){
            double aa = (C /B)*2;
            double bb = B;
            double cc = Math.sqrt((aa*aa) + (bb* bb));
            double radR = Math.acos(aa /cc);

            result = Math.toDegrees(radR);
        }else{
            double bb = (((A*B)-C) /A)*2;
            double aa = A;
            double cc = Math.sqrt((aa*aa) + (bb* bb));
            double radR = Math.acos(aa /cc);

            result = Math.toDegrees(radR);
        }
        System.out.println(result);


    }


}


Measured memory_bytes: 23252
#include<stdio.h>
int main(){
    int n,k,max,min;
    scanf("%d %d",&n,&k);
    if(k==1){
        printf("0\n");
    }
    else{
        if(n<k){
            printf("1\n");
        }
        else if(n==k){
            printf("0\n");
        }
        else{
            if(n%k==0){
                printf("0\n");
            }
            else{
                printf("1\n");
            }
        }
    }
    return 0;
}

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

int main()
{
    int sum, count=0;
    int n, x;
    while(true)
    {   
        count=0;
        cin>>n>>x;
        if((n==0)&&(x==0))break;
        for(int i = 1;i<=n-2;i++)
        {
            for(int j=i+1;j<=n-1;j++)
            {
                for(int k=j+1;k<=n;k++)
                {
                    if((i+j+k)==x)count++;
                }
            }
        }
        cout<<count<<endl;
    }
    return 0;
}


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

using namespace std;

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

typedef modint<1000000007> mint;

mint comb(int n, int m) {
  mint ret = 1;
  n = n - m;
  for (int i = 1; i <= m; i++) {
    ret *= n + i;
    ret /= i;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<int, int> prime;
  prime[2] = 0;
  prime[3] = 0;
  for (int i = 5; i < 1e5; i += 2) {
    bool is = true;
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        is = false;
        break;
      }
    } 
    if (is) {
      prime[i] = 0;
    }
  }
  int n, m;
  cin >> n >> m;
  for (auto p: prime) {
    int num = p.first;
    while (m % num == 0) {
      m /= num;
      prime[num]++;
    }
  }
  if (m != 1) {
    prime[m] = 1;
  }
  mint ans = 1;
  for (auto p: prime) {
    if (p.second == 0) {
      continue;
    }
    ans *= comb(n + p.second - 1, p.second);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
use proconio::input;

fn solve(n: usize, a: &[i64], q: usize, bc: &[(i64, i64)]) -> Vec<i64> {
    let mut freq = vec![0; 100001];
    let mut ans = 0;
    for &x in a {
        ans += x;
        freq[x as usize] += 1;
    }
    let mut r = Vec::new();
    for &(b, c) in bc {
        ans += freq[b as usize] * (c - b);
        freq[c as usize] += freq[b as usize];
        freq[b as usize] = 0;
        r.push(ans);
    }
    r
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
        q: usize,
        bc: [(i64, i64); q],
    }
    let r = solve(n, &a, q, &bc);
    for x in r {
        println!("{}", x);
    }
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  string s;
  cin >> s;
  int l = s.size();
  if(isKai(s) && isKai(s.substr(0, (l - 1) /2))
     && isKai(s.substr((l + 3) / 2 - 1, (l - 1) / 2))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){
    int K, count=9;
    deque<ll> dq;
    cin >> K;
    if (K < 10){
        out(K);
        return 0;
    }
    for (int i=1; i<10; ++i) dq.push_back(i);
    while (K > count) {
        ll v = dq.front();
        dq.pop_front();
        if (v%10 == 0) {
            v *= 10;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);

            v += 1;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);
        } else if(v%10 == 9) {
            v *= 10;
            v += 8;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);

            v += 1;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);
        } else {
            int a = v%10;
            v *= 10;
            v += a-1;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);

            v += 1;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);

            v += 1;
            count++;
            if(count==K){
                out(v);
                return 0;
            }
            dq.push_back(v);
        }
    }
}


Measured memory_bytes: 768
N,M = (int(x) for x in input().split())

A = []
ans = 0
for i in range(N):
    a = [int(x) for x in input().split()]
    a.pop(0)
    A.append(a)

for i in range(M):
    for j in range(N):
        if i+1 not in A[j]:
            ans -= 1
            break
    ans += 1

print(ans)

Measured memory_bytes: 3060
N = gets.to_i
md = 10**5+1
d = gets.split.map(&:to_i).sort
cnt = [0]*(md+1)
ans = 0
md.times do |i|
  cnt[i+1] = cnt[i]
  while (i+1)==d[0]
    cnt[i+1] += 1
    d.shift
  end
  if cnt[i+1] == N/2
    ans += 1
  end
  break if cnt[i+1] > N/2
end
p ans


Measured memory_bytes: 9720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;

    int inp1, inp2, cnt = 0, chk = 0;

    for(int i = 0; i < n; i++){
        cin >> inp1 >> inp2;
        if(inp1 == inp2)
            cnt++;
        else{
            cnt = 0;
        }
        if(cnt == 3){
            chk = 1;
        }
    }

    if(chk == 1)
        cout << "Yes";
    else
        cout << "No";



    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
long long modpow(long long a, long long n, long long mod) { //累乗の余剰
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    rep(i,n)std::cin >> a[i];
    std::vector<int> d(1010,0);
    std::unordered_map<ll,ll> prime;
    rep(j,n){
        int dum=0;
        dum=a[j];
        std::vector<int> dd(1010,0);
        rrep(i,2,1005){
            
            while(dum%i==0){
                dum/=i;
                dd[i]++;
            }
        }
        if(dum!=1){
            auto it=prime.find(dum);
            if(it==prime.end()){
                prime.insert(mp(dum,1));
            }
            
        }
 
        rep(i,1005){
            d[i]=max(d[i],dd[i]);
        }
    }
    ll ans=0ll;
    int cnt=0,cntcnt=0;
    rep(j,n){
        std::vector<int> dd(1005,0);
        int dum=0;
        dum=a[j];
        
        ll ddum=1ll;
        rrep(i,2,1008){
            while(dum%i==0){
                dum/=i;
                dd[i]++;
            }
            
        }
        a[j]=dum;
        rrep(i,2,1003){
            ddum*=modpow(i,ll(d[i]-dd[i]),MOD);
            ddum%=MOD;
            
        }
        
        for(auto i=prime.begin();i!=prime.end();i++){
            ll ddd=0ll;
            if(i->fi==a[j]){
                ddd++;
            }
            //if(ddd)std::cout << a[j]<< " "<<i->fi << std::endl;
            ddum*=modpow(i->fi,i->se-ddd,MOD);
            ddum%=MOD;
        }
        ans+=ddum;
        ans%=MOD;
    }
    //std::cout << cnt <<" "<<cntcnt << std::endl;
    std::cout << ans << std::endl;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int ret = 0;
  for (int i = 1; i <= n; i += 2) {
    int cnt = 0;
    for (int j = 1; j * j <= i; ++j) {
      if (i % j == 0) {
        ++cnt;
        if (j * j != i) ++cnt;
      }
    }
    if (cnt == 8) ++ret;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,M,A[100007],T,K=0,L=0;
  cin >> N >> M;
  rep(i,N){
    cin >> A[i];
    T=A[i];
    K=0;
    while(T%2==0){
      T/=2;
      K++;
    }
    if(i>0){
      if(K!=L){
        cout << 0 << endl;
        return 0;
      }
    }
    else{
      L=K;
    }
  }
  sort(A,A+N);
  reverse(A,A+N);
  ll C=A[0]/2,D=A[0];
  Rep(i,1,N){
    while(C<=M && C%A[i]!=A[i]/2){
      C+=D;
    }
    if(C>M){
      cout << 0 << endl;
      return 0;
    }
    D=lcm(C,D);
  }
  cout << (M-C-1)/D+1 << endl;
}

Measured memory_bytes: 1024
N = int(input())
S = input()

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

Measured memory_bytes: 42268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
		String str = rd.readLine();
	    int n = Integer.parseInt(str);
	    str = rd.readLine();
	    boolean s[] = new boolean[100003];
	    boolean a[] = new boolean[100003];
	    
	    // T => x   F => o 
	    for(int i = 0; i <= 100002; i++)
		{
			s[i] = str.charAt(i % n) == 'x';
		} 
	    
	    a[0] = a[1] = false;
	    for(int i = 1; i <= n + 1; i++)
	    {
	    	a[i + 1] = a[i] ^ s[i] ^ a[i - 1];
	    }  
	    		
	    if(a[0] == a[n] && a[1] == a[n + 1])
	    {
	    	for(int i = 0; i < n; i++)
	    	{
	    		System.out.print(a[i] ? 'W' : 'S');
	    	}
	    	System.exit(0);
	    }
	    
	    a[0] = true;
	    a[1] = false;
	    for(int i = 1; i <= n + 1; i++)
	    {
	    	a[i + 1] = a[i] ^ s[i] ^ a[i - 1];
	    }  
	    		
	    if(a[0] == a[n] && a[1] == a[n + 1])
	    {
	    	for(int i = 0; i < n; i++)
	    	{
	    		System.out.print(a[i] ? 'W' : 'S');
	    	}
	    	System.exit(0);
	    }
	    
	    a[0] = false;
	    a[1] = true;
	    for(int i = 1; i <= n + 1; i++)
	    {
	    	a[i + 1] = a[i] ^ s[i] ^ a[i - 1];
	    }  
	    		
	    if(a[0] == a[n] && a[1] == a[n + 1])
	    {
	    	for(int i = 0; i < n; i++)
	    	{
	    		System.out.print(a[i] ? 'W' : 'S');
	    	}
	    	System.exit(0);
	    }
	    
	    a[0] = a[1] = true;
	    for(int i = 1; i <= n + 1; i++)
	    {
	    	a[i + 1] = a[i] ^ s[i] ^ a[i - 1];
	    }  
	    		
	    if(a[0] == a[n] && a[1] == a[n + 1])
	    {
	    	for(int i = 0; i < n; i++)
	    	{
	    		System.out.print(a[i] ? 'W' : 'S');
	    	}
	    	System.exit(0);
	    }
	    
	    System.out.println(-1);
		
  	}
}

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

S = input()

a, b = 0, 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            a += 1
        else:
            b += 1
    else:
        if S[i] == '1':
            a += 1
        else:
            b += 1
print(min(a, b))

Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, NN;
  cin >> N;
  NN = N * N;

  auto index = [&N](int r, int c) {
    return N * r + c;
  };
  auto idxInv = [&N](int index) {
    return pair<int, int>(index / N, index % N);
  };

  vector<int> ps(NN);
  F0R(i, NN) {
    cin >> ps[i];
    ps[i]--;
    //cout << idxInv(ps[i]).first << ',' << idxInv(ps[i]).second << ' ';
  }

  vector<bool> vs(NN, true);

  vector<int> as(NN);

  F0R(r, N) {
    int rd = min(r, N - r - 1);
    F0R(c, N) {
      int cd = min(c, N - c - 1);
      as[index(r, c)] = min(rd, cd);
    }
  }

  auto print_as = [&]() {

    F0R(r, N) {
      F0R(c, N) {
        cout << as[index(r, c)] << ' ';
      }
      cout << newl;
    }
  };
  //print_as();

  int result = 0;

  F0R(i, NN) {
    int r, c;
    tie(r, c) = idxInv(ps[i]);

    //debug(ps[i] + 1);
    result += as[ps[i]];
    vs[ps[i]] = false;

    queue<tuple<int, int, int>> qu;
    qu.emplace(r, c, as[ps[i]]);
    as[ps[i]]++;

    while (qu.size()) {
      int d;
      tie(r, c, d) = qu.front();
      qu.pop();
      int idx = index(r, c);
      if (d >= as[idx]) continue;
      //cout << "as[" << idx << "] = " << d << newl;
      as[idx] = d;
      if (vs[idx]) d++;

      if (r > 0) qu.emplace(r - 1, c, d);
      if (c > 0) qu.emplace(r, c - 1, d);
      if (r < N - 1) qu.emplace(r + 1, c, d);
      if (c < N - 1) qu.emplace(r, c + 1, d);
    }
    //print_as();
  }
  cout << result;
}
#endif


Measured memory_bytes: 5260
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

int gcd(int a, int b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

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

  A--;
  int l = lcm(C, D);
  int b = B - (B / C) - (B / D) + (B / l);
  int a = A - (A / C) - (A / D) + (A / l);
  cout << b - a << endl;
}

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


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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }






int main() {

int N;
cin >> N;
vector<char>A(N);
REP(i, N){
  string S;
  cin >> S;
  A.at(i) = S.at(0);
}

vector<ll>M(5, 0);

REP(i, N){
  if(A.at(i) == 'M') M.at(0)++;
  if(A.at(i) == 'A') M.at(1)++;
  if(A.at(i) == 'R') M.at(2)++;
  if(A.at(i) == 'C') M.at(3)++;
  if(A.at(i) == 'H') M.at(4)++;
}

ll ans = 0;
REP(i, 5)REP(j, i)REP(k, j){
  ans += M.at(i) * M.at(j) * M.at(k);
}

print(ans);
}


Measured memory_bytes: 384
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    static int[] A = new int[100000];
    static int[] B = new int[101];

    static void update(int i, int x){
        if (A[i] == Integer.MAX_VALUE){
            A[i] = x;
            B[i/1000] = Math.min(x, B[i/1000]);
        }else{
            A[i] = x;
            int min = Integer.MAX_VALUE;
            for (int j = i/1000 * 1000; j < (i/1000 + 1) * 1000; j++){
                if (A[j] < min){
                    min = A[j];
                }
            }
            B[i/1000] = min;
        }
    }
     
    static void find(int s, int t){
        int min = Integer.MAX_VALUE;
        if (s/1000 == t/1000 || s/1000 + 1 == t/1000){
            for (int i = s; i < t + 1; i++){
                if (A[i] < min){
                    min = A[i];
                }
            }            
        }else{
            //left range
            for (int i = s; i < (s/1000 +1)*1000; i++){
                if (A[i] < min){
                    min = A[i];
                }
            }

            for (int j = s/1000 + 1; j < t/1000; j++){
                if (B[j] < min){
                    min = B[j];
                }
            }   
            //right range
            for (int i = (t/1000) * 1000; i < t + 1; i++){
                if (A[i] < min){
                    min = A[i];
                }
            }
        }System.out.println(min);
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int q = Integer.parseInt(line[1]);
        for (int i = 0; i < 100000; i++){
            A[i] = Integer.MAX_VALUE;
        }
        for (int i = 0; i < 101; i++){
            B[i] = Integer.MAX_VALUE;
        }
        for (int k = 0; k < q; k++){
            String[] ln = br.readLine().split(" ");
            int com = Integer.parseInt(ln[0]);
            int x = Integer.parseInt(ln[1]);
            int y = Integer.parseInt(ln[2]);
            if (com == 0){
                update(x,y);
            }else{
                find(x,y);
            }
        }
    }
}    

Measured memory_bytes: 66004
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
  string s;cin>>s;
  int n=s.size();
  int sum=0;
  int mi=0;
  rep(i,0,n){
  	if(s[i]=='S')sum++;
    else sum--;
    mi=min(mi,sum);
  }
  cout<<-mi*2<<endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

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

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

typedef long long ll;

using namespace std;



template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  modint pow(u64 exp){
    modint res=1,rhs=*this;
    while (exp) {
      if (exp % 2) {
        res *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return res;
  }

  friend ostream& operator<<(ostream& os,modint& rhs){
    os << rhs.value();
    return os;
  }

  friend istream& operator>>(istream &is,modint &rhs){
      is>>rhs.value();
      rhs.value()%=Modulus;
      return is;
  }

};

using mint=modint<(int)1e9+7>;
struct factorial{
  vector<mint>fact,inv;
  factorial(int n){
    fact.assign(n,0);
    inv.assign(n,0);
    fact[0]=1;
    for(int i=0;i<n-1;i++){
      fact[i+1]=fact[i]*(i+1);
    }
    inv[n-1]=(mint)1/fact[n-1];
    for(int i=n-1;i>=1;i--){
      inv[i-1]=inv[i]*i;
    }
  }
  mint comb(int a,int b){
    if(b>a||b<0)return 0;
    return fact[a]*inv[b]*inv[a-b];
  }

};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  if(k>=n){
    k=n-1;
  }
  factorial f(n+7);
  mint res=0;
  rep(i,k+1){
    res+=f.comb(n-1,i)*f.comb(n,i);
  }
  cout<<res<<endl;





  return 0;

}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<functional>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j;
	int n,cnt,l,s,flg;
	int a[3];
	while(1) {
		cin >> n;
		if(n==0000) break;
		cnt=0;
		flg=0;
		while(1) {
			if(n==6174) break;
			a[0]=n/1000;
			n=n%1000;
			a[1]=n/100;
			n=n%100;
			a[2]=n/10;
			a[3]=n%10;
			
			if(a[0]==a[1] && a[0]==a[2] && a[0]==a[3]) {cout << "NA" << endl;flg=1;break;}
			sort(a,a+4);
	//		cout << a[0] << a[1] << a[2] << a[3] << endl;
			s=(a[0]*1000)+(a[1]*100)+(a[2]*10)+a[3];
			sort(a,a+4,greater<int>());
			l=(a[0]*1000)+(a[1]*100)+(a[2]*10)+a[3];
	//		cout << a[0] << a[1] << a[2] << a[3] << "==" << l << endl;
			if(l-s==6174) {cnt++;break;}
			else {n=l-s;cnt++;}
		}
		if(flg==0)cout << cnt << endl;
	}
	exit(0);
}
			
	

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

int main(void) {
  int n, l; cin >> n >> l;
  string words[n];
  for (int i = 0; i < n; i++) cin >> words[i];
  sort(words, words + n);
  for (string word: words) cout << word;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define pb push_back
using namespace std;
const int P=1e9+7,N=5010;
int dp[N][N],sz[N],f[N],tmp[N],ans,n,u,v;
vector<int> G[N];
inline void upd(int &x,int y){((x+=y)>=P)&&(x-=P);}
void dfs(int u,int fa){
    dp[u][1]=1;sz[u]=1;
    for(int &v:G[u]) if(v^fa){
        dfs(v,u);
        rep(i,1,sz[u]) rep(j,1,sz[v]){
            int x=1ll*dp[u][i]*dp[v][j]%P;
            upd(tmp[i+j],x);
            upd(tmp[i],P-1ll*f[j]*x%P);
        }sz[u]+=sz[v];
        rep(i,1,sz[u]) dp[u][i]=tmp[i],tmp[i]=0;
    }
}
int main(){
    scanf("%d",&n);
    f[2]=1;rep(i,2,n/2) f[i*2]=1ll*(i*2-1)*f[i*2-2]%P;
    rep(i,1,n-1) scanf("%d%d",&u,&v),G[u].pb(v),G[v].pb(u);
    dfs(1,0);
    rep(i,1,n) upd(ans,1ll*dp[1][i]*f[i]%P);
    printf("%d\n",ans);
    return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005, INF = 0x3f3f3f3f;

int n, T;
int a[N], b[N], p[N];

int f[35];

int main() {
	read(n), read(T);
	for (int i = 1; i <= n; ++i) {
		read(a[i]), read(b[i]);
		++a[i], b[i] += a[i];
		p[i] = i;
	}
	std::sort(p + 1, p + 1 + n, [&](int x, int y) {
		return 1ll * b[x] * (a[y] - 1) < 1ll * b[y] * (a[x] - 1);
	});
	int m = n;
	while (m && a[p[m]] == 1) {
		--m;
	}
	std::sort(p + 1 + m, p + 1 + n, [&](int x, int y) {
		return b[x] < b[y];
	});
	for (int i = 0; i <= 30; ++i) {
		f[i] = INF;
	}
	f[0] = 0;
	for (int i = 1; i <= m; ++i) {
		for (int j = 30; j; --j) {
			f[j] = std::min<long long>(f[j], 1ll * f[j - 1] * a[p[i]] + b[p[i]]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= 30; ++i) {
		int now = f[i];
		int j = m + 1;
		while (j <= n && now + b[p[j]] <= T) {
			now += b[p[j]];
			++j;
		}
		if (now <= T) {
			ans = std::max(ans, i + j - m - 1);
		}
	}
	print(ans);
}


Measured memory_bytes: 10076
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
int main(){
	getline(cin,s1);
	getline(cin,s2);
	sort(s1.begin(),s1.end());
	sort(s2.begin(),s2.end(),greater<char>());
	if(s1<s2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			while(true){
				int m = sc.nextInt(), f = sc.nextInt(), r = sc.nextInt();
				if(m == -1 && f == -1 && r == -1){
					break;
				}
				if(m == -1 || f == -1){
					System.out.println("F");
				}else if(m + f >= 80){
					System.out.println("A");
				}else if(m + f >= 65){
					System.out.println("B");
				}else if(m + f >= 50){
					System.out.println("C");
				}else if(m + f >= 30){
					if(r >= 50){
						System.out.println("C");
					}else{
						System.out.println("D");
					}
				}else{
					System.out.println("F");
				}
			}
		}
	}
}


Measured memory_bytes: 26140
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int a,b;
  cin >>a >> b;
  if(b%a==0){
    cout << a+b << endl;
  }
  else{
    cout << b-a << endl;
  }
}
  

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

from collections import Counter
C = Counter(A)
#print(C)

M = max(A)
X = [0]*(M+1)
for i in A:
    j = i*2
    while j <= M:
        X[j] = 1
        j += i
#print(X)

ans = 0
for a in A:
    if C[a] == 1 and X[a] != 1:
        ans += 1
print(ans)


Measured memory_bytes: 126444
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		List<String> S = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			S.add(in.readLine());
		}
		Map<String, Integer> counts = new HashMap<>();
		for (String s : S) {
			String sorted = sortStr(s);
			if (counts.containsKey(sorted)) {
				counts.put(sorted, counts.get(sorted) + 1);
			} else {
				counts.put(sorted, 1);
			}
		}
		long result = 0;
		for (Integer num : counts.values()) {
			if (num > 1) {
				result += count(num);
			}
		}
		System.out.println(result);

	}

	static String sortStr(String s) {
		char[] c = s.toCharArray();
		Arrays.sort(c);
		return new String(c);
	}

	static long count(int val) {
		long result = (long) (val - 1);
		for (int i = val - 2; i >= 1; --i) {
			result += (long) i;
		}
		return result;
	}
}

Measured memory_bytes: 50648
n = int(input())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

ans = 0
for i in range(n):
    if x[i] == y[i]:
        ans += 1
        if ans == 3:
            print("Yes")
            break
    
    else:
        ans = 0
        

if ans == 0 or ans == 1 or ans == 2:
    print("No")




Measured memory_bytes: 9176
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define N 1000

long long xx[N], yy[N], zz[N], xx_[N], yy_[N], zz_[N];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;
	long long diff = xx_[j] + yy_[j] + zz_[j] - xx_[i] - yy_[i] - zz_[i];

	return diff < 0 ? -1 : 1;
}

int main() {
	static int ii[N];
	int n, m, i, b, f1, f2, f3;
	long long a, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%lld%lld%lld", &xx[i], &yy[i], &zz[i]);
	ans = 0;
	for (b = 0; b < 8; b++) {
		f1 = b & 1;
		f2 = b & 2;
		f3 = b & 4;
		for (i = 0; i < n; i++) {
			xx_[i] = f1 ? -xx[i] : xx[i];
			yy_[i] = f2 ? -yy[i] : yy[i];
			zz_[i] = f3 ? -zz[i] : zz[i];
			ii[i] = i;
		}
		qsort(ii, n, sizeof *ii, compare);
		a = 0;
		for (i = 0; i < m; i++)
			a += xx_[ii[i]] + yy_[ii[i]] + zz_[ii[i]];
		if (ans < a)
			ans = a;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	fast;
	int n,m;
	cin >> n >> m;
	int s,c;
	if(n==1 && m==0){
		cout<<"0";
		return 0;
	}
	vector<int>v(n,0);
	vector<int>arr(n,0);
	for(int i = 0 ; i < m ; i ++ ){
		cin >> s >> c;
		s--;
		if(v[s]!=0 && arr[s]!=c){
			cout<<"-1";
			return 0;
		}
		v[s] = 1;
		arr[s] = c;
	}
	string res = "";
	if(v[0]==0){
		arr[0]=1;
	}
	for(int i = 0 ; i < n ; i++ ){
		res+=arr[i]+'0';
	}
	if(res.size()!=n || (res[0]=='0' && n!=1)){
		cout<<"-1";
		return 0;
	}
	cout<<res;
	return 0;
}




Measured memory_bytes: 256