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

// @@ !! LIM(binsearch)
// --> binsearch
// ---- inserted library file binsearch.cc

template<typename T>
T binsearch(auto check, T yes, T no, T err = (T)1) {
  while (abs(yes - no) > err) {
    T mid = (yes + no) / (T)2;
    if (check(mid)) yes = mid;
    else            no  = mid;
  }
  return yes;
}

// ---- end binsearch.cc
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  ll n = S.size();
  
  auto check = [&](ll k) -> bool {
    assert(k >= 1);
    ll rmax = k;
    ll rmin = 0;
    ll eo = 0;
    /*
    auto incmax = [&]() -> void { if (++rmax > k) rmax -= 2; };
    auto decmin = [&]() -> void { if (--rmin < 0) rmin += 2; };
    */
    for (ll i = 0; i < n; i++) {
      if (S[i] == '1') {
	if (rmin == k) return false;
	else if (rmin == k - 1) {
	  rmax = rmin = k;
	  eo = 1;
	}else {
	  if (rmax < k) rmax++;
	  else if (eo) rmax--;
	  rmin++;
	}
      }else if (S[i] == '0') {
	if (rmax == 0) return false;
	else if (rmax == 1) {
	  rmax = rmin = 0;
	  eo = 1;
	}else {
	  if (rmin > 0) rmin--;
	  else if (eo) rmin++;
	  rmax--;
	}
      }else {
	if (eo) {
	  if (rmax == k) rmax = k - 1;
	  else rmax++;
	  if (rmin == 0) rmin = 1;
	  else rmin--;
	}else {
	  if (rmax < k) rmax++;
	  if (rmin > 0) rmin--;
	}
      }
      // DLOG("i=", i, "rmax=", rmax, "rmin=", rmin);
    }
    return true;
  };

  ll x = binsearch<ll>(check, n, 0);
  cout << x << endl;

  return 0;
}



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


Measured memory_bytes: 5592
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    long long int n,ans=0,i,j,k;
    cin>>n;
    long long int a[n+1][n+1];
    bool p[n+1][n+1];
    memset(p,0,sizeof(p));
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                if(a[i][j]==a[i][k]+a[k][j]&&k!=j&&k!=i)
                    p[i][j]=1;
                if(a[i][j]>a[i][k]+a[k][j]){
                    cout<<"-1"<<endl;
                    return 0;
                }
            }
        }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            ans+=p[i][j]==0?a[i][j]:0;
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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(int argc, char const *argv[]) {
  ll n,k;
  cin >>  n >> k;
  vector<ll> a(n),f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(all(a));
  sort(all(f));
  reverse(all(f));
  ll l = -1, r = 1e12;
    while(l+1 < r){
        ll c = (l+r) / 2;
        ll sum = 0;
        rep(i,n)sum += max(0ll, (a[i] - c/f[i]));
        if(sum <= k)r = c;
        else l = c;
    }
  cout << r << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
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;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}


ll dp[100010][3];


int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; ++i){
        int a, b, c; cin >> a >> b >> c;
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a;
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + b;
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + c;
    }
    cout << accumulate(dp[n], dp[n]+3, 3, [](ll acc, ll x) {return max(acc, x);}) << '\n';

    
    
    return 0;
}


Measured memory_bytes: 3840
/*  ex9_2
    L40S38  */
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char cube;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char *cube){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->cube = *cube;
    new->next = *first;
    *first = new;
    return;
}

//スタックからデータを取り出す
void pop(node **first){
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return;
}



int main(void){
    //キューブが積まれている順番を格納
    char cubes[MAX+1],*ptr;
    scanf("%s",cubes);
    ptr=&cubes[0];
    //最初のノードの指す先
    node *first = NULL;
    int count=0;
    //while構文を使ってスタックの中身を操作
    while(*ptr){
        //先にキューブを一旦乗せる
        push(&first,ptr);
        if(first->next != NULL && first->next->cube!=*ptr){
            //違う色が隣り合わせになるときはスタックから2つのキューブを取り出す
            pop(&first);
            pop(&first);
            count+=2;
        }
        ptr++;
    }
    //結果の出力
    printf("%d\n",count);
    return 0;
}

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

const int INF = (1 << 30) - 1;

inline void chmin(int &a, int b) { a = min(a, b); }

