akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef pair<lint,lint>pll;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int DEBUG=0;


const int N=62;
const lint inf=1LL<<61;
pll dpa[N],dpb[N];

pll mul(pll a,lint b){
  return pll(a.first*b,a.second+1);
}

pll rev(pll a){
  return pll(a.first,-a.second);
}

const int PUL=0;


int main(){
  int n;
  cin>>n;
  vector<lint>a(n);
  if(PUL){
    rep(i,n)a[i]=-2;
  }else{
    rep(i,n)cin>>a[i];
  }
  rep(i,N){
    dpa[i]=pll(-inf,1);
    dpb[i]=pll(inf,-1);
  }
  dpa[n]=dpb[n]=pll(1,0);
  for(int i=n-1;i>=0;--i){
    for(int j=i+1;j<=n;++j){
      dpa[i]=max(dpa[i],max(rev(mul(rev(dpa[j]),a[i])),rev(mul(dpb[j],a[i]))));
      dpb[i]=min(dpb[i],min(mul(rev(dpa[j]),a[i]),mul(dpb[j],a[i])));
    }
    if(DEBUG){
      cerr<<"dpa["<<i<<"]="<<dpa[i].first<<" "<<dpa[i].second<<endl;
      cerr<<"dpb["<<i<<"]="<<dpb[i].first<<" "<<dpb[i].second<<endl;
    }
  }
  pll ma=pll(-inf,1);
  rep(i,n+1)ma=max(ma,dpa[i]);
  pll idx(inf,inf);
  rep(i,n+1){
    if(ma.first==dpa[i].first){
      idx=min(idx,pll(-dpa[i].second,i));
    }
  }
  int cur=idx.second;
  int rem=-ma.second;
  pll val=rev(ma);
  vi ans;
  while(rem>0){
    if(DEBUG){
      cerr<<"cur="<<cur<<endl;
      cerr<<"rem="<<rem<<endl;
      cerr<<"val="<<val.first<<" "<<val.second<<endl;
    }
    int nxt=-1;
    for(int j=cur+1;j<=n;++j){
      if(mul(dpb[j],a[cur])==val){
	nxt=j;
	val=dpb[j];
	break;
      }
      if(mul(rev(dpa[j]),a[cur])==val){
	nxt=j;
	val=rev(dpa[j]);
	break;
      }
    }
    ans.push_back(cur);
    cur=nxt;
    rem--;
  }
  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<ans[i]+1<<endl;
  }
}



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

int main()
{
	string s;
	cin >> s;
	int nagasa = s.length();
	for (int i = 0; i < nagasa - 8; i++) {
		cout << s[i];
	}
	cout << endl;

	return 0;
}

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

int main()
{
    ll a;
    cin >> a;
    cout << a * a * a << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const int inf = 1 << 30;
map<char,int>mp;
map<char,int>::iterator it;
const int maxn = 1e5;
bool ans = true;
int main(){
	string a;
	int k;
	cin >> a >> k;
	int l = a.size();
	for(int i = 0;i<l;i++){
		if(k==0) break;
		if(a[i]=='a') continue;
		if('z'-a[i]+1<=k){
			k-='z'-a[i]+1;
			a[i] = 'a';
		}
	}
	if(a[l-1]+k > 'z')	a[l-1] = 'a'+(k-('z'-a[l-1]+1))%26;
	else a[l-1] = a[l-1] + k;
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		int k = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		
		if (n > k) {
			System.out.println(k * x + (n - k) * y);
		} else {
			System.out.println(x * n);
		}
	}
}

Measured memory_bytes: 20820
N,K=map(int,input().split())

ans=0
b=0

def ho(a,K):
    for za in range(0,10000):
        if a*2**za>=K:
            break
    return za

for i in range(1,N+1):
    jo=ho(i,K)
    b=(1/N) *(1/2)**jo
    ans=ans+b
    b=0

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using s64 = signed long long;
using u64 = unsigned long long;
using f128 = long double;

int main()
{
    s64 x, k, d;
    cin >> x >> k >> d;

    if(x < 0)
    {
        x *= -1;
    }

    s64 stepCount = x / d;
    if(stepCount >= k)
    {
        cout << abs(x - d * k) << endl;
        return 0;
    }

    s64 minX = x - d * stepCount;
    s64 leftStep = k - stepCount;
    if(leftStep % 2 == 0)
    {
        cout << abs(minX) << endl;
    }
    else
    {
        cout << abs(minX - d) << endl;
    }

    return 0;
}


