akhauriyash/Code-Regression huggingface dataset:
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int>vi;
typedef vector<ll>vii;
typedef set<int>si;
typedef set<ll>sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const ll MOD =(ll)1e9+1147483647;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<nl;
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3576
using System;
using System.Linq;

namespace _0276
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 7; i++)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                Console.WriteLine(x[0] - x[1]);
            }
        }
    }
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    
    for (;;) {
        ll b; cin >> b;
        if (!b) break;
        ll x = 0, y = 0;
        for (ll i = 1; i * i <= b * 4; i++) {
            ll n = b * 2 - i * (i - 1);
            ll d = 2 * i;
            // cout << i << endl;
            if (n % d == 0 && n / d > 0) {
                x = n / d, y = i;
            }
        }
        cout << x << " " << y << endl;
    }
}


Measured memory_bytes: 3104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  string S; cin>>S;
  vector<int> word(S.size());
  set<int> ch;
  rep(i,S.size())
  {
    word.at(i)=S.at(i)-'a';
    ch.insert(S.at(i)-'a');
  }
  if(S.size()<26)
  {
    rep(i,26)
    {
      if(!(ch.count(i))) 
      {
        cout<<S<<(char)(i+'a')<<endl;
        return 0;
      }
    }
  }
  if(S=="zyxwvutsrqponmlkjihgfedcba") {cout<<-1<<endl; return 0;}
  
  set<int> list;
  int last;
  char p=S.at(25);
  for(int i=25;i>=0;i--)
  {
    if(S.at(i-1)-'a'>S.at(i)-'a')
    {
      list.insert(S.at(i)-'a');
      S.pop_back();
      continue;
    }  
    list.insert(S.at(i)-'a');
    S.pop_back();
    last=S.at(i-1)-'a';
    list.insert(S.at(i-1)-'a');
    S.pop_back();
    break;
  }  
  for(int i=last+1;i<26;i++)
  {
    if(list.count(i))
    {
      cout<<S<<(char)(i+'a')<<endl;
      return 0;
    }
  }  
  
  /*
  rep(i,26)
  {
    if(i==0) {continue;}
    if(S.at(i)>S.at(i-1)) {}
  */
  /*
  next_permutation(word.begin(),word.end());
  string ans="";
  bool judge=false;
  for(int i=25;i>=0;i--)
  {
  	if(word.at(i)!=i) {judge=true;}
    if(judge) {ans+=(char)(word.at(i)+'a');}
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  */
  return 0;
}


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