int main()
{
	int dp[4][256];

	int N;
	int dat[4];
	int L[10];
	int bit_cnt[256] = {};
	int bit_size[256] = {};

	fill_n(*dp, 1024, INF);
	dp[0][0] = 0;
	
	cin >> N >> dat[0] >> dat[1] >> dat[2];

	for ( int i = 0; i < N; i++ ) cin >> L[i];

	for ( int i = 0; i < (1 << N); i++ ) {
		for ( int j = 0; j < N; j++ ) {
			if ( (i >> j) & 1 ) {
				bit_cnt[i]++;
				bit_size[i] += L[j];
			}
		}
	}

	for ( int i = 0; i < 3; i++ ) {
		for ( int j = 0; j < (1 << N); j++ ) {
			if ( dp[i][j] != INF ) {
				for ( int k = 1; k < (1 << N); k++ ) {
					if ( (j | k) == j + k ) {
						chmin(dp[i + 1][j | k], dp[i][j] + (bit_cnt[k] - 1) * 10 + abs(bit_size[k] - dat[i]));
					}
				}
			}
		}
	}

	int minv = INF;

	for ( int i = 0; i < (1 << N); i++ ) {
		minv = min(minv, dp[3][i]);
	}

	cout << minv << endl;

	return ( 0 );
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int N, M;
set<int> adg[MAX];
set<int> sz[MAX];
int from[MAX];

void print(int from, int to) {
    cout << from+1 << " " << to+1 << "\n";
}

void solve() {
    if (M%2 == 1) {
        cout << -1 << endl;
        return;
    }

    REP (i, N) sz[adg[i].size()].insert(i);
    assert(sz[0].size() == 0);

    int idx = 1;
    while (sz[0].size() < N) {
        while (sz[idx].size() == 0) idx++;
        auto itn = sz[idx].begin();
        int n = *itn;
        sz[idx].erase(n);
        sz[0].insert(n);
        if (from[n]%2 == 1) {
            auto itm = adg[n].begin();
            int m = *itm, cnt = adg[m].size();
            print(n, m);
            from[n]++;
            sz[cnt].erase(sz[cnt].find(m));
            sz[cnt-1].insert(m);
            adg[n].erase(itm);
            adg[m].erase(adg[m].find(n));
        }
        for (auto it = adg[n].begin(); it != adg[n].end(); it++) {
            int m = *it, cnt = adg[m].size();
            print(m, n);
            from[m]++;
            sz[cnt].erase(sz[cnt].find(m));
            sz[cnt-1].insert(m);
            adg[n].erase(it);
            adg[m].erase(adg[m].find(n));
        }
        idx = max(1, idx-1);
    }

    assert(sz[0].size() == N);
}

int main() {
    cin >> N >> M;
    REP (i, M) {
        int a, b; cin >> a >> b; a--; b--;
        adg[a].insert(b);
        adg[b].insert(a);
    }
    solve();
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	int ans=0;
	while(A!=0&&K!=0){
	  ans++;
	  A--;
	  K--;
	}
	
	while(B!=0&&K!=0){
	  B--;
	  K--;
	}
	
	while(C!=0&&K!=0){
	  ans--;
	  C--;
	  K--;
	}

    cout<<ans<<endl;
}



Measured memory_bytes: 3624
N,Q = map(int,input().split())
S = input()
T = [0]*(N+1)
for i in range(N):
    T[i+1] = T[i] + (1 if S[i : i + 2] == "AC" else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(T[r-1] - T[l-1])

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

# A,B,C,X,Yを取得
a, b, c, x, y = map(int, input().split())

price = 0
if a + b <= 2 * c:
    price = (a * x) + (b * y)
else:
    num_ab = min(x, y)
    price = 2 * c * num_ab

    if x > y:
        price += (x - y) * min(a, 2 * c)
    elif x < y:
        price += (y - x) * min(b, 2 * c)

# 結果を出力
print("{}".format(price))


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

using namespace std;

#define rep(i) for(int i = 0; i < 4; i++)
long MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    long dp[101][4][4][4];
    rep(i) rep(j) rep(k) dp[3][i][j][k] = 1;
    dp[3][0][2][1] = 0;
    dp[3][2][0][1] = 0;
    dp[3][0][1][2] = 0;

    for (int m = 4; m <= n; m++){
        rep(i) rep(j) rep(k){
            dp[m][i][j][k] = 0;
            if (i == 0 && j == 2 && k == 1) continue;     // AGC
            else if (i == 2 && j == 0 && k == 1) continue;  // GAC
            else if (i == 0 && j == 1 && k == 2) continue;  // ACG
            else{
                rep(l) dp[m][i][j][k] += dp[m-1][l][i][j];
                if (i == 2 && k == 1) dp[m][i][j][k] -= dp[m-1][0][i][j]; // AG?C
                else if (j == 2 && k == 1) dp[m][i][j][k] -= dp[m-1][0][i][j]; // A?GC
                dp[m][i][j][k] %= MOD;
            }
        }
    }
    long ans = 0;
    rep(i) rep(j) rep(k){
        ans += dp[n][i][j][k];
        ans %= MOD;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 888
a = list(map(int, input().split()))
a.sort()
if (a[2] * 2 - (a[1]+a[0])) % 2 == 0:
  print((a[2]*3 - sum(a)) // 2)
else:
  print(((a[2]+1)*3 - sum(a)) // 2)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
      cout.precision(10);
      cout << fixed;
   }
} iofix;

void solve(){
     int64_t X; cin >> X;
     if(X >= 400 && X <= 599)
          cout << 8 ;
     else if (X >= 600 && X <= 799)
          cout << 7;
     else if(X >= 800 && X <= 999)
          cout << 6 ;
     else if (X >= 1000 && X <= 1199)
          cout << 5; 
     else if(X >= 1200 && X <= 1399)
          cout << 4 ;
     else if (X >= 1400 && X <= 1599)
          cout << 3; 
     else if(X >= 1600 && X <= 1799)
          cout << 2 ;
     else if (X >= 1800 && X <= 1999)
          cout << 1;       
}

int main(){

   	solve();

#ifndef Time
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}

Measured memory_bytes: 3828
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

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

        int n = sc.nextInt();
        long ans = 0;
        int FirstPutValue = 1;
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        for (int i = 0; i < n; i++ ) {
            String s = sc.next();
            char[] chars = s.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);

            if (map.containsKey(key)) {
                int value = map.get(key);
                ans += value;
                map.put(key, value + 1);
            } else {
                map.put(key, FirstPutValue);
            }
        }

        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 53860
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int i=0;
    cin>>s;
    int coun=0,ans=0;
    while(i<s.size()){
        if((s[i]=='A')||(s[i]=='T')||(s[i]=='G')||(s[i]=='C')){

            coun++;
            //cout<<i<<" "<<coun<<endl;
            i++;
        }
        else{
            //cout<<i<<" "<<coun<<endl;
            ans=max(ans,coun);
            coun=0;
            i++;
        }
    }
    cout<<max(ans,coun);
    return 0;
}


Measured memory_bytes: 256
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_until<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {break;}
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
}
fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}

fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let s:i32 = r.read_until();
    let w:i32 = r.read_until();
    println!("{}", if s <= w {
        "unsafe"
    }else{
        "safe"
    });
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll A,B,C; cin >> A >> B >> C;

    ll ans = 0;
    ans += min(B,C);
    B -= ans;
    C -= ans;
    ans += ans;
    if(C){
        ll t = min(C,A);
        ans += t;
        C -= t;
    }

    if(C){
        ans++;
    }

    if(B) ans += B;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 1e6 + 5, M = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    a[i+1] = (s[i] == 'g' ? 1 : -1) + a[i];
  }
  int k = n, ans = 0;
  for (int i = n; i >= 1; i--) {
//cout << a[i] << ' ' << k << ' ' << s[i-1] << '\n';
    if (!k) break;
    if (a[i] < 2) break;
    if (s[i-1] == 'g') {
      ans++;
      k--;
      k = min(k, (a[i] - 2) / 2);
    }
  }
  cout << ans;
}


Measured memory_bytes: 3816
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	while(1){
		scanf("%d", &n);
		if (n == 0) break;
		vector<int>t, h;
		for (int i=0; i<n; i++){
			int tmp;
			scanf("%d", &tmp);
			t.push_back(tmp);
		}
		for (int i=0; i<2*n; i++){
			bool find = false;
			for (int j=0; j<n; j++){
				if (t[j] == i+1){
					find = true;
				}
			}
			if (find == false){
				h.push_back(i+1);
			}
			find = false;
		}
		sort(t.begin(), t.end());
		sort(h.begin(), h.end());
		int b = 0;
		bool td = false;
		bool hd = false;
		while(1){
			for (int i=0; i<t.size(); i++){
				if (t[i] > b){
					b = t[i];
					t.erase(t.begin() + i);
					td = true;
					break;
				}
			}
			if (td == false){
				b = 0;
			}
			td = false;
			if (t.size() == 0) break;
			for (int i=0; i<h.size(); i++){
				if (h[i] > b){
					b = h[i];
					h.erase(h.begin() + i);
					hd = true;
					break;
				}
			}
			if (hd == false){
				b = 0;
			}
			hd = false;
			if (h.size() == 0) break;
		}
		int ts = h.size();
		int hs = t.size();
		printf("%d\n%d\n", ts, hs);
	}

	return 0;
}