Measured memory_bytes: 3640
// Noic - Semana 50 - Avançado
// Complexidade: O(N*V)

#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 110;
const int maxv = 1e5+10; // maior resposta possível

int w[maxn], v[maxn];
 
int dp[maxn][maxv];
 
int main(void)
{
	int n, W;
	cin >> n >> W;
 
	for (int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];
 	
 	// Casos Base
	for (int i = 0; i <= n; i++)
	{
		dp[i][0] = 0;
		for (int j = 1; j < maxv; j++)
			dp[i][j] = W+1; // por enquanto, daremos um valor grande
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j < maxv; j++)
		{
			// precisamos checar se é possível usar v[i]
			if (j >= v[i]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
			else dp[i][j] = dp[i-1][j];
		}
	}
 
	int ans = 0;
	for (int i = 1; i < maxv; i++)
		if (dp[n][i] <= W) ans = i;
 
	cout << ans << "\n";
}

Measured memory_bytes: 41216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

constexpr int M = 16*2;
using mat = array<array<mint,M>,M>;


mat mult(mat& A,mat& B){
    mat C{};
    for(int i=0;i<M;i++) for(int k=0;k<M;k++) for(int j=0;j<M;j++) C[i][j] += A[i][k]*B[k][j];
    return C;
}

mat pow(mat& A,ll n){
    if(n==1) return A;
    mat R = pow(A,n>>1);
    R = mult(R,R);
    if(n&1) R = mult(R,A);
    return R;
}

void solve(){
    int N;
    cin >> N;
    if(N<=4){
        cout << 0 << "\n";
        return ;
    }
    mat A{};
    for(int i=0;i<M;i++){
        if(i%2==0){
            //仕切りを入れる
            for(int j=i+2;j<M;j+=2) A[j+1][i] += 1;
            //ボールを入れる
            A[i+1][i] += 1;
        }else{
            //仕切りを入れる
            if(i>=10) for(int j=i+2;j<M;j+=2) A[j][i] += 1;
            //ボールを入れる
            A[i-1][i] += 1;
        }
    }
    mat res = pow(A,N-4);
    mint ans = 0;
    cout << res[M-2][0]+res[M-1][0] << "\n";
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        solve();
    }
}

Measured memory_bytes: 4164
#![allow(dead_code)]

// This file is a "Hello, world!" in Rust language for wandbox.
use std::process;


fn main()
{
    let nums: usize = read(); // 10000, 5000, 1000
    
	let str: String = read();
  	
  	if str.len() <= nums {
      println!("{}", str);
  } else {
  	println!("{}...", &str[0..nums]);
  }
  
}
    
// Rust language references:
//   https://www.rust-lang.org/
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_n<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}


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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int a[m][2];
    
    rep(i, m){
        cin >> a[i][0] >> a[i][1];
      --a[i][0];--a[i][1];
    }
    
    int ans = 0;
    
    rep(i, m){
        
        UnionFind tree(n);
        rep(j, m){
        if(j != i)tree.unite(a[j][0], a[j][1]); // xの木とyの木を併合する
        }

         rep(k, n-1){
            if(tree.same(k, n-1) == false){
            ++ans;
            break;
            }
        }
    }
    
    cout<< ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    long long k;
    int n;
    char s[105];
    cin>>s>>k;
    n=strlen(s);
    int i=0;
    while(s[i]=='1')
        i++;
    if(k<=i)
        cout<<1<<endl;
    else
    {
        cout<<s[i]-'0'<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib> 
#include <ctime>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
	string s; int n;
	cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		printf("%c", 'A' + ((s[i] + n - 'A') % 26));
	}
	cout << endl;
}

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

using namespace std;

#define ll long long
#define PI acos(-1.0)

ll dp[110][105005];
int n, w, weight[105], cost[105];

ll func(int indx, int curr)
{
    if(indx > n) return 0;
    if(dp[indx][curr] != -1) return dp[indx][curr];
    ll ans1 = 0, ans2 = 0;
    if(curr+weight[indx] <= w)
    {
		ans1 = cost[indx] + func(indx+1,curr+weight[indx]);
	}	
	ans2 = func(indx+1,curr);
	return dp[indx][curr] = max(ans1,ans2);
}