int main(int argc, char const *argv[])
{
    int n;
    string s;

    cin >> n >> s;

    auto max_count = 0;

    for (int i = 1; i < n; i++) {
        auto first = s.substr(0, i);
        auto latter = s.substr(i);
        auto type_count = 0;
        string latest;
        for (auto c_first : first) {
            if (latest.find(c_first) != string::npos) {
                continue;
            }
            for (auto c_latter : latter) {
                if (c_first == c_latter) {
                    type_count++;
                    break;
                }
            }
            latest += c_first;
        }
        if (type_count > max_count) {
            max_count = type_count;
        }
    }

    cout << max_count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
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;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const long long max_cache=1000000;
long long cache_fact[max_cache];
long long combination_cached(long long n,long long r){
  if(r<0||r>n)return 0;
  if(r==0||r==n)return 1;
  static bool cached=false;
  if(cached==false){
    cached=true;
    cache_fact[0]=0;
    REP(max_cache-1){
      cache_fact[i+1]=cache_fact[i]+__builtin_ctzll(i+1);
    }
  }
  return cache_fact[n]-cache_fact[r]-cache_fact[n-r]>0?0:1;
}
void solve(long long N, string a){
  vector<ll> ans;
  set<ll> s;
  REP(N){
    ans.push_back(a[i]-'1');
    s.insert(ans.back());
  }
  REP(N){
    cerr<<combination_cached(N-1,i)<<endl;
  }
  if(s.size()==1){
    cout<<0<<endl;
  }else if(s.size()==2){
    ll ansl=0;
    ll sm=*s.begin(),lr=*(next(s.begin()));
    REP(ans.size()){
      if(ans[i]!=sm)ansl=(ansl+combination_cached(ans.size()-1,i))%2;
    }
    if(ansl!=0){
      cout<<lr-sm<<endl;
    }else{
      cout<<0<<endl;
    }
  }else{
    ll ansl=0;
    REP(ans.size()){
      if(ans[i]==1)ansl=(ansl+combination_cached(ans.size()-1,i))%2;
    }
    cout<<ansl<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    string a;
    cin>>a;
    solve(N, std::move(a));
    return 0;
}


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

#define int long long

int32_t main(){
	int n ;
	cin >> n ;
	int sum = 0 ;
	int ans = 0 ;
	int mod = 1e9 + 7 ;
	for(int i = 0 ; i < n ; i++){
		int x ; cin >> x ;
		ans = (ans + x*sum) % mod ;
		sum = (sum + x) % mod ;
	}
	cout << ans ;
	return 0 ;
}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    map<string, ll> mp;
    ll mx = 0;
    for (ll i = 0; i < N; i++) {
        string a;
        cin >> a;
        mx = max(mx, ++mp[a]);
    }
    for (const auto& [a, b] : mp) {
        if (b == mx) {
            prints()(a);
        }
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 19184
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define X first
#define Y second
#define debug(x) cerr << #x << ": " << x << endl;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define rep(i,l,r) for (ll i=l; i<r; i++)
#define repr(i,r,l) for (ll i=r; i>=l; i--)
using namespace std;
const long long int N=2e3+30;
pair <ll,ll> d[N];
int main(){
    ll n,sq,ans=0;
    cin >> n;
    sq = sqrt(n);
    if (sq*sq == n) sq--;
    rep (i,1,sq+1){
        rep (j,i,n){
            if (i*j < n){
                if (i!=j) ans+=2;
                else{
                    ans+=1;
                }
               // debug(i);debug(j);
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
   ios::sync_with_stdio(false);
    int a,b,c,x,y;
    int ans=0,cnta=0,cntb=0;;
    cin>>a>>b>>c>>x>>y;
    float ma,mb;
    ma=(a)/(float)(a+b)*c;
    mb=(b)/(float)(a+b)*c;
    if((2*c)<(a+b))
        {
            if(x<y)
            {
                int cc=cnta;
                cnta+=(x-cc);
                cntb+=(x-cc);
                ans+=x*2*c;
            }
           else
           {
                int cc=cntb;
                cnta+=(x-cc);
                cntb+=(x-cc);
                ans+=y*2*c;
           }
        }
        else
        {
             cout<<x*a+y*b;
             return 0;
        }
 
        if(x>y){
        int cc=min(2*c,a);
        ans+=(cc*(x-y));
    }
    else{
        int cc=min(2*c,b);
        ans+=(cc*(y-x));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
food = [0] * M
K_list = []
for _ in range(N):
    K_list.append(list(map(int, input().split())))

for i in range(N):
    for j in range(1, K_list[i][0]+1):
        food[K_list[i][j]-1] += 1


print(food.count(N))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define maxN 200005
#define maxA 26
using namespace std;

//FILE *fin = freopen("c.in", "r", stdin);

int n;
char s[maxN];

int len, nxt[maxN][maxA], dp[maxN];
int pos[maxN];


int main()
{
    scanf("%s", s + 2);
    n = strlen(s + 2) + 1;
    for (int i = n; i > 1; -- i)
    {
        for (int j = 0; j < maxA; ++ j)
            nxt[i][j] = nxt[i + 1][j];
        nxt[i][s[i] - 'a'] = i;
    }

    for (int i = n; i >= 1; -- i)
    {
        dp[i] = n + 1;
        for (int j = 0; j < maxA; ++ j)
            if (dp[nxt[i + 1][j]] + 1 < dp[i])
            {
                dp[i] = dp[nxt[i + 1][j]] + 1;
                pos[i] = j;
            }
    }
    for (int i = 1; i <= n && i;)
    {
        printf("%c", pos[i] + 'a');
        i = nxt[i + 1][pos[i]];
        if (i == 0) break;
    }

    return 0;
}


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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n;
  cin >> n;
  vector<long long> A(n + 1), X(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
    if (i & 1) {
      X[1] += A[i];
    } else {
      X[1] -= A[i];
    }
  }
  X[1] /= 2;
  for (int i = 1; i < n; ++i) {
    X[i + 1] = A[i] - X[i];
  }
  for (int i = 1; i <= n; ++i) {
    cout << 2 * X[i] << " \n"[i == n];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
  string s;
  cin >> s;

  for (int i = 0; i < 3; i++) {
    if (s[i] == s[i+1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }

  cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=3e3+10;
const int mod=998244353;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,x,C[N][N];

int getC(int n,int m) {
	if(m<0||n<m) return 0;
	return C[n][m];
}

int cal(int n) {
	int ret=0;
	if(2*n<x||x%2==1) ret=1;
	for(int i=n;i<2*n;i++) {
		if(i<x) ret=(ret+getC(n,i-n))%mod;
		else {
			if(i%2==x%2) continue;
			int cnt=(i-x+1)/2;
			int rp=n-2*cnt,rs=i-4*cnt;
			ret=(ret+getC(rp,rs-rp))%mod;
		}
	}
	return ret;
}

int main() {
	for(int i=0;i<N;i++) {
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	cin>>n>>x;
	int ans=0;
	for(int i=0;i<=n;i++) {
		ans=(ans+1ll*getC(n,i)*cal(n-i))%mod;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 34304
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    string s, ss;
    ll t;
    cin>>t;
    cin>>s>>ss;

    for(int i=0; i<t; i++)
    {
        cout<<s[i]<<ss[i];
    }
    cout<<endl;
}


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

int main()
{
    int n ,k;
    cin>>n>>k;
    double prob=0;
    for(int i=1;i<=n;i++)
    {
        double temp=double(k)/i;
        double weil=ceil(log(temp)/log(2));
        int t=ceil(weil);
        double ttt=pow(0.5,t)/n;
        if(k<i)
            prob+=double(1)/n;
        else
            prob+=ttt;
    }

    cout<<setprecision(15)<<prob;
}


Measured memory_bytes: 256
from collections import deque 


n = int(input())
preroots = [[] for i in range(n-1)]
for i in range(len(preroots)):
    preroots[i] = list(map(int,input().split()))

roots = [[] for i in range(n+1)]
for i in preroots:
    roots[i[0]].append((i[1],i[2]))
    roots[i[1]].append((i[0],i[2]))
         
    
QK = list(map(int,input().split()))
query = [[] for i in range(QK[0])]
         
for i in range(QK[0]):
    query[i] = list(map(int,input().split()))
    
    
waylen = [-1 for i in range(n+1)]
waylen[QK[1]] = 0

q = deque()
q.append(QK[1])

while len(q):
    p = q.popleft()
    for i in roots[p]:
        if waylen[i[0]] != -1:continue
        waylen[i[0]] = i[1] + waylen[p]
        q.append(i[0])
        
for i in range(QK[0]):
    print(waylen[query[i][0]]+waylen[query[i][1]])

Measured memory_bytes: 81508
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  set<ll> s;
  rep(i,n) {
    ll a;
    cin >> a;
    s.insert(a);
  }
  cout << s.size() << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n;
char s[200005];
int a[200005];

int main() {
    scanf("%d%s", &n, s);
    n *= 2;
    a[0] = 0;
    char col = s[0];
    int bal = 1;
    int ans = 1;
    for (int i = 1; i < n; ++i) {
        if (s[i] != col) {
            a[i] = 0;
            ++bal;
        } else {
            a[i] = 1;
            ans = (LL)ans * bal % MOD;
            --bal;
        }
        if (col == 'W') {
            col = 'B';
        } else {
            col = 'W';
        }
    }
    for (int i = 2; i <= n / 2; ++i) {
        ans = (LL)ans * i % MOD;
    }
    if (col == 'B' || bal != 0) {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 300005
using namespace std;
int h,w,k,ans = 0;
string s[7];
set<pair<vector<int>,vector<int> >> st;
vector<int> row,col;
int count(){
    int cnt = 0;
    for(int i = 0; i < h; i++){
        bool ok = false;
        for(int ii = 0; ii < (int)row.size(); ii++){
            if(row[ii] == i)ok = true;
        }
        if(ok)continue;
        for(int j = 0; j < w; j++){
            ok = false;
            for(int ii = 0; ii < (int)col.size(); ii++){
                if(col[ii] == j)ok = true;
            }
            if(ok)continue;
            if(s[i][j] == '#')cnt++;
        }
    }
    return cnt;
}
void func(int x,int y){
    int black = count();
    if(black == k){
        vector<int> aa(h),bb(w);
        for(int i = 0; i < h; i++)aa[i] = 0;
        for(int i = 0; i < w; i++)bb[i] = 0;
        for(int i = 0; i < (int)row.size(); i++)
            aa[row[i]] = 1;
        for(int i = 0; i < (int)col.size(); i++)
            bb[col[i]] = 1;
        st.insert({aa,bb});
        ans++;
    }
    if(x == h || y == w)return;
    // for(int i = y; i < w; i++){
    //     for(int j = x; j < h; j++){
    //         row.pb(j);
    //         func(j + 1,i);
    //         row.pop_back();
    //     }
    //     col.pb(i);
    //     func(x,i + 1);
    //     for(int j = x; j < h; j++){
    //         row.pb(j);
    //         func(j + 1,i + 1);
    //         row.pop_back();
    //     }
    //     col.pop_back();
    // }
    for(int i = x; i < h; i++){
        for(int j = y;j < w; j++){
            col.pb(j);
            func(i,j + 1);
            col.pop_back();
        }
        row.pb(i);
        func(i + 1,y);
        for(int j = y; j < w; j++){
            col.pb(j);
            func(i + 1,j + 1);
            col.pop_back();
        }
        row.pop_back();
    }
    //func(x,y + 1);
    //func(x + 1,y);
    //func(x + 1,y + 1);
}

int main()
{
    FLASH
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++)
        cin >> s[i];
    func(0,0);

    cout << st.size();
    return 0;
}


Measured memory_bytes: 3840
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[300005][5];  //0 1; Netural; 0 0; 0 Before;  1 0 10 Brefore; 1 1; 1 + Natural
char a[300005];
const int modo=1000000007;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    scanf("%s",a);
    dp[0][1]=1;
    int i;
    int n=strlen(a);
    for (i=0;i<n;i++)
    {
        if ((a[i]=='?')||(a[i]=='1'))
        {
            dp[i+1][3]+=dp[i][1];
            dp[i+1][3]%=modo;
            dp[i+1][4]+=dp[i][3];
            dp[i+1][4]%=modo;
            dp[i+1][4]+=dp[i][4];
            dp[i+1][4]%=modo;
            if (i%2==0)
            {
                dp[i+1][0]+=dp[i][0];
                dp[i+1][0]%=modo;
                dp[i+1][3]+=dp[i][2];
                dp[i+1][3]%=modo;
            }
            else
            {
                dp[i+1][1]+=dp[i][0];
                dp[i+1][1]%=modo;
                dp[i+1][2]+=dp[i][2];
                dp[i+1][2]%=modo;
            }
        }
        if ((a[i]=='?')||(a[i]=='0'))
        {
            dp[i+1][4]+=dp[i][4];
            dp[i+1][4]%=modo;
            dp[i+1][2]+=dp[i][3];
            dp[i+1][2]%=modo;
            dp[i+1][2]+=dp[i][2];
            dp[i+1][2]%=modo;
            dp[i+1][0]+=dp[i][1];
            dp[i+1][0]%=modo;
            dp[i+1][0]+=dp[i][0];
            dp[i+1][0]%=modo;
        }
    }
    dp[n][4]+=dp[n][3];
    printf("%d\n",dp[n][4]%modo);
    return 0;
} 


Measured memory_bytes: 6400
import bisect
num = int(input())
up = sorted(list(map(int,input().split())))
mid = sorted(list(map(int,input().split())))
dw = sorted(list(map(int,input().split())))
SUM = 0

for i in mid:
  head = bisect.bisect_left(up,i)
  foot = len(dw) - bisect.bisect_right(dw,i)
  SUM += head * foot

print(SUM)

Measured memory_bytes: 23244
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = 1;
    rep(i, n)
    {
        if(ans * 2 - ans < k) ans *= 2;
        else ans += k;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
ll n,A,B,C,D;
int main()
{
	while(cin>>n>>A>>B>>C>>D)
	{
		bool flag=false;
		for(ll i=0;i<=n;i++)//add i times 
		{
			ll j=n-1-i;
			ll mn=A+i*C-j*D;
			ll mx=A+i*D-j*C;
			if(B<=mx&&B>=mn)
				flag=true;
		}
		if(flag)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

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

int N;
vector<int> a;

void solve(){

    vector<int> res;

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

        int pivot = -1;

        for(int j =(int)a.size()-1;j >= 0; --j){
            
            if(a[j]==j){

                pivot = j;
                break;

            }

        }
        
        if(pivot == -1){
            cout << -1<<endl;
            return;
            
        }        
        res.push_back(pivot+1);
        a.erase(a.begin()+pivot);
    }
    reverse(res.begin(),res.end());
    for(auto v:res)cout << v << endl;
}
    


int main(void){
    cin >> N;
    a.resize(N);
    for(int i= 0;i <N;i++)cin >> a[i],--a[i];
    solve();
    
}


Measured memory_bytes: 256
n=int(input())
d=[list(map(int, input().split())) for _ in range(n)]
ans=False
for i in range(n-2):
    if d[i][0]==d[i][1] and d[i+1][0]==d[i+1][1] and d[i+2][0]==d[i+2][1]:
        ans=True
        break
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 62468
#include <stdio.h>

int main(void){
long long int many[5]={0};
int hoge,hogera;
char s[16]={0};
long long int math = 0;

scanf("%d",&hoge);
for(hogera=0;hogera<hoge;hogera++){
scanf("%s",&s);
switch(s[0]){
case 'M':many[0]++;break;
case 'A':many[1]++;break;
case 'R':many[2]++;break;
case 'C':many[3]++;break;
case 'H':many[4]++;break;
default : break;
}
}

math += (many[0]*many[1]*many[2]);
math += (many[0]*many[1]*many[3]);
math += (many[0]*many[1]*many[4]);
math += (many[0]*many[2]*many[3]);
math += (many[0]*many[2]*many[4]);
math += (many[0]*many[3]*many[4]);
math += (many[1]*many[2]*many[3]);
math += (many[1]*many[2]*many[4]);
math += (many[1]*many[3]*many[4]);
math += (many[2]*many[3]*many[4]);
printf("%lld",math);
return 0;
}

Measured memory_bytes: 256
from itertools import permutations
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


#ここから書き始める
n = int(input())
x = [i for i in range(1, n + 1)]
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a = 0
b = 0
cnt = 0
a_finished = False
b_finished = False
for i in permutations(x):
    # print("i =", i)
    if a_finished and b_finished:
        break
    if list(i) == p:
        a = cnt
        a_finished = True 
    if list(i) == q:
        b = cnt
        b_finished = True
    cnt += 1
ans = abs(a - b)
print(ans)

Measured memory_bytes: 5300
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <vector>
using namespace std;

int main()
{
    const char *Yes = "Yes";
    const char *No = "No";

    char s[101];
    char t[101];

    if (scanf("%s%s", s, t) < 1) return 0;

    vector<char> vs;
    vector<char> vt;

    for (int i = 0; i < (signed)strlen(s); i++)
    {
        vs.push_back(s[i]);
    }

    for (int i = 0; i < (signed)strlen(t); i++)
    {
        vt.push_back(t[i]);
    }

    sort(vs.begin(), vs.end());
    sort(vt.begin(), vt.end(), greater<char>());

    bool flg = false;
    int vss = vs.size();
    int vst = vt.size();
    int vmn = vss < vst ? vss : vst;
    int j = 0;
    for (; j < vmn; j++)
    {
        if (vt[j] < vs[j])
        {
            break;
        }
        else if (vs[j] < vt[j])
        {
            flg = true;
            break;
        }
    }

    printf("%s\n", flg ? Yes : (j == vmn && vss < vst) ? Yes : No);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int K;
vector<pair<int,int> >f(int X,int Y)
{
	if(X+Y==K)
	{
		return{make_pair(X,Y)};
	}
	for(long l=max((X+Y+K-1)/K,2);;l++)
	{
		if(X+Y<=l*K&&(l*K-X-Y)%2==0)
		{
			long T=(l*K-X-Y)/2;
			long V=0;
			if(T>=K)V=T-K,T=K;
			vector<pair<int,int> >ret;
			ret.push_back(make_pair(K-T,-T));
			long x=K-T,y=-T;
			for(int i=1;i<l-1;i++)
			{
				if(x+K<=X+V)
				{
					ret.push_back(make_pair(x+=K,y));
				}
				else
				{
					int p=X+V-x;
					ret.push_back(make_pair(x=X+V,y+=K-p));
				}
			}
			ret.push_back(make_pair(X,Y));
			return ret;
		}
	}
}
main()
{
	int x,y;cin>>K>>x>>y;
	int X=abs(x),Y=abs(y);
	if(K%2==0&&(X+Y)%2==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	bool flag=false;
	if(X<Y)
	{
		swap(X,Y);
		flag=true;
	}
	vector<pair<int,int> >ret=f(X,Y);
	cout<<ret.size()<<endl;
	for(pair<int,int>p:ret)
	{
		if(flag)swap(p.first,p.second);
		cout<<p.first*(x<0?-1:1)<<" "<<p.second*(y<0?-1:1)<<endl;
	}
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll K;
int A[202020][70];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	for(i=1;i<=N;i++) cin>>A[i][0];
	
	int cur=1;
	FOR(i,60) {
		for(j=1;j<=N;j++) A[j][i+1]=A[A[j][i]][i];
		if(K&(1LL<<i)) cur=A[cur][i];
	}
	
	cout<<cur<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define llint long long int

using namespace std;

int main() {
    llint N, K;

    cin >> N >> K;

    vector<int> P(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> P[i];
    }
    vector<llint> C(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> C[i];
    }
    llint ans = LONG_LONG_MIN;

    for (int i = 1; i <= N; i++) {
        int mas = i;
        llint score = 0;
        llint max_score = LONG_LONG_MIN;
        vector<llint> masu_list;

        for (int k = 1; k <= K; k++) {
            mas = P[mas];

            if (k == 1 || mas != masu_list[0]) {
                score += C[mas];

                if (score > max_score) {
                    max_score = score;
                }
                masu_list.push_back(mas);
            }
            else {
                if (score > 0) {
                    mas = i;
                    score *= (K - 1) / masu_list.size();
                    max_score = score;

                    for (int k2 = masu_list.size() * ((K - 1) / masu_list.size()) + 1; k2 <= K; k2++) {
                        mas = P[mas];
                        score += C[mas];

                        if (score > max_score) {
                            max_score = score;
                        }
                    }
                }
                break;
            }
        }
        if (max_score > ans) {
            ans = max_score;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
    int n;
    string s;
    cin >> n >> s;
    
    int i, count, maxcount;
    char c;
    maxcount = 0;
    for(i = 1; i < n - 1; i++){
        string x, y;
        x = s.substr(0, i);
        y = s.substr(i, n - 1);
        
        count = 0;
        for(c = 'a'; c <= 'z'; c++){
            bool findx, findy;
            if (x.find(c) != std::string::npos) {
                findx = true;
            }else {
                findx = false;
            }
            
            if (y.find(c) != std::string::npos) {
                findy = true;
            }else {
                findy = false;
            }
            
            if(findx && findy){
                count++;
            }
        }
        
        if(count > maxcount){
            maxcount = count;
        }
    }
	cout << maxcount << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;
int main(){
double N, K;cin >> N >>K;

cout << ceil((N - 1)/(K - 1));
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

const int N = 1e5+5;
ll dp[100][N];
int n , w[N] , p[N] , k;

ll calc (int idx , int rem){

    if (idx == n)
        return 0;

    ll &ret = dp[idx][rem];
    if (~ret)
        return ret;

    ret = calc(idx+1,rem);

    if (w[idx] <= rem)
        ret = max (ret , calc(idx+1,rem-w[idx]) + p[idx]);

    return ret;

} 

void Suhaib_Sawalha (){

    cin >> n >> k;
    for (int i = 0 ; i < n ; ++i)
        cin >> w[i] >> p[i];

    memset(dp,-1,sizeof dp);
    cout << calc(0,k);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 81776
#include<bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
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() {
    LL N;
    LL K;
    cin >> N >> K;
    vector<LL> a(N);
    for(int i = 0;i < N;i++) {
        cin >> a[i];
        a[i] = a[i]%K - 1;
    }
    vector<LL> modsum(N);
    LL sum = 0;
    for(int i = 0;i < N;i++) {
        sum += a[i];
        modsum[i] = sum % K;
    }
    map<LL, LL> mp;
    LL ans = 0;
    for(int i = 0;i < min(K, N);i++) {
        mp[modsum[i]] = mp[modsum[i]] + 1;
        if(i+1 == K && modsum[i] == 0)  ans--;
    }
    for(auto& m : mp) {
        LL key = m.first;
        LL value = m.second;
        ans += value * (value - 1) / 2;
        if (key == 0) {
            ans += value;
        }
    }
    for(int i = 1;i + K - 1 < N;i++) {
        mp[modsum[i-1]] = mp[modsum[i-1]] - 1;
        mp[modsum[i+K-1]] = mp[modsum[i+K-1]] + 1;
        ans += mp[modsum[i+K-1]] - 1;
    }
    cout << ans << endl;
}

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

int main(){
  int a,b,c,d;
  int s,e;
  cin>>a>>b>>c>>d;
  if(a>c){
    s=a;
  }else{
    s=c;
  }
  if(b<d){
    e=b;
  }else{
    e=d;
  }
  int ans = e-s;
  if(ans<0){
    ans = 0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    long double a,b,x;
    cin >> a >> b >> x;
    long double pi = 3.14159265358979311599796346854418516159057617187500;
    if(2*x >= a*a*b){
        long double deg1 = atan(2*b/a - 2*x/(a*a*a));
        cout << fixed << setprecision(16);
        cout <<  deg1*180/pi << endl;
    }
    else{
        long double deg2 = atan(a*b*b/(2*x));
        cout << fixed << setprecision(16);
        cout << deg2*180/pi << endl;
    }
}


Measured memory_bytes: 3844
// Example program
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<vector<int>> vaul(2, vector<int>(n));
    vector<vector<int>> dp(2, vector<int>(n, 0));
    for (int j = 0; j < 2; ++j)
        for (int i = 0; i < n; ++i)
            cin >> vaul[j][i];
    dp[0][0] = vaul[0][0];
    for (int i = 1; i < n; ++i) {
        dp[0][i] = dp[0][i - 1] + vaul[0][i];
    }
    dp[1][0] = dp[0][0] + vaul[1][0];
    for (int i = 1; i < n; ++i) {
        dp[1][i] = max(dp[1][i - 1], dp[0][i]) + vaul[1][i];   
    }
    cout << dp[1][n - 1];
}


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

#include <boost/range/algorithm.hpp> // boost::sort(arr)


int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<pair<double, int>> arr;
  rep(i, n) {
    int h;
    cin >> h;
    double temp_diff = abs(a - (t - h * 0.006));
    arr.emplace_back(temp_diff, i + 1);
  }
  boost::sort(arr);
  cout << arr[0].second << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

for(int i=0;;i++){
int H = sc.nextInt();
int W = sc.nextInt();
if(H==0&&W==0){
    break;
}

for(int m=0;m<H;m++){

for(int k=0;k<W;k++){
    System.out.printf("#");
}
    System.out.printf("\n");
}
    System.out.printf("\n");
}
    sc.close();
}

}


Measured memory_bytes: 62904
import Control.Monad

main :: IO()
main = do
  i <- map (read:: String -> Int) .words <$> getLine
  let n = head i
  let x = last i
  m <- replicateM n getLine
  let m2 = map (read:: String -> Int) m
  print $ n + (x - sum m2) `div` minimum m2

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,s=0;
    cin>>n;
    vec A[11];
    rep(i,9) A[1].push_back(i+1);
    rep(i,9){
        int a=i+2;
        for(auto j:A[a-1]){
            if(j%10==0) A[a].push_back(j*10),A[a].push_back(j*10+1),s+=2;
            else if(j%10==9) A[a].push_back(j*10+8),A[a].push_back(j*10+9),s+=2;
            else rep(k,3) A[a].push_back(j*10+j%10-1+k),s++;
            if(s>n) break;
        }
    }
    int b=1;
    rep(i,10)for(auto j:A[i+1]){
        if(b==n){
            cout<<j;
            return 0;
        }
        b++;
    }
}

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

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

    int H, W;
    cin >> H >> W;

    map<int, int> candidates;
    multiset<int> moves;

    rep(i, W) {
        candidates[i] = i;
        moves.insert(0);
    }

    rep(i, H) {
        int A, B;
        cin >> A >> B;
        A--;

        int r = -1;
        for (auto it = candidates.lower_bound(A); it != candidates.end() && it->first <= B; candidates.erase(it++)) {
            r = max(r, it->second);
            moves.erase(moves.find(it->first - it->second));
        }
        if (r != -1 && B != W) {
            moves.insert(B - r);
            candidates[B] = r;
        }

        if (moves.size() == 0) {
            cout << -1 << endl;
        } else {
            cout << *moves.begin() + (i + 1) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 22360
#include<stdio.h>
  int main(void){
      int i,j,n,b,f,r,v,A[3][10]={0},B[3][10]={0},C[3][10]={0},D[3][10]={0};
      scanf("%d",&n);
      for(i=0;i<n;i++){
         scanf("%d %d %d %d",&b,&f,&r,&v);
         if(b==1)
          A[f-1][r-1]=v+A[f-1][r-1];
         else if(b==2)
           B[f-1][r-1]=v+B[f-1][r-1];
         else if(b==3)
           C[f-1][r-1]=v+C[f-1][r-1];
         else if(b==4)
           D[f-1][r-1]=v+D[f-1][r-1];
      }
      for(i=0;i<3;i++){
         for(j=0;j<10;j++){
            printf(" %d",A[i][j]);
         }
      putchar('\n');
      }
      printf("####################\n");
      for(i=0;i<3;i++){
         for(j=0;j<10;j++){
            printf(" %d",B[i][j]);
         }
      putchar('\n');
      }
      printf("####################\n");
      for(i=0;i<3;i++){
         for(j=0;j<10;j++){
            printf(" %d",C[i][j]);
        }
    putchar('\n');
      }
     printf("####################\n");
      for(i=0;i<3;i++){
         for(j=0;j<10;j++){
            printf(" %d",D[i][j]);
         }
      putchar('\n');
      }
      return 0;
  }


Measured memory_bytes: 2088
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    if N == 1:
        return 1

    ans = N
    l = 0
    r = 0
    s = A[l]
    while l < N-1:
        if r+1 < N:
            if s & A[r+1] == 0:
                r += 1
                s |= A[r]
                ans += r - l
                continue
        if l == r:
            l += 1
            r += 1
            s = A[l]
        else:
            s &= ~A[l]
            l += 1
    return ans

print(solve())

#  1  2  4  8  1
#  l  r              (1,2)
#  l     r           (1,4)(2,4)
#  l        r        (1,8)(2,8)(4,8)
#     l     r
#     l        r     (2,1)(4,1)(8,1)


Measured memory_bytes: 77644
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int ans = 700;
	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o') {
			ans += 100;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

ll n,m,cnt=0,A,C;
ll x[51] = {};
ll dp[55][55][2505] = {};
vector<ll> a,b,c;

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>m;
        a.push(m);
    }
    for(int i=0; i<n; i++){
        cin>>m;
        b.push(m);
    }
    for(int i=0; i<n; i++){
        cin>>m;
        c.push(m);
    }
    
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());

    for(auto v: b){
        A = lower_bound(a.begin(), a.end(), v) - a.begin();
        C = c.end() - upper_bound(c.begin(), c.end(), v);
        cnt+=A*C;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> imos(m+10,0);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n-1){
        if(a[i+1] > a[i]){
            if(a[i+1] > a[i] + 1){
                imos[a[i]+4]++;
                imos[a[i+1]+3] -= a[i+1]-a[i];
                imos[a[i+1]+4] += a[i+1]-a[i]-1;
            }
        }else{
            if(m - a[i] > 1){
                imos[a[i]+4]++;
                imos[m+3] -= m-a[i];
                imos[m+4] += m-a[i]-1;
            }
            imos[1] += m-a[i]-1;
            imos[2] -= m-a[i]-1;
            imos[3]++;
            imos[a[i+1]+3] -= m-a[i]+a[i+1];
            imos[a[i+1]+4] += m-a[i]+a[i+1]-1;
        }
    }
    rep(i,m+5){
        imos[i+1] += imos[i];
    }
    rep(i,m+5){
        imos[i+1] += imos[i];
    }
    ll sm = 0;
    rep(i,n-1){
        if(a[i+1] > a[i]){
            sm += a[i+1] - a[i];
        }else{
            sm += m-a[i]+a[i+1];
        }
    }
    ll mx = 0;
    for(int i=3;i<=m+2;i++){
        mx = max(imos[i],mx);
    }
    cout << sm-mx << "\n";
    return 0;
}


Measured memory_bytes: 1792