Measured memory_bytes: 1060
using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            String first_input;
            List<String> result = new List<String>();
            do
            {
                first_input = Console.ReadLine();
                string[] first_input_arr = first_input.Split(' ');
                int t = int.Parse(first_input_arr[0]);
                int p = int.Parse(first_input_arr[1]);
                int r = int.Parse(first_input_arr[2]);

                int[] correct = new int[t];
                int[,] error = new int[t,p];
                int[] score = new int[t];

                for(int i = 0; i< r; i++)
                {
                    string[] input_arr = Console.ReadLine().Trim().Split(' ');
                    int tid = int.Parse(input_arr[0]) - 1;
                    int pid = int.Parse(input_arr[1]) - 1;
                    int time = int.Parse(input_arr[2]);
                    string message = input_arr[3];

                    if(message == "CORRECT")
                    {
                        correct[tid]++;
                        score[tid] += time;
                        score[tid] += 1200 * error[tid, pid];
                    }
                    else if(message == "WRONG")
                    {
                        error[tid, pid]++;
                    }
                }
                int max = -1;
                int team = 0;

                for (int i = 0; i< t; i++)
                {
                    max = -1;
                    team = 0;
                    for(int j = 0; j< t; j++)
                    {
                        if(correct[j] > max)
                        {
                            team = j;
                            max = correct[j];
                        }
                        else if(correct[j] == max)
                        {
                            if(score[j] < score[team])
                            {
                                team = j;
                            }
                        }

                    }
                    
                    result.Add((team+1) + " " + correct[team] + " " + score[team]);
                    correct[team] = -1;
                    score[team] = -1;                    
                }
            } while (first_input != "0 0 0");

            foreach (String s in result) Console.WriteLine(s);
            
        }
    }
}

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

def f(s, t):
  set_s = set()
  set_t = set()
  for i in s:
    set_s.add(i)
  for i in t:
    set_t.add(i)
  return len( set_s & set_t )

ans = 0
for i in range(1,N):
  s = S[i:]
  t = S[:i]
  ans = max(ans, f(s ,t))
print(ans)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll n;
	cin>>n;
	vec ans(n+1,0);
	floop(i,1,101)
	{
		floop(j,1,101)
		{
			floop(k,1,101)
			{
				ll temp=p(i+j,2)+p(j+k,2)+p(i+k,2);
				if(temp<=2*n )
				ans[temp/2]+=1;				
			}
		}
	}
	floop(i,1,n+1)
	cout<<ans[i]<<"\n";
	//cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3544