int main()
{	
	scanf("%d %d", &n, &w);
	for(int i =1 ; i <= n; i++) scanf("%d %d", &weight[i],&cost[i]);
	memset(dp,-1,sizeof(dp));
	ll ans = func(1,0);
	printf("%lld\n",ans);
	
	return 0;
}


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

typedef std::pair<int, int> pi;
std::priority_queue<pi, std::vector<pi>, std::greater<pi> > q;
const int MAXN = 510 * 510;
int n, A[MAXN], B[MAXN];
std::vector<pi> add[MAXN];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, t; i <= n; ++i) {
		std::cin >> t; B[i] = t;
		for (int j = 1; j < i; ++j) add[1].emplace_back(t - 1, i);
		add[t].emplace_back(t, i);
		for (int j = i + 1; j <= n; ++j) add[t + 1].emplace_back(n * n, i);
	}
	for (int i = 1; i <= n * n; ++i) {
		for (auto t : add[i]) q.push(t);
		if (q.empty() || q.top().first < i)
			return std::cout << "No" << std::endl, 0;
		A[i] = q.top().second; q.pop();
	}
	std::cout << "Yes" << std::endl;
	for (int i = 1; i <= n * n; ++i)
		std::cout << A[i] << (" \n" [i == n * n]);
	return 0;
}


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

int main() {
  int K, A, B; cin >> K >> A >> B;
  string result = "NG";
  for (int i = A; i <= B; i++) {
    if (i%K == 0) result = "OK";
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
 int n;
 int ans, sum = 0;
 
 cin >> n;
 char s[n];
 
 for(int i = 0; i < n; i++){
     cin >> s[i];
 }

 for(int i = 0; i < n; i++){
     if(s[i] != s[i+1]){
         sum++;
     }
 }

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


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

signed main() {
  stack<int> st;
  string s;
  while ( cin >> s ) {
    if ( s == "+" ) {
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a+b);      
    } else if ( s == "-" ) {
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(b-a);      
    } else if ( s == "*" ) {
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a*b);      
    } else {
      st.push(stoi(s));      
    }
  }

  cout << st.top() << endl;
  
  return 0;
}



Measured memory_bytes: 3188
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main() {

  string s; cin >> s;
  if( s[0] == s[2] ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int count(int x) {
	if (!x) return 0;
	return x%10+count(x/10);
}

void solve() {
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	long long ans = 0;
	for (int i = 1; i <= n; ++i) {
		int c = count(i);
		if (a <= c && c <= b) ans += i;
	}
	printf("%lld", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    int ind = 0;
    for (int i = 0; i < N; i++) {
        if(h[i] != 0){
            ind = i;
            break;
        }
    }
    int tmp;
    int check;
    for (int cx = 0; cx < 101; cx++) {
        for (int cy = 0; cy < 101; cy++) {
            tmp = h[ind] + abs(cx - x[ind]) + abs(cy - y[ind]);
            check = true;
            for (int i = 0; i < N; i++) {
                if(i == ind) continue;    
                if(h[i] == 0){
                    if(abs(cx - x[i]) + abs(cy - y[i]) < tmp){
                        check = false;
                    }
                }
                else{
                    if(h[i] + abs(cx - x[i]) + abs(cy - y[i]) != tmp){
                        check = false;
                    }
                }
            }
            if(check){
                printf("%d %d %d\n", cx, cy, tmp);
                return 0;
            }
        }
    }

}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int sum=0,a;
	string s;
	stringstream ss;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		ss<<s.substr(i,1);
		ss>>a;
		sum+=a;
		ss.clear();
	}
	ss<<s;
	ss>>a;
	if(a%sum)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int MN = 200005;

int N, M, A[MN];

inline bool check(int x) {
	int l = 1, r = M;
	for (int i = N; i > 1; --i)
		if ((A[i] >= x) == (A[i - 1] >= x)) { l = i; break; }
	for (int i = N; i < M; ++i)
		if ((A[i] >= x) == (A[i + 1] >= x)) { r = i; break; }
	if (l == 1 && r == M) return (A[N] >= x) ^ (~N & 1);
	return N - l <= r - N ? A[l] >= x : A[r] >= x;
}

int main() {
	scanf("%d", &N), M = 2 * N - 1;
	for (int i = 1; i <= M; ++i) scanf("%d", &A[i]);
	int l = 3, r = M - 1, mid, ans = 2;
	while (l <= r) {
		mid = (l + r) / 2;
		if (check(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2468
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<typename T> void debug_out(string name, T arg) { cerr<<name<<"="<<arg<<endl; }
template<typename T1, typename... T2> void debug_out(string name, T1 arg, T2... args) {
    cerr<<name.substr(0, name.find(','))<<"="<<arg<<", ";
    debug_out(name.substr(name.find(',') + 1), args...); }
#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion



int main() {
    FASTIO

    double d; cin>>d;
    cout<<d*2*M_PI<<endl;

}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll l,r; cin>>l>>r;
  
  ll ans=LINF;
  for(ll i=l; i<=min(l+2019, r); i++){
    for(ll j=i+1; j<=min(l+2019, r); j++){
      chmin(ans, i*j%2019);
    }
  }
  cout<<ans<<endl;
  
}

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

int main(){

  int n;
  cin >> n;

  int l = n % 10;

  if(l == 3) cout << "bon";
  else if(l == 0 || l == 1 || l == 6 || l == 8) cout << "pon";
  else cout << "hon";
  cout << endl;

  return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	auto kaibun = [&] (string t) {
		string r = t;
		reverse(t.begin(), t.end());
		return (t == r);
	};
	int n = s.size();
	bool a, b, c;
	a = kaibun(s);
	b = kaibun(s.substr(0,n / 2));
	c = kaibun(s.substr(n - (n / 2), n / 2));
	if (a && b && c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3552
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {   
    double r, g; cin >> r >> g;
    cout << 2*g-r << ln;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;

lli small(lli a, lli b, lli c) {
	lli l = min(a, b); l = min(l, c);
	lli r = max(a, b); r = max(r, c);
	lli ans = r - l;
	return ans;
}

lli split(lli x, lli y) {
	lli m = 10000000000;
	lli A, B, C;
	rep(i, 1, x / 2 + 1) {
		A = i * y;
		B = (x - i)*(y / 2);
		C = (x - i)*(y - y / 2);
		m = min(m, small(A, B, C)); //cout << m << endl;
		lli j = x - i;
		A = i * y;
		B = j / 2 * y;
		C = (j - j / 2)*y;
		m = min(m, small(A, B, C));
	}

	return m;
}

int main(void)
{
	lli H, W; cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0)cout << 0 << endl;
	else {
		cout << min(split(H, W), split(W, H)) << endl;

	}

	return 0;
}


Measured memory_bytes: 256
n, k = map(int,input().split())
s = input()
ans = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    ans += 1
for i in range(k):
  if ans < n-2:
    ans += 2
  elif ans == n-2:
    ans += 1
  else:
    pass
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL<<60;

int dp[30];

void solve(int n) {
    dp[0] = 1;

    for (int i = 1; i <= n; i++) {
        dp[i] += dp[i-1];
        if (i > 1) dp[i] += dp[i-2];
        if (i > 2) dp[i] += dp[i-3];
    }

    int day = (dp[n]+9)/10;
    int ans = (day+364)/365;
    cout << ans << endl;
}

int main() {
    while (true) {
        memset(dp, 0, sizeof(dp));
        int n; cin >> n;
        if (n) solve(n);
        else break;
    }

    return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
int W, H, x, y, r; 
cin >> W >> H >> x >> y >> r; 
if(x >= 0 && x <= W - r && y >= 0 && y <= H-r)
  cout << "Yes" << endl;  
else
  cout << "No" << endl;  
}


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

int n,m,k;
int mapp[15][15];
int r[10]={0};
int c[10]={0};
int vr[10]={0};
int vc[10]={0};
int cnt1,cnt2;
vector<int>q1[100005];
vector<int>q2[100005];
void dfs1(int a,int b){
	if(a>b){
		for(int i=1;i<=a;i++){
			if(vr[i]==1){
				q1[cnt1].push_back(i);
			}
		}
		cnt1++;
		return;
	}
	vr[a]=1;
	dfs1(a+1,b);
	vr[a]=0;
	dfs1(a+1,b);
	return;
}
void dfs2(int a,int b){
	if(a>b){
		for(int i=1;i<=a;i++){
			if(vc[i]==1){
				q2[cnt2].push_back(i);
			}
		}
		cnt2++;
		return;
	}
	vc[a]=1;
	dfs2(a+1,b);
	vc[a]=0;
	dfs2(a+1,b);
	return;
}

int main()
{
	cin>>n>>m>>k;
	int sum=0;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		for(int j=0;j<m;j++){
			if(s[j]=='#'){
				mapp[i][j+1]=1;
				r[i]++;
				c[j+1]++;
				sum++;
			}
			else {
				mapp[i][j+1]=0;
			}
		}
	}
	cnt1=cnt2=1;
	dfs1(1,n);
	dfs2(1,m);
	int sum3=0;
	for(int i=1;i<cnt1;i++){
		int sum1=0;
		for(int j=0;j<q1[i].size();j++){
			sum1+=r[q1[i][j]];
		}
		for(int j=1;j<cnt2;j++){
			int sum2=0;
			for(int k2=0;k2<q2[j].size();k2++){
				sum2+=c[q2[j][k2]];
				for(int k1=0;k1<q1[i].size();k1++){
					sum2-=mapp[q1[i][k1]][q2[j][k2]];
				}
			}
			if(sum1+sum2+k==sum){
//				for(int k1=0;k1<q1[i].size();k1++){
//					cout<<q1[i][k1]<<" ";
//				}
//				cout<<endl;
//				for(int k2=0;k2<q2[j].size();k2++){
//					cout<<q2[j][k2]<<" ";
//				}
//				cout<<endl;
				sum3++;
			}
		}
	}
	cout<<sum3<<endl;
	return 0;
}

Measured memory_bytes: 8332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACirclePond solver = new ACirclePond();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACirclePond {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {

            out.println(in.readDouble() * 2 * Math.PI);
        }

    }

    static class FastScanner {
        private StringTokenizer st;
        private BufferedReader in;

        public FastScanner(final InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

        public String readToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public double readDouble() {
            return Double.parseDouble(readToken());
        }

    }
}



Measured memory_bytes: 33376
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        a: u8,
        b: u8
    };
    println!(
        "{}",
        ["Impossible", "Possible"][((a % 3 == 0) || (b % 3 == 0) || ((a + b) % 3 == 0)) as usize]
    );
}


Measured memory_bytes: 2096
#include<stdio.h>
int main(){
	int i,n,a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=n-1;i>=0;i--){
		printf("%d",a[i]);
		if(i!=0)printf(" ");
		else printf("\n");
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////


typedef pair <int, int> P;
 
const ll MOD=1000000007;
 
ll power(ll x, ll k, ll p){
    if (k==0) return 1;
    else if (k==1) return x%p;
	ll res = power(x, k / 2, p);
	if (k%2==0) return (res * res)%p;
    else return (res * res % p * x)%p;
}
 
ll dp[2][1010];
 
void solve() {
    ll N, M;
    cin >> N >>M;
    
    if (M==1){
        cout << 1<< endl;
    }
    else {
        int a=0;
        ll b=2;
        while (b<=100010){
            if (M%b==0){
                dp[0][a]=b;
                while (M%b==0){
                    M/=b;
                    dp[1][a]++;
                }
                a++;
            }
            b++;
        }
		if(M != 1) {
			dp[0][a] = M;
			dp[1][a] = 1;
			a++;
		}
        ll ans=1;
        if (a==0){
            cout << N << endl;
        }
        else {
            rep(i, 0, a){
                ll p=1;
                ll q=1;
                for (ll j=N ;j< dp[1][i]+N; j++){
                    p*=j;
                    p%=MOD;
                }
                for(ll j=1; j<dp[1][i]+1; j++){
                    q*=j;
                    q%=MOD;
                }
                ans*=(p*power(q, MOD-2, MOD)) % MOD;
                ans%=MOD;
            }
            cout << ans << endl;
        }
    }
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
  int n;
  cin>>n;
  int counter=0;
  if(n>81)
    cout<<"No"<<endl;
  else
  {
    for(int i=1;i<10;i++)
    {
      int a=n%i;
      int b=n/i;
      if(a==0&&b<10)
      {
        cout<<"Yes"<<endl;
        counter++;
        break;
      }
    }
    if(counter==0)
      cout<<"No"<<endl;
  }
}

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

using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        vec[i]=x;
    }
    sort(vec.begin(),vec.end());
    int m=n/2;
    cout << vec[m]-vec[m-1]<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    int64_t n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());

    int64_t h = 0;
    int64_t w = 0;
    for(int i = n-1; i > 0; i--){
        if(a[i] == a[i-1]){
            if(h == 0){
                h = a[i];
                i--;
            }
            else if(w == 0){
                w = a[i];
                break;
            }
        }
    }
    int64_t ans = h*w;
    cout << ans << endl;
}


Measured memory_bytes: 640
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back;
#define X first;
#define Y second;
#define pii pair<int,int>;
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int n,a[maxn];
int main(){
	migmig;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >>a[i];
	}
	int cnt=1;
	int mx=a[0];
	for(int i=1;i<n;i++){
		if(a[i] >= mx){
			cnt++;
			mx=a[i];
		}
	}
	cout<<cnt;
	return 0;
}



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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  for (int _ = 2; _--; ) {
    if (s != string(rbegin(s), rend(s))) {
      cout << "No\n";
      exit(0);
    }
    s.resize((n - 1) / 2);
  }
  cout << "Yes\n";
}


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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 998244353;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll MOD (ll a) {
    if (a < 0)
        a += mod;
    return (a % mod);
}