#include <cstdio>
#include <map>
using namespace std;
int main(){
  int N;
  scanf("%d", &N)+1;
  map<char, char> mcc;
  char tmp;
  for (int i = 0; i < N+1; i++) {
    scanf("%c", &tmp)+1;
    mcc[tmp]++;
  }

  if (mcc['R'] > mcc['B']) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

struct Dice{
  int n[6];
  void roll(char c){
    int nn;
    if(c == 'E'){
      nn = n[0];
      n[0] = n[3];
      n[3] = n[5];
      n[5] = n[2];
      n[2] = nn;
    }else if(c == 'W'){
      nn = n[0];
      n[0] = n[2];
      n[2] = n[5];
      n[5] = n[3];
      n[3] = nn;
    }else if(c == 'N'){
      nn = n[0];
      n[0] = n[1];
      n[1] = n[5];
      n[5] = n[4];
      n[4] = nn;
    }else if(c == 'S'){
      nn = n[0];
      n[0] = n[4];
      n[4] = n[5];
      n[5] = n[1];
      n[1] = nn;
    }
    return;
  }
  void print(){
    cout << n[0] << endl;
    return;
  }
};


int main(){
  Dice d;
  for(int i = 0; i < 6; i++) cin >> d.n[i];
  string s; cin >> s;
  for(int i = 0; i < s.size(); i++){
    d.roll(s[i]);
  }
  d.print();
  return 0;
}



Measured memory_bytes: 3164
import Data.List
import Control.Applicative
import Control.Monad.Writer

main = do
  getLine
  input <- map read . words <$> getContents
  mapM_ putStrLn $ solve $ input

solve :: [Int] -> [String]
solve xs = let (_:ys) = snd $ runWriter (isort ([], xs)) in ys

debug :: ([Int], [Int]) -> String
debug (xs, ys) = intercalate " " $ map show (reverse xs ++ ys)

isort :: ([Int], [Int]) -> Writer [String] ([Int], [Int])
isort (xs, []) = do
  tell [debug (xs, [])]
  return (xs, [])
isort (xs, y:ys) = do
  tell [debug (xs, y:ys)]
  isort (insert' y xs, ys)

insert' :: Int -> [Int] -> [Int]
insert' x [] = [x]
insert' x (y:ys)
  | x < y = y:insert' x ys
  | otherwise = x:y:ys



Measured memory_bytes: 4064
n,m,c = map(int,input().split(" "))
b = list(map(int,input().split(" ")))
ac = 0
for i in range(n):
  a = list(map(int,input().split(" ")))
  answer = c
  for i in range(m):
    answer += a[i]*b[i]
  if answer > 0:
    ac += 1
print(ac)

Measured memory_bytes: 3064
n;g[9][9];a;b;z;c;
f(x,y){++*g[x],z+=c==n;for(y=n;y;--y)g[x][y]&!*g[y]?++c,f(y),--c:0;--*g[x];}
main(){
	for(;~scanf("%d%d",&a,&b);n=n?:a)g[a][b]=g[b][a]=!!n;
	f(c=1);
	printf("%d",z);
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
 
#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
    const int MOD = (int)(1e9) + 7;
    const double PI = acos(-1);
    const double EPS = 1e-9;
    template <class T> bool chmax(T &a, const T &b) {
          if (a < b) {
                  a = b;
                      return true;
                        }
            return false;
    }
template <class T> bool chmin(T &a, const T &b) {
      if (a > b) {
              a = b;
                  return true;
                    }
        return false;
}
signed main() {
      cin.tie(0);
      ios::sync_with_stdio(false);
      cout << fixed << setprecision(12);


      vector<int>v(3);
      cin>>v[0]>>v[1]>>v[2];
      sort(all(v));
      int odd=0;
      int ans=0;
      rep(i,0,3)
          if(v[i]&1)odd++;

      if(odd==0 or odd==3){
          ans+=(v[2]-v[0]+v[2]-v[1])/2;
      }
      else if(odd==1){
          rep(i,0,3)if(v[i]%2==0){
              v[i]++;
          }
              ans++;
          ans+=(v[2]-v[0]+v[2]-v[1])/2;

      }
      else if(odd==2){
          rep(i,0,3)if(v[i]%2==1){
              v[i]++;
          }
              ans++;
          ans+=(v[2]-v[0]+v[2]-v[1])/2;
      }

      cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int w, h,a[1000],b[1000];
	cin >> w >> h;
	for (int i = 0; i < w; ++i) cin >> a[i];
	sort(a, a + w);
	for (int i = 0; i < h; ++i) cin >> b[i];
	sort(b, b + h);
	for (int i = h - 1; i > ~0; --i) {
		for (int j = 1; j <= b[i]; ++j) {
			a[w - j] -= 1;
		}
		sort(a, a + w);
	}
	cout << (a[0] < 0 ? "0" : "1") << endl;
	return 0;
}


Measured memory_bytes: 3156
<?php

fscanf(STDIN, "%d %d", $h, $w);
$map = [];
for ($i = 0; $i < $h; $i++) {
    $map[] = str_split(trim(fgets(STDIN)));
}

$flg = true;
for ($r = 0; $r < $h; $r++) {
    for ($c = 0; $c < $w; $c++) {
        if ($map[$r][$c] == '#') {
            if (dfs($r, $c) == 1) {
                $flg = false;
                break;
            }
        }
    }
}

echo $flg ? 'Yes' : 'No', PHP_EOL;

function dfs($r, $c) {
    global $map, $h, $w;
    $map[$r][$c] = '.';
    $cnt = 1;

    $mps = [
        [1, 0],
        [-1, 0],
        [0, 1],
        [0, -1],
    ];
    foreach ($mps as $mp) {
        $nr = $r + $mp[0];
        $nc = $c + $mp[1];

        if ($nc < 0 || $nc > $w - 1) continue;
        if ($nr < 0 || $nr > $h - 1) continue;
        if ($map[$nr][$nc] != '#') continue;

        $cnt += dfs($nr, $nc);
    }

    return $cnt;
}


Measured memory_bytes: 6776
#include <stdio.h>
#include <stdlib.h>
#define D 365
typedef long long ll;
int main() {
	srand(628);
	scanf("%*d");
	int c[26], s[D][26];
	int t[D] = {0};
	int bestLasts[D][26] = {0};
	ll bestSats[D] = {0};
	for (int i = 0; i < 26; i++) {
		scanf("%d", &c[i]);
	}
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", &s[i][j]);
		}
	}
	for (int i = 0; i < D; i++) {
		t[i] = rand() % 26 + 1;
	}
	for (int i = 0; i < D; i++) {
		if (i != 0) {
			bestSats[i] = bestSats[i - 1];
		}
		bestSats[i] += s[i][t[i] - 1];
		if (i != 0) {
			for (int j = 0; j < 26; j++) {
				bestLasts[i][j] = bestLasts[i - 1][j];
			}
		}
		bestLasts[i][t[i] - 1] = i + 1;
		for (int j = 0; j < 26; j++) {
			bestSats[i] -= (c[j] * (i + 1 - bestLasts[i][j]));
		}
	}

	for (int cnt = 0; cnt < 200000; cnt++) {
		int tmpt[D];
		int tmpLasts[D] = {0};
		ll tmpSats[D] = {0};
		int pos = rand() % D;
		int type = rand() % 26 + 1;
		for (int i = 0; i < D; i++) {
			tmpt[i] = t[i];
			tmpSats[i] = bestSats[i];
			tmpLasts[i] = bestLasts[type - 1][type - 1];
		}
		tmpt[pos] = type;
		tmpSats[pos] += s[pos][type - 1];
		tmpSats[pos] -= s[pos][t[pos] - 1];
		tmpLasts[pos] = pos + 1;
		for (int i = pos + 1; i < D; i++) {
			if (i != 0) {
				tmpLasts[i] = tmpLasts[i - 1];
			}
			if (tmpt[i] == type - 1) {
				tmpLasts[i] = i + 1;
			}
		}
		for (int i = pos + 1; i < D; i++) {
			if (i != 0) {
				tmpSats[i] = tmpSats[i - 1];
			}
			if (tmpt[i] == type - 1) {
				tmpSats[i] += (c[type] * (i + 1 - bestLasts[i][type - 1]));
				tmpSats[i] -= (c[type] * (i + 1 - tmpLasts[i]));
			}
		}
		if (tmpSats[D - 1] > bestSats[D - 1]) {
			for (int i = 0; i < D; i++) {
				bestSats[i] = tmpSats[i];
				bestLasts[i][type - 1] = tmpLasts[i];
			}
			t[pos] = tmpt[pos];
		}
	}
	// printf("%lld\n", bestSats[D - 1]);

	for (int i = 0; i < D; i++) {
		printf("%d\n", t[i]);
	}
	return 0;
}

Measured memory_bytes: 1816
def sum_digits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n = n // 10
    return sum


n, a, b = map(int, input().split())
s = [0]*5
ans = 0
for i in range(n+1):
    temp = sum_digits(i)
    if a <= temp and temp <= b:
        ans += i
print(ans)

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x, n;
	cin >> x >> n;
	int p[n];
	bool vis[202] = {0};
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		vis[p[i]] = true;
	}
	int ans1, ans2;
	for (int i = x; i <= x + 101; i++) {
		if (i < 0 || !vis[i]) {
			ans1 = i;
			break;
		}
	}
	for (int i = x; i >= x - 101; i--) {
		if (i < 0 || !vis[i]) {
			ans2 = i;
			break;
		}
	}
	if (x - ans2 <= ans1 - x) {
		cout << ans2 << "\n";
	}
	else {
		cout << ans1 << "\n";
	}
 	return 0;
}