ll POWER (ll a, ll n) {
    if (n == 0)
        return 1;
    if (n == 1)
        return a;
    if (n & 1) {
        ll ans = MOD (POWER (a, (n-1)/2));
        ans = MOD (ans * ans);
        ans = MOD (ans * a);
        return ans;
    }
    else {
        ll ans = MOD (POWER (a, n/2));
        ans = MOD (ans * ans);
        return ans;
    }
}
//Ordered set
//pbds s1
ll n, m, k;
ll fact[200006];
ll invfact[200006];

ll go (ll alpha) {
    //cout << "YO:" << alpha << endl;
    ll ans = 0;
    ans = MOD (m*MOD(POWER(m-1, alpha-1)));
    ll val = MOD (fact[n-1]*MOD(invfact[alpha-1]*invfact[n-alpha]));
   // cout << "YO:" << val << endl;
    ans = MOD (ans * val);
    return ans;
}

void testCase() {
    cin >> n >> m >> k;
    fact[0] = 1;
    invfact[0] = MOD (POWER(fact[0], mod-2));
    for (int i=1; i<=n; i++) {
        fact[i] = MOD (fact[i-1]*i);
        invfact[i] = MOD (POWER (fact[i], mod-2));
    }
    ll ans = 0;
    ll alpha = n-k;
    alpha = max (1ll, alpha); 
    while (alpha <= n) {
        ans = MOD (ans + go(alpha));
        alpha++;
    }
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 6768
#include<iostream>
#include<bitset>
using namespace std;
int main(){
    string a="AKIHABARA",s,c;
    cin>>s;
    for(int i=0;i<16;i++){
        bitset<4>b(i);
        c=a;
        for(int i=3;i>=0;i--)if(!b[i])c.erase(c.begin()+(i?2*i+2:0));
        if(s==c){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
    return 0;
}

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

int main()
{
  string S;
  cin >> S;
  int N = S.size();
  int64_t ans = 0;
  for (int bit = 0; bit < (1 << (N - 1)); bit++)
  {
    int64_t s = 0, tmp = 0;
    tmp += (int)(S.at(0) - '0');
    for (int i = 0; i < N - 1; i++)
    {
      if (bit & (1 << i))
      {
        s += tmp;
        tmp = 0;
      }
      tmp *= 10;
      tmp += (int)(S.at(i + 1) - '0');
    }
    ans += (s + tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    vector<pair<ll,ll>> jobs;
    rep(i,n){
        int a, b; cin >> a >> b;
        jobs.push_back(make_pair(b,a));
    }
    sort(ALL(jobs));
    ll now = 0;
    bool can = true;
    rep(i,n){
        now += jobs[i].second;
        if(jobs[i].first < now) can = false;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    ll sum = 0;
    rep(i,n){
        sum+=a[i];
    }
    ll ans = INF;
    ll sum1 = 0;
    rep(i,n-1){
        sum1+=a[i];
        ans = min(ans,abs(sum-sum1*2));
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
signed main() {
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	int mi = a, ma = a;
	for (int h = 1; h <= n; h++) {
		if (mi - ((n - h) * d) <= b && b <= ma - ((n - h) * c)) {
			cout << "YES" << endl; return 0;
		}
		mi += c; ma += d;
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

ll MOD = 998244353;
ll F[300010];
ll I[300010];

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b % 2) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b /= 2;
    }
    return res;
}

void init() {
    F[0] = 1;
    for (int i = 1;i <= 300000;i++) {
        F[i] = (F[i - 1] * i) % MOD;
    }
    I[300000] = power(F[300000], MOD - 2);
    for (int i = 299999;i >= 0;i--) {
        I[i] = (I[i + 1] * (i + 1)) % MOD;
    }
    return;
}

ll nchoosek(ll a, ll b) {
    ll d = (I[b] * I[a - b]) % MOD;
    return (F[a] * d) % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    init();
    ll res = 0;
    int N;
    ll A, B, K;
    cin >> N >> A >> B >> K;
    for (int i = 0;i <= N;i++) {
        if (A * i > K) continue;
        if ((K - A * i) % B != 0) continue;
        ll num = (K - A * i) / B;
        if (num > N) continue;
        res += (nchoosek(N, i) * nchoosek(N, num)) % MOD;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i, x, y) for(register int i = x; i <= y; ++i)
#define repd(i, x, y) for(register int i = x; i >= y; --i)
#define repl(i, x) for(register int i = fi[x]; i; i = l[i].next)
using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, a[maxn];
multiset<int> s;
int read(){
	int num = 0, flag = 1; char c = getchar();
	for(; c < '0' || c > '9'; c = getchar())
		if(c == '-') flag = 0;
	for(; c >= '0' && c <= '9'; c = getchar())
		num = (num<<3)+(num<<1)+c-48;
	return flag? num: -num;
}

bool mycmp(int x, int y){
	return x > y;
}

void init(){
	n = read();
	rep(i, 1, n) a[i] = read();
}

void work(){
	int ans = 0;
	rep(i, 1, n) s.insert(a[i]);
	while(!s.empty()){
		int x = *s.rbegin(); s.erase(s.find(x));
//		printf("%d:\n", x);
		for(int i = 1; (1LL<<i) <= 2*x; ++i){
			if((1LL<<i) < x) continue;
			int y = (1LL<<i)-x;
			set<int>::iterator z = s.lower_bound(y);
			if(z == s.end()) continue;
			if(*z == y){
//				printf("%d\n", y);
				++ans;
				s.erase(z);
				break;
			}
		}
	}
	printf("%d\n", ans);
}

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	init();
	work();
	return 0;
}

Measured memory_bytes: 10368
if __name__ == "__main__":
    s = input()
    t = input()

    s_num = list()
    t_num = list()

    for ss in s:
        s_num.append(ord(ss))
    for tt in t:
        t_num.append(ord(tt))

    s_num.sort()
    t_num.sort(reverse=True)

    s_str = ''
    t_str = ''
    for ss in s_num:
        s_str += chr(ss)
    for tt in t_num:
        t_str += chr(tt)

    if s_str == t_str:
        print('No')
    elif min([s_str, t_str]) == s_str:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    string s; 
    while(cin >> s){
        int joi = 0, ioi = 0;
        for (int i = 0; i < s.size()-2; i++){
            if (s[i] == 'J' && s[i+1] == 'O' && s[i+2] == 'I'){
                joi++;
            } else if (s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I'){
                ioi++;
            }
        }
        cout << joi << endl << ioi << endl;
    }
}


Measured memory_bytes: 3172
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a >= 3200){
		cout<<s<<endl;
	}else{
		cout<<"red"<<endl;
	}

}

Measured memory_bytes: 3588
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  int n;
  cin >> n;
  cout << n/3 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;


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

  string city[N];
  int P[N];
  int ID[N];


  for(int i = 0; i < N; i++){
    string data_city;
    int data_P;

    cin >> data_city >> data_P;

    city[i] = data_city;
    P[i] = data_P;
    ID[i] = i+1;
  }

  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      string Citytmp;
      int Ptmp;
      int itmp;
      if(city[i] > city[j]){
        Citytmp =  city[i];
        city[i] = city[j];
        city[j] = Citytmp;

        Ptmp =  P[i];
        P[i] = P[j];
        P[j] = Ptmp;

        itmp =  ID[i];
        ID[i] = ID[j];
        ID[j] = itmp;
      }
      if(city[i] == city[j]){
        if(P[i] < P[j]){
          Citytmp =  city[i];
          city[i] = city[j];
          city[j] = Citytmp;

          Ptmp =  P[i];
          P[i] = P[j];
          P[j] = Ptmp;

          itmp =  ID[i];
          ID[i] = ID[j];
          ID[j] = itmp;
        }
      }
    }
  }

  cout << endl;
  for(int i = 0; i < N; i++){
    cout << ID[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector<int>is[1000005];
int h[205],a[100005],b[100005],c[100005];;
vector<P1>edge[1000005];
int par[205],ran[205];
void init(){ for(int i=0;i<205;i++) par[i] = i,ran[i] = 0; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }
int p[100005];
bool cmp(const int &a,const int &b){
	return c[a] < c[b];
}
int main(){
	while(1){
		cin >> n >> m;
		if(!n) return 0;
		rep(i,1000005) is[i].clear();
		rep(i,1000005) edge[i].clear();
		for(int i=1;i<=n;i++){
			cin >> h[i];
			is[h[i]].pb(i);
		}
		init();
		for(int i=1;i<=m;i++){
			//int a,b,c;
			cin >> a[i] >> b[i] >> c[i]; p[i] = i;
			edge[h[a[i]]].pb(mp(c[i],mp(a[i],b[i])));
			edge[h[b[i]]].pb(mp(c[i],mp(b[i],a[i])));
			unite(a[i],b[i]);
		}
		int C = 0;
		for(int i=1;i<=n;i++) if(find(i)==i) C++;
		if(C>=2){
			puts("0"); continue;
		}
		sort(p+1,p+m+1,cmp);
		rep(i,1000005){
			SORT(edge[i]);
		}
		init();
		int cnt = 0,ret = 0,sum = 0;
		for(int i=1000000;i>=1;i--){
			for(int k=0;k<edge[i].size();k++){
				int x = edge[i][k].sc.fi;
				if(h[edge[i][k].sc.sc] >= i && !same(edge[i][k].sc.sc,x)){
					unite(edge[i][k].sc.sc,x);
					cnt++; ret += edge[i][k].fi;
				}
			}
			sum += is[i].size();
			if(sum && cnt != sum-1){
				cnt = 0; ret = 0; init();
				if(i!=1){
					for(int x=1;x<=m;x++){
						int k = p[x];
						if(h[a[k]] >= i-1 && h[b[k]] >= i-1 && !same(a[k],b[k])){
							unite(a[k],b[k]);cnt++;ret+=c[k];
						}
					}
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 55144
def gcd(a,b):
  if a*b == 0:
    return max(a,b)
  if a<b:
    a,b = b,a
  return gcd(b,a%b)
n = int(input())
ls = list(map(int,input().split()))
length = 2**(n.bit_length())
calc = gcd
unit = 0
Seg = [unit for i in range(length*2-1)]
def init():
  for i in range(n):
    Seg[i+length-1] = ls[i]
  for i in range(length-2,-1,-1):
    Seg[i] = calc(Seg[2*i+1],Seg[2*i+2])
def update(i,x):
  i += length-1
  Seg[i] = x
  while i>0:
    i = (i-1)//2
    Seg[i] = calc(Seg[2*i+1],Seg[2*i+2])
def query(a,b,k,l,r):
  if r<=a or b<=l:
    return unit
  if a<=l and r<=b:
    return Seg[k]
  else:
    vl = query(a,b,2*k+1,l,(l+r)//2)
    vr = query(a,b,2*k+2,(l+r)//2,r)
    return calc(vl,vr)

init()
ans = []
for i in range(n):
  ans.append(gcd(query(0,i,0,0,length),query(i+1,n,0,0,length)))
print(max(ans))

Measured memory_bytes: 121880