Measured memory_bytes: 3604
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
/*void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}*/

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	int max=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<max-1)
		{
			cout<<"No";
			return 0;
		}
		if(a[i]>max)
		max=a[i];
	}
	cout<<"Yes";
	return 0;
}











Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    bool ht[10]={false};
    for(int i=0;i<10;i++)
    {
        int x;
        cin>>x;
        ht[x]=true;
    }
    for(int i=0;i<=10*n;i++)
    {
        if(i>=n)
        {
        bool checked=true;
        string S=to_string(i); ////it doesnt work here try online compile
        for(int j=0;j<S.size();j++)
        {
            if(ht[S[j]-'0'])
            {
                checked=false;
            }
        }
        if(checked)
        {
            cout<<i<<endl;
            return 0;
        }
        }
    }

}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Fr(i,a,b) for(int i=(a);i<=(int)(b);++i)
#define Dr(i,a,b) for(int i=(a);i>=(int)(b);--i)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
#define bug(x) cout<<#x<<'='<<x<<" "
#define debug(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
const int M=2e5+5,Mo=1e9+7;
int n,c1[M],col[M];
int pre[M];
void init(){
	cin>>n;
	Fr(i,1,n)scanf("%d",&c1[i]);
	int ct=0;
	Fr(i,1,n)if(c1[i]!=c1[i-1])col[++ct]=c1[i];
	n=ct;
}
int las[M],nxt[M],dp[M];
int dfs(int x){
	if(x>n)return 1;
	if(~dp[x])return dp[x];
	int s=0;
	if(nxt[x]&&nxt[x]!=x+1)s+=dfs(nxt[x]);
	s+=dfs(x+1);
	s%=Mo;
	return dp[x]=s;
}
int main() {
	memset(dp,-1,sizeof(dp));
	init();
	Fr(i,1,n){
		nxt[las[col[i]]]=i;
		las[col[i]]=i;
	}
	cout<<dfs(1)<<endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S, T;
    cin >> S >> T;

    vector<vector<ll>> index(26, vector<ll>((ll)S.size(), -1));

    rep(i, S.size()) {
        index[(ll)(S[i] - 'a')][i] = i;
    }
    rep(i, 26) {
        ll place = -1;
        rep(j, S.size()) {
            if (index[i][j] != -1) {
                place = index[i][j];
                break;
            }
        }
        if (place == -1) continue;
        for (ll j = (ll)S.size() - 1; j >= 0; j--) {
            if (index[i][j] != -1) {
                place = index[i][j];
            }
            else index[i][j] = place;
        }
    }

    /*
    rep(i, 26) {
        cout << "i : " << (char)('a' + i) << endl;
        rep(j, S.size()) {
            cout << index[i][j] << endl;
        }
    }
    */

    ll cnt = 0, ans;
    ll now = -1;
    ll next;
    rep(i, T.size()) {
        if (now == (ll)S.size() - 1) next = index[(ll)(T[i] - 'a')][0];
        else next = index[(ll)(T[i] - 'a')][now + 1];
        if (next == -1) {
            cout << -1 << endl;
            return 0;
        }
        if (now >= next) {
            cnt++;
        }
        //cout << now << " " << next << " " << cnt << endl;
        now = next;
    }

    ans = cnt * (ll)S.size();
    ans += (next + 1);

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

Measured memory_bytes: 21760
#include <stdio.h>

int main(void){

  char o[51];
  char e[51];
	scanf("%s", o);
  scanf("%s", e);
  int end;
	for (int i = 0; i < 51; i++) {
    if (e[i] < 'a' || e[i] > 'z') {
      end = i-1;
      break;
    }
    printf("%c%c", o[i], e[i]);
  }
  if (o[end+1] >= 'a' && o[end+1] <= 'z') {
    printf("%c", o[end+1]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
# Header {{{
def assert(p)
  raise 'Assertion Failed' unless p
end

# Constants {{{
INF = 10**9
# }}}

# IO {{{
class MyIO
  def initialize
    @input = $stdin
    @output = $stdout
  end

  # @param filename [String]
  def set_input(filename)
    @input = File.open(filename, 'r')
  end

  def set_output(filename)
    @output = File.open(filename, 'w')
  end

  def intl
    splitl.map(&:to_i)
  end

  def splitl
    @input.gets.chomp.split(' ')
  end

  def gets
    @input.gets.chomp
  end

  def puts(*args)
    @output.puts(*args)
  end
end

io = MyIO.new
# }}}

def lower_bound(arr, val)
  assert(arr.is_a?(Array))
  low, high = 0, arr.size
  while high - low > 1
    mid = (low + high) / 2
    if arr[mid] < val
      low = mid
    else
      high = mid
    end
  end
  if arr[low] >= val
    low
  else
    high
  end
end

def upper_bound(arr, val)
  assert(arr.is_a?(Array))
  low, high = 0, arr.size
  while high - low > 1
    mid = (low + high) / 2
    if arr[mid] <= val
      low = mid
    else
      high = mid
    end
  end
  if arr[low] > val
    low
  else
    high
  end
end

# }}}

# io.set_input('inputs/4.txt')

MOD = 1_000_000_007

n, t = io.intl
levels = []
n.times do
  levels << io.gets.to_i
end
levels.sort!

ans = 1
1.upto(n-1) do |i|
  # insert levels[i] before one of levels[0...i]
  min_v = levels[i] - t
  lower, upper = lower_bound(levels[0...i], min_v), upper_bound(levels[0...i], min_v)
  ans = ans * (i - lower + 1) % MOD
end
puts ans

# vim: foldmethod=marker

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> grid(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> grid.at(i).at(j);
    }
  }
  
  vector<int> row(H);
  vector<int> col(W);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (grid.at(i).at(j) == '#') {
        row.at(i) = 1;
        col.at(j) = 1;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    bool rowflag = false;
    for (int j = 0; j < W; j++) {
      if (row.at(i) == 1 && col.at(j) == 1) {
        cout << grid.at(i).at(j);
        rowflag = true;
      }
    }
    if (rowflag) {
      cout << endl;
    }
  }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int a[100005];
int main()
{

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int res=0,tmp=0;
    for(int i=1;i<n;i++){
        if(a[i]<=a[i-1]){
            tmp++;
            res=max(res,tmp);
        }else{
        tmp=0;
        }
    }
    cout<<res<<endl;
//    int n;
//    cin>>n;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,x[105];
signed main() {
	cin>>N;
	rep(i,N)cin>>x[i];
	int ans=inf;
	rep(i,101){
		int sum=0;
		rep(j,N){
			sum+=(x[j]-i)*(x[j]-i);
		}
		chmin(ans,sum);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    int n; cin>>n;
    vector<int> ind[1<<20];
    int a[500005], s[500005];
    s[0]=0;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        s[i]=(s[i-1]^a[i]);
        ind[s[i]].push_back(i);
    }
    ll zct[500005]={};
    for(auto x:ind[0]) zct[x]++;
    for(int i=1; i<=n; i++) zct[i]+=zct[i-1];
    ll ans=0;
    if(s[n]==0){
        for(int i=1; i<(1<<20); i++){
            if(ind[i].empty()) continue;
            ll dp=1, sdp=1, sdpp=zct[ind[i][0]];
            for(int j=1; j<ind[i].size(); j++){
                dp=sdp*zct[ind[i][j]]+1+MOD-sdpp;
                dp%=MOD;
                sdp+=dp;
                sdp%=MOD;
                sdpp+=zct[ind[i][j]]*dp;
                sdpp%=MOD;
            }
            ans+=sdp;
            ans%=MOD;
        }
        ll p=1;
        for(int i=0; i<zct[n-1]; i++) p=p*2%MOD;
        ans+=p;
        ans%=MOD;
    }else{
        ll dp=1, sdp=1, sdpp=zct[ind[s[n]][0]];
            for(int j=1; j<ind[s[n]].size(); j++){
                dp=sdp*zct[ind[s[n]][j]]+1+MOD-sdpp;
                dp%=MOD;
                sdp+=dp;
                sdp%=MOD;
                sdpp+=zct[ind[s[n]][j]]*dp;
                sdpp%=MOD;
            }
        ans=dp;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 42228
import java.util.*;

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

        String s = sc.nextLine();
        String p = sc.nextLine();

        int num_s = s.length();
        s += s.substring(0,s.length() - 1);
        
        int yes = 0;
        for(int i = 0;i < num_s;i++){
            if((s.substring(i,(p.length() + i))).equals(p)) yes++;
        }

        if(yes > 0) System.out.println("Yes");
        else    System.out.println("No");
    }
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
  

}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL){
    return treeMaximum(x->right);
  }
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
    return y;
  }

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left=x;
  }
  else{
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
  


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if(z->key<y->key){
    y->left=z;
  }
  else{
    y->right=z;
  }




}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25180
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  if(tail+1==LEN){
    tail=0;
  }
  else{
    tail++;
  }
}

P dequeue(){
  P u;
  u=Q[head];
  if(head+1==LEN){
    head=0;
  }
  else{
    head++;
  }
  return u;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }

  while(head!=tail){
    u=dequeue();
    if(u.t>q){
      u.t-=q;
      elaps+=q;
      enqueue(u);
    }
    else{
      elaps+=u.t;
      printf("%s %d\n",u.name,elaps);
    }
  }
  
  return 0;
}



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

int main() {
	// your code goes here
    int h, n;
    cin >> h >> n;
    int a[n + 1];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    long long int s = 0;
    for(int i = 0; i < n; i++)
    {
        s += a[i];
    }
    long long res = 0;
    res = h - s;
    if(res <= 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    //cout << s << endl;
	return 0;
}


Measured memory_bytes: 640