akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff  first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 1e7+9;
const lli mod= 1000000007;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
///=================== ALWAYS CHECK 1 or 0 base case=================================================================================///
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///

void solve()
{
    pair<lli,lli>p[100000];
    lli n,k;cin>>n>>k;
    lli sum=0;
    for(int i=0;i<n;i++)
    {
        lli a,b;cin>>a>>b;
        p[i].ff=a,p[i].ss=b;
    }
    sort(p,p+n);
    for(int i=0;i<n;i++)
    {
        sum+=p[i].ss;
        if(sum>=k)
        {
            cout<<p[i].ff<<endl;return;
        }
    }

}
int main()
{
    solve();
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

struct E {
    int to, w;
};
 
using G = vector<vector<E>>;
 
template <typename T>
pair<vector<T>, vector<int>> dijkstra(G g, int s, T inf) {
    int n = g.size();
    vector<T> d(n, INF);
    vector<int> r(n, -1);
    d[s] = 0;
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while(!pq.empty()){
        auto c = pq.top();pq.pop();
        if(d[c.second] < c.first) continue;
        for(auto e : g[c.second]){
            if(d[e.to] > d[c.second] + e.w){
                d[e.to] = d[c.second] + e.w;
                r[e.to] = c.second;
                pq.push({d[e.to], e.to});
            }
        }
    }
    return {d, r};
}

int main() {
    std::ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    G g(n+m);
    for(int i=0;i<n;i++){
        int k;cin >> k;
        for(int j=0;j<k;j++){
            int l;cin >> l;l--;
            g[i].push_back({n+l, 1});
            g[n+l].push_back({i, 1});
        }
    }
    auto p = dijkstra(g, 0, INF);
    string ans = "YES";
    for(int i=0;i<n;i++){
        int d = p.first[i];
        if(d == INF) ans = "NO";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 21492
N,X,Y=map(int,input().split())

if Y<X:
    X,Y=Y,X

Dist=[0 for i in range(N)]

for i in range(1,N):
    for j in range(i,N+1):
        dist_a=j-i
        dist_b=abs(i-X)+abs(j-Y)+1
        ans=min(dist_a,dist_b)
        Dist[ans]+=1

for i in range(1,N):
    print(Dist[i])

Measured memory_bytes: 73840
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A < B and (A + V * T) >= (B + W * T):
    print("YES")
    exit()
if B < A and (A - V * T) <= (B - W * T):
    print("YES")
    exit()

print("NO")

Measured memory_bytes: 9200
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b){
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	ull n;
	cin >> n;
	vector<ull> v(n);
	ull ans = 1LL;
	REP(i, n) {
		cin >> v[i];
		ans = lcd(ans, v[i]);
	}
	dump(ans);
}



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

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

	int a, b;
	cin >> a >> b;
	int height_a = 0;
	for (int i = 0; i < b - a; i++) {
		height_a = height_a + i;
	}
	
	cout << height_a - a << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n, minj, cnt = 0;
    cin >> n;
    int A[n];
    for (int i=0; i<n; i++){
        cin >> A[i];
    }
    for (int i=0; i<n; i++){
        minj = i;
        for (int j=i; j<n; j++){
            if (A[j] < A[minj]){
                minj = j;
            }
        }
        if (A[i] != A[minj]) cnt += 1;
        swap(A[i], A[minj]);
    }
    for (int i=0; i<n; i++){
        if (i == n-1){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3112
def min_index(A):
    index = 0
    m = A[0]
    for i in range(1,len(A)):
        if A[i] < m:
            m = A[i]
            index = i
    return index

def selectionsort(A,N):
    count = 0
    for i in range(N-1):
        j = min_index(A[i+1:])
        if A[i] > A[i+j+1]:
            #A[i],A[i+j+1] = A[i+j+1],A[i]
            count += 1
            A[i],A[i + min_index(A[i+1:]) + 1] = A[i + min_index(A[i+1:]) + 1],A[i]
    return A,count

if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    ans,count = selectionsort(A,N)
    for i in range(N):
        if i != N - 1:
            print(ans[i],end = " ")
        else:
            print(ans[i])
    print(count)



Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

const int d4[4][2] = {
    {1, 0},
    {0, 1},
    {-1, 0},
    {0, -1},
};

bool solve() {
    int w, h;
    cin >> w >> h;
    if (!w or !h) return false;
    w = 2*w-1; h = 2*h-1;
    bool g[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            g[i][j] = false;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 1-i%2; j < w; j += 2) {
            int k;
            cin >> k;
            g[i][j] = k == 1;
        }
    }
    using P = pair<int, int>;
    queue<P> q;
    bool used[h][w];
    int dist[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            used[i][j] = false;
            dist[i][j] = 1<<28;
        }
    }
    q.push(P(0, 0));
    dist[0][0] = 1;
    while (q.size()) {
        P p = q.front(); q.pop();
        int x, y;
        tie(x, y) = p;
        if (used[y][x]) continue;
        used[y][x] = true;
//        printf("%d %d %d\n", x, y,dist[y][x]);
        for (int d = 0; d < 4; d++) {
            int nx = x+2*d4[d][0], ny = y+2*d4[d][1];
            if (!(0 <= nx and nx < w and 0 <= ny and ny < h)) continue;
            if (g[(y+ny)/2][(x+nx)/2]) continue;
            dist[ny][nx] = min(dist[ny][nx], dist[y][x]+1);
            q.push(P(nx, ny));
        }
    }
    if (dist[h-1][w-1] == 1<<28) dist[h-1][w-1] = 0;
    printf("%d\n", dist[h-1][w-1]);
    return true;
}

int main() {
    while (true) {
        if (!solve()) break;
    }
    return 0;
}

Measured memory_bytes: 3080
n, x = gets.chomp.split
a_arr = gets.chomp.split.map {|i| i.to_i}.insert(0,0)

if x.to_i == 0
  puts a_arr.inject {|mem, i| mem + i}
  exit
end

count = 0

(n.to_i + 1).times do |i|
  next if i == 0
  if a_arr[i - 1] + a_arr[i] > x.to_i
    d = a_arr[i] - ( x.to_i - a_arr[i - 1] )
    a_arr[i] -= d
    count += d
  end
end

puts count


Measured memory_bytes: 9612
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#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};

int n;

int main(){
    cin>>n;
    cout<<n*800-(n/15*200)<<endl;
}

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

map<int, int> prime_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }

    if (n != 1) res[n] = 1;
    return res;
}

// unsigned long long fact(unsigned long long n) {
//     if (n == 0) return 1;
//     unsigned long long t = n * fact(n - 1);
//     return t;
// }

int main() {
    int N;
    cin >> N;
    map<int, int> mp; 
    for (int i = 1; i <= N; i++) {
        map<int, int> tmp = prime_factor(i);

        for (auto j = tmp.begin(); j != tmp.end(); j++) {
            // cout << j->first << " " << j->second << endl;
            mp[j->first] += j->second; 
        }
    }

    unsigned long long ans = 1;
    for (auto i = mp.begin(); i != mp.end(); i++) {
        // cout << i->first << " " << i->second << endl;
        ans *= (i->second + 1);
        ans %= 1000000007;
        // cout << ans << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int, input().split(' '))
deg = abs(30 * H + 0.5 * M - 6 * M)
if deg >180:
    deg = 360 - deg
deg = math.radians(deg)
print(math.sqrt((B - A * math.cos(deg)) ** 2 + (A * math.sin(deg)) ** 2))

Measured memory_bytes: 9448
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
result='Yay!'
r=[a,b,c,d,e]
for i in r:
    for x in r:
        if i-x>k:
            result=':('
print(result)

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

using namespace std;

struct mov {
  int fromY, fromX;
  int toY, toX;
};

vector<mov> hitory;
int main() {
  int H, W;
  cin >> H >> W;
  int map[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> map[i][j];
    }
  }

  for (int i = 0; i < H; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < W-1; j++) {
        if (map[i][j] % 2) {
          hitory.push_back({i,j,i,j+1});
          map[i][j + 1]++;
        }
      }
      if (i != H-1) {
        if (map[i][W-1] % 2) {
          hitory.push_back({i,W-1,i+1,W-1});
          map[i+1][W-1]++;
        }
      }
    } else {
      for (int j = W-1; j > 0; j--) {
        if (map[i][j] % 2) {
          hitory.push_back({i,j,i,j-1});
          map[i][j - 1]++;
        }
      }
      if (i != H-1) {
        if (map[i][0] % 2) {
          hitory.push_back({i,0,i+1,0});
          map[i+1][0]++;
        }
      }
    }
  }

  cout << hitory.size() << endl;
  for(auto itr = hitory.begin(); itr != hitory.end(); ++itr) {
    cout << itr->fromY + 1 << " " << itr->fromX + 1 << " ";
    cout << itr->toY + 1 << " " << itr->toX + 1 << endl;
  }

  return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  vector<vector<ll>> c(3, vector<ll>(3));
  for (ll i = 0; i < 3; ++i) {
    for (ll j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }

  for (ll i = 0; i <= 100; ++i) {
    for (ll j = 0; j <= 100; ++j) {
      for (ll k = 0; k <= 100; ++k) {
        ll a1 = c[0][0]-i;
        if (a1 != c[0][1]-j || a1 != c[0][2]-k) {
          continue;
        }

        ll a2 = c[1][0]-i;
        if (a2 != c[1][1]-j || a2 != c[1][2]-k) {
          continue;
        }
  
        ll a3 = c[2][0]-i;
        if (a3 != c[2][1]-j || a3 != c[2][2]-k) {
          continue;
        }

        if (a1 < 0 || a2 < 0 || a3 < 0) continue;

        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A[3][3],N,B;
  int x[3][3];
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>A[i][j];
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>B;
    for(int j=0;j<3;j++)for(int k=0;k<3;k++){
      if(A[j][k]==B)x[j][k]=1;
    }
  }
  bool X=false;
  for(int i=0;i<3;i++){
    if(x[0][i]+x[1][i]+x[2][i]==3||x[i][0]+x[i][1]+x[i][2]==3)X=true;
  }
  if(x[0][0]+x[1][1]+x[2][2]==3||x[0][2]+x[1][1]+x[2][0]==3)X=true;
  if(X)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    reverse(all(s));
    ll cnt=0, sum=0;
    rep(i,s.size()){
        if(s[i]=='B'){
            sum+=cnt;
        }else{
            cnt++;
        }
    }
    cout1(sum)
}

Measured memory_bytes: 720
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <sstream>
using namespace std;

#define LL long long
#define LD long double
#define PR pair<int,int>

#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define Sz(s) int((s).size())
#define All(s) (s).begin(),(s).end()
#define Fill(s,v) memset(s,v,sizeof(s))
#define pb push_back
#define mp make_pair
#define x first
#define y second

template<typename T> T Abs(T x) { return(x<0 ? -x : x); }
template<typename T> T Sqr(T x) { return(x*x); }

const int INF = (int)1e9;
const LD EPS = 1e-12;
const LD PI = acos(-1.0);

string s;


int main() {
	cin >> s;
	int offset = s[0] == '1';
	int count = 0;

	for (int i = offset; i < s.length(); i++) {
		if ((i-offset)%2==0 && s[i]=='1') count++;
		else if ((i-offset)%2==1 && s[i]=='0') count++;
	}
	int ans = min(count, ((int)s.length())-count);

	cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s;
    int i,j;
    for(i=0;i<h;i++){
        string line;
        cin >> line;
        s.push_back(line);
    }

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

    int k;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(s.at(i).at(j)=='#') continue;
            int counter =0;
            for(k=0;k<8;k++){
                int x = j + dx[k];
                int y = i + dy[k];
                if(x<0 || x>=w) continue;
                if(y<0 || y>=h) continue;
                if(s.at(y).at(x)=='#') counter++;
            }
            s.at(i).at(j) = char(counter + '0');
        }
    }
    for (i=0;i<h;i++)
        cout << s.at(i) << endl;
    
}

Measured memory_bytes: 3632
/*
Êý¾Ý²»Çå¿Õ£¬±¬ÁãÁ½ÐÐÀá¡£
¶à²â²»¶ÁÍê£¬±¬ÁãÁ½ÐÐÀá¡£
±ß½ç²»ÌØÅÐ£¬±¬ÁãÁ½ÐÐÀá¡£
Ì°ÐÄ²»Ö¤Ã÷£¬±¬ÁãÁ½ÐÐÀá¡£
D P Ë³Ðò´í£¬±¬ÁãÁ½ÐÐÀá¡£
´óÐ¡ÉÙµÈºÅ£¬±¬ÁãÁ½ÐÐÀá¡£
±äÁ¿²»Í³Ò»£¬±¬ÁãÁ½ÐÐÀá¡£
Ô½½ç²»ÅÐ¶Ï£¬±¬ÁãÁ½ÐÐÀá¡£
µ÷ÊÔ²»×¢ÊÍ£¬±¬ÁãÁ½ÐÐÀá¡£
Òç³ö²» l l£¬±¬ÁãÁ½ÐÐÀá¡£
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),a[200005],b[200005],s[200005],t[200005];
bool ok[200005][32];
unsigned long long hs1[200005],hs2[200005],hsb=571,P[200005];
inline int get1(int l,int r){
	if(l>r)	return 0;
	return hs1[r]-hs1[l-1]*P[r-l+1];
}
inline int get2(int l,int r){
	if(l>r)	return 0;
	return hs2[r]-hs2[l-1]*P[r-l+1];
}
signed main(){
	P[0]=1;fz(i,1,n)	P[i]=P[i-1]*hsb;
	fz(i,1,n)	a[i]=read();
	fz(i,1,n)	b[i]=read();
	fz(i,0,30){
		fz(j,1,n)	s[j]=a[j]>>i&1;
		fz(j,1,n)	t[j]=b[j]>>i&1;
//		fz(j,1,n)	cout<<s[j];puts("");
//		fz(j,1,n)	cout<<t[j];puts("");
		memset(hs1,0,sizeof(hs1));
		memset(hs2,0,sizeof(hs2));
		fz(j,1,n){
			hs1[j]=(hs1[j-1]*hsb)+s[j];
			hs2[j]=(hs2[j-1]*hsb)+t[j];
		}
		fz(j,1,n){
			if(get1(1,j)==get2(n-j+1,n)&&get1(j+1,n)==get2(1,n-j))
				ok[j][i]=1;
		}
		fz(j,1,n)	s[j]^=1;
//		fz(j,1,n)	cout<<s[j];puts("");
//		fz(j,1,n)	cout<<t[j];puts("");
		memset(hs1,0,sizeof(hs1));
		memset(hs2,0,sizeof(hs2));
		fz(j,1,n){
			hs1[j]=(hs1[j-1]*hsb)+s[j];
			hs2[j]=(hs2[j-1]*hsb)+t[j];
		}
		fz(j,1,n){
			if(get1(1,j)==get2(n-j+1,n)&&get1(j+1,n)==get2(1,n-j))
				ok[j][i]=1;
		}
	}
	fz(i,0,n-1){
		bool flag=1;
		int ind=i;
		if(i==0)	ind=n;
		fz(j,0,30){
			if(!ok[ind][j])	flag=0;
		}
		if(flag)	cout<<i<<" "<<(a[ind]^b[n])<<endl;
	}
	return 0;
}

Measured memory_bytes: 17536
import numpy as np
n, m = (int(_) for _ in input().split())  
skp = [[int(i) for i in input().split()] for i in range(m+1)]
sk, p = skp[:-1], skp[-1]

def judge(sw_status, sk, p):
    sk = (np.array(sk) - 1).tolist()
    num = sw_status[[sk[1:]]].sum()%2
    if num == p:
        light = 1
    else:
        light = 0
    return light

ans = 0
for i in range(2**n):
    sw_status = np.array([j for j in bin(i)[2:].zfill(n)]).astype(int)
    for SK, P in zip(sk, p):
        j = judge(sw_status, SK, P)
        if j is 0:
            break
    if j is 1:
        ans += 1

print(ans)

Measured memory_bytes: 14188
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 101;
const int mod = 1e9+7;

long long powmod(long long a, long long b) {
	long long ret = 1;
	while(b) {
		if(b&1ll) ret*=a, ret%=mod;
		a*=a; a%=mod;
		b>>=1;
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	long long n; cin>>n;
	long long ans = powmod(10, n)+2*(mod-powmod(9, n))+powmod(8, n);
	ans%=mod;
	cout << ans << '\n';

	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
int main() {
	int r,d,x;

	cin >> r>>d>>x;

	vector<int> X(11);
	
	X.at(0) = x;
	for (int i = 0; i < 10; i++) {
		 X.at(i+1)=r*X.at(i)-d;
	}


	for (int i = 0; i < 10; i++) {
		cout << X.at(i+1) << endl;
	}

}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
     int W, H, x, y, r;
     scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x >= r && y >= r && (H - r) >= y && (W - r) >= x) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2104
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	var (
		mx  = math.MinInt64
		ans int
	)
	for i := 0; i < n; i++ {
		a, b := scanInt(), scanInt()
		if a > mx {
			mx = a
			ans = a + b
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3840
#include "bits/stdc++.h"
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
        if(abs(a[i]-a[j])%(n-1)==0){
          cout<<a[i]<<" "<<a[j]<<endl;
          return 0;
        }
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3168
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;

public class Main {

  static int n, ans;
  static char[] colors;
  static Set<Long> usd;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    colors = br.readLine().toCharArray();

    br.close();

    ans = 0;
    int l = 0, r = n - 1;

    while (l < r) {
      while (l < n && colors[l] == 'R') {
        l++;
      }
      while (r >= 0 && colors[r] == 'W') {
        r--;
      }
      if (l >= r) break;
      colors[l] = 'R';
      colors[r] = 'W';
      ans++;
    }

    out.println(ans);

    out.flush();
  }
}


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

#define ll long long
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define PP pair<P,int>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define all(a) (a).begin(),(a).end()


signed main()
{
    string st;
    cin>>st;
    if(st[0]=='9'||st[1]=='9'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// ??????g????????????????????\?????????
void insertionSort(int A[],int n,int g) {
  for (int i=g; i<n; i++) {
    int v = A[i];
    int j = i-g;
    while (j>=0 && A[j]>v) {
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  // ??°???G = {1, 4, 13, 40, 121, 364, 1093, ...}?????????
  for (int h=1; ;) {
    if (h>n) {
      break;
    }
    G.push_back(h);
    h = 3*h+1;
  }

  // ?????????G[i] = g?????????
  for (int i=G.size()-1; i>=0; i--) {
    insertionSort(A, n, G[i]);
  }
}

int main(void) {
  cin >> n;
  // ??????????????\???scanf??¢??°????????¨
  for(int i=0; i<n; i++) scanf("%d",&A[i]);
  cnt = 0;

  shellSort(A,n);

  cout << G.size() << endl;
  for(int i=G.size()-1; i>=0; i--) {
    printf("%d", G[i]);
    if(i) printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  for(int i=0;i<n;i++) printf("%d\n",A[i]);

  return 0;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    string s;
    cin >> s;
    if (s[0] == '9' || s[1] == '9')
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, x, m;
    cin >> n >> x >> m;

    // 累積和と出現位置
    vi sum(1, 0), pos(m+1, -1);
    sum[0] = x, pos[x] = 0;

    for(ll i=1; i<n; i++){
        x = (x*x)%m;
        sum.push_back(sum[i-1] + x);
        // これまでに出現していない場合
        if(pos[x] == -1) pos[x] = i;
        // これまでに出現している場合はループ長を検出
        else{
            // 1ループ当たりの長さとその区間和
            ll loopSize = i-pos[x];
            ll loopSum = sum[i] - sum[pos[x]];

            // 最後までに何回ループが含まれるかと端数分の処理
            ll loopTotal = ((n-pos[x])/loopSize)*loopSum;
            ll fractionSize = (n-pos[x])%loopSize;
            ll fraction = (fractionSize == 0 ? 0 : (pos[x] == 0 ? sum[fractionSize-1] : sum[pos[x]+fractionSize-1] - sum[pos[x]-1]));
            cout << (pos[x] == 0 ? 0 : sum[pos[x]-1]) + loopTotal + fraction << endl;
            return 0;
        }
    }
    // ループがなかった場合
    cout << sum[sum.size()-1] << endl;
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
#define INF (1LL<<50)
using namespace std;
typedef long long ll;
ll a[52],b[52];
ll n,m;
ll mem[52][52][52][52][2][3],used[52][52][52][52][2][3];
 
ll cal(ll arr[],int s,int g){
  ll res=0;
  while(s<g) res+=arr[s++];
  return res;
}
 
int saiki(int x,int y,int turn,int pass,int A,int B,ll sum){
  int nt=!turn;
  ll res,res2;
  res=res2=turn?INF:-INF;
 
  if(pass==3)return sum+(cal(a,A,x)-cal(b,B,y)); 
 
  if(used[x][y][A][B][turn][pass])return sum+mem[x][y][A][B][turn][pass];
  used[x][y][A][B][turn][pass]=1;
 
  if(x<n&&turn==0){
    if(!a[x]) res=saiki(x+1,y,nt,0,A,y,sum);
    else res=saiki(x+1,y,nt,0,A,B,sum);
  }
  if(y<m&&turn==1){
    if(!b[y])res=saiki(x,y+1,nt,0,x,B,sum);
    else res=saiki(x,y+1,nt,0,A,B,sum);
  }
  
 
  res2=saiki(x,y,nt,pass+1,x,y,sum+(cal(a,A,x)-cal(b,B,y)));  
  if(turn==0) res=max(res,res2);
  if(turn==1) res=min(res,res2);
  mem[x][y][A][B][turn][pass]=res-sum;
  return res;
}
 
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a[i],a[i]=max(0LL,a[i]);
  for(int i=0;i<m;i++) cin>>b[i],b[i]=max(0LL,b[i]);
  cout <<saiki(0,0,0,0,0,0,0)<<endl;  
  return 0;
}

Measured memory_bytes: 243732
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
li = []
for i in range(N):
    tmp = V[i] - C[i]
    li.append(tmp)
for i in range(N):
    if li[i] > 0:
        ans += li[i]
print(ans)

Measured memory_bytes: 3064
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l2.reverse()

stack1=[]
stack2=[]

for i in range(1, len(l1)+1):
  stack1.append(sum(l1[0:i]))
for i in range(1, len(l2)+1):
  stack2.append(sum(l2[0:i]))

stack2.reverse()

candy_max = 0
for i in range(n):
  candy = stack1[i] + stack2[i]
  if candy > candy_max:
    candy_max = candy
    
print(candy_max)

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

import sys
import os
import heapq

N = int(input())

A = list(map(int, input().split()))

B = A[:N]
B_sum = sum(B)
heapq.heapify(B)
dict_b = {}

for i in range(N, 2 * N):
    a = A[i]
    min_val = heapq.heappop(B)
    greater = max(a, min_val)
    heapq.heappush(B, greater)

    if greater != min_val:
        B_sum += (a - min_val)
    dict_b[i] = B_sum


C = A[-N:]
C = [-c for c in C]
C_sum = -1 * sum(C)
heapq.heapify(C)
dict_c = {}

for i in range(2 * N - 1, N - 1, -1):
    a = A[i]
    max_val = -1 * heapq.heappop(C)
    fewer = min(a, max_val)
    heapq.heappush(C, -fewer)

    if fewer != max_val:
        C_sum -= (max_val - a)
    dict_c[i] = C_sum

max_score = max(sum(A[:N]) - dict_c[N], dict_b[2*N-1] - sum(A[-N:]))
for i in range(N, 2 * N - 1):
    score = dict_b[i] - dict_c[i+1]
    if score > max_score:
        max_score = score

print(max_score)

Measured memory_bytes: 50056
##
#<6>wa
n = int(input())
s = list(input())
st = [set() for i in range(3)]
for a in s:
    for pre in st[1]:
        st[2].add(pre + a)#3桁目
    for pre in st[0]:
        st[1].add(pre + a)#2桁目
    st[0].add(a)#1桁目

print(len(st[2]))

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

const int MOD = 1000000007;
const int INF = 1e9;

const int max_fac = 5 * 1e5;
long long fac[max_fac], finv[max_fac], inv[max_fac];
void ComInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < max_fac; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long Comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  ComInit();
  long long ans = 0;
  for(int i = 1; i <= k; i++){
    ans = 0;
    int need = i - 1;
    int room = 2 + i - 1;
    int space = k - 1;
    int red = n - k - need;
    ans = Comb(space, need);
    ans %= MOD;
    ans *= Comb(room - 1 + red, red);
    ans %= MOD;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 15316
N = int(input())
h = list(map(int,input().split()))

INF = 10 ** 9 + 1
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, len(dp)):
  dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))
  
print(dp[N - 1])


Measured memory_bytes: 20652
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
const int inf_int=1e8;
const ll inf_ll=1e16;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double dbl;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
#define prev sdghjk
const int MX = 1e6+1;
const int MAXN = 4e5+100;
const int LOG = 20;
const ll mod =1e9;
#define x1 xvxbn
#define y1 afsdgjj

string a;

map<pair<ull,ull> ,int> mp;
ll ans = 0;
int n;
void gen(string a,bool flag){
    for(int mask = 0;mask<(1<<n);++mask){
        ull h1 = 0, h2 = 0;
        for(int i=0;i<n;++i){
            if(mask&(1<<i)){
                h1 = h1 * 29 + a[i];
            }
        }
        for(int i=n-1;i>=0;--i){
            if(!(mask&(1<<i))){
                h2 = h2 * 29 + a[i];
            }
        }
        if(flag){
            mp[{h1,h2}]++;
        } else{
            ans += mp[{h2,h1}];
        }
    }
}
void solve(){
    cin >> n;
    string a="",b="";
    for(int i=1;i<=n;++i)
    {
        char x;
        cin >> x; x = x - 'a'+1;
        a.pb(x);
    }
    for(int i=1;i<=n;++i){
        char x;cin >> x;x = x -'a'+1;
        b.pb(x);
    }
    gen(a,true);
    gen(b,false);
    cout << ans<<endl;



}


#define FILE "taxi"
signed main()
{
        #ifdef taow
            debug = 1;
           freopen("input.txt","r",stdin);
         //   freopen("output.txt","w",stdout);
        #endif // taow
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        cout.setf(ios::fixed);
        cout.precision(20);

        int t = 1;
        while(t--)
            solve();
}


Measured memory_bytes: 33024
n, m, x = map(int, input().split())
a = [int(i) for i in input().split()]

c1 = 0
for i in reversed(range(1, x)):
   if (i in a):
      c1 += 1

c2 = 0
for i in range(x+1, n):
   if (i in a):
      c2 += 1

if (c1 <= c2):
   print(c1)
else:
   print(c2)


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


int main() {

  int N;
  cin >> N;

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

  A.push_back(0);
  for(int i = 0;i < N;i++) {
    ans += A.at(i) / 2;
    if(A.at(i) % 2 == 1 && A.at(i+1) != 0) {
      ans++;
      A.at(i+1)--;
    }
  }

  cout << ans << endl;


}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

ll a[N] , b[N] ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll n ;
    cin >> n ;
    ll s= 0 ; 
    for (int i = 1  ; i <= n ; i ++) cin >> a[i], s += a[i] ;
    for (int i = 1 ; i <= n ; i ++) cin >> b[i] , s -= b[i] ;
    if (s < 0) return cout << -1 , 0 ;
    vector<ll> v ;
    //v.pb(-1e12) ;
    ll ans = 0 ;
    ll sum = 0 ;
    for (int i = 1 ; i <= n; i ++) {
    	if (a[i] < b[i]) {
    		ans ++ ;
    		sum += b[i] - a[i] ;
		}
		else v.pb(a[i] - b[i]) ;
	}
	sort(all(v)) ;
	reverse(all(v)) ;
	for (auto u : v) {
		if (!sum) break;
		sum -= min(sum , u) ;
		ans ++ ;
	}
	cout << ans ;
    return (0) ;
}

Measured memory_bytes: 2936
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI c(n - 1), s(n - 1), f(n - 1);
  REP(i, 0, n - 1) {
    cin >> c[i] >> s[i] >> f[i];
  }
  REP(i, 0, n) {
    int ans = 0;
    REP(j, i, n - 1) {
      ans = (max(ans, s[j]) + f[j] - 1) / f[j] * f[j];
      ans += c[j];
    }
    cout << ans << "\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  
  int ab = 0, b = 0;
  for (int i = 0; i < S.size(); i++)
  {
    string ans = "No";
    if (S.at(i) == 'a' && ab < A + B)
    {
      ans = "Yes";
      ab++;
    }
    else if (S.at(i) == 'b' && ab < A + B && b < B)
    {
      ans = "Yes";
      ab++;
      b++;
    }
    cout << ans << endl;
    //cerr << ab << " " << b << " " << endl;
  }
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;
  cin>>n>>k;
  vector<pair<ll,ll>>su(n);
  rep(i,n)
  {
    ll a,b;
    cin>>a>>b;
    su[i]={b,a};
  }
  //su[n]={0,1e9+7};
  sort(all(su),greater<pair<ll,ll>>());
  set<ll>used;
  vector<ll>id;
  rep(i,n)
  {
    if(!used.count(su[i].second)){used.insert(su[i].second);id.push_back(i);}
  }
  //cout<<"su"<<endl;
  //for(auto t:su)//cout<<t.first<<" "<<t.second<<endl;
//  for(auto t:id)//cout<<t<<endl;
  ////cout<<"idsize"<<id.size()<<endl;




  vector<ll>sum1(n+1),sum2(id.size()+1);
  rep(i,n)sum1[i+1]=su[i].first+sum1[i];
  rep(i,id.size())sum2[i+1]=su[id[i]].first+sum2[i];
  ll syurui=used.size();
  ll res=0LL;

//for(auto t:sum2)//cout<<t<<endl;



//cout<<" ednl"<<endl;;
  ll inid=upper_bound(all(id),k-1)-id.begin();
  //cout<<inid<<sum1[k]<<endl;
  res=(ll)inid*inid+sum1[k];
  inid--;
  ll idx=k-1;
  repi(i,1,1+min(k,syurui))
  {
    ll tres=i*i;
    ll maid=id[i-1];
    //cout<<" i"<<i<<endl;
    if(maid>k-1)
    {
      while(idx==id[inid])
      {
        inid--;
        idx--;
      }
      idx--;
      //cout<<"inid"<<inid<<endl;
      tres-=sum2[inid+1];
      tres+=sum2[i];
      tres+=sum1[idx+1];
      //cout<<"i"<<i<<idx<<id[inid]<<endl;
      //cout<<sum2[inid]<<endl;
      //cout<<sum2[i]<<endl;

      //cout<<sum1[k-num]<<endl;;
      //cout<<tres<<endl;
    }
    chmax(res,tres);
    //cout<<res<<endl;
  }
  cout<<res<<endl;

  return 0;

}


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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a[n+1];
    for(int i = 0; i <= n; i++)  cin >> a[i];
    if(n == 0){
        cout << (a[0]==1 ? 1 : -1) << endl;
        return 0;
    }else if(a[0] == 1){
        cout << (accumulate(a, a+n+1, 0ll) == 1 ? 1 : -1) << endl;
        return 0;
    }else if(a[0] > 1){
        cout << -1 << endl;
        return 0;
    }
    ll sum = accumulate(a, a+n+1, 0ll);
    ll ans = 1, avail = 1;
    for(int i = 1; i <= n; i++){
        if(i == n){
            if(avail*2 >= a[i]){
                cout << ans+a[i] << endl;
            }else{
                cout << -1 << endl;
            }
            return 0;
        }
        if(avail*2 < a[i]){
            cout << -1 << endl;
            return 0;
        }
        avail *= 2;
        avail = min(avail, sum);
        ans += avail;
        if(a[i] > 0){
            avail -= a[i];
            sum -= a[i];
        }
    }
}

Measured memory_bytes: 3980
open Scanf
open Printf

let rec scan_list = function
  | 1 -> scanf "%d" (fun k -> [k])
  | n -> scanf "%d " (fun k -> k :: scan_list (n-1))

let count = function
  | [] -> (0, [])
  | x::xs -> let rec f acc = function
      | [] -> (acc, [])
      | y::ys -> if x = y
        then f (acc + 1) ys
        else (acc, (y::ys))
    in f 1 xs

let rec f = function
  | [] -> 0
  | xs -> let c, ys = count xs in
    c / 2 + f ys

let () = let lst = scanf "%d\n" scan_list in
  printf "%d\n" (f lst)

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i <= 999; i++)
    {
        int a, b, c, d = i;
        c = d % 10;
        d /= 10;
        b = d % 10;
        d /= 10;
        a = d;
        int pos = 0;
        rep(j, n)
        {
            if (s[j] == (a + '0') && pos == 0)
                pos++;
            else if (s[j] == (b + '0') && pos == 1)
                pos++;
            else if (s[j] == (c + '0') && pos == 2)
                pos++;
        }
        if (pos == 3)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
///a = 97  z = 122
///A = 65  Z = 90

#include <bits/stdtr1c++.h>

using namespace std;

#define endl                "\n"
#define pb                  push_back
#define pii                 pair<int, int>
#define mp                  make_pair
#define x                   first
#define y                   second
#define all(v)			    ((v).begin()), ((v).end())
#define sz(v)			    ((int)((v).size()))
#define ll                  long long
#define rep(i,n)            for(int i=0 ; i<sz(n) ; i++)
#define lp(i, n)            for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define ms(arr, v)      memset(arr, v, sizeof arr)
typedef vector<vector<char>> vcc;
typedef vector<int> vi;
typedef deque<int> de;

const int N = 2e5 + 10;
int arr[N];
int _fixed[N];
int n;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif*/
    cin >> n;
    lp(i,n)
    {
        cin >> arr[i];
        _fixed[i] = arr[i];
    }
    sort(arr, arr+n);
    lp(i, n)
    {
        if(arr[n-1] == _fixed[i]) cout << arr[n-2] << endl;
        else cout << arr[n-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
n = int(input())
o = ""
for i in range(1, n+1):
    if (i % 3) == 0:
        o = o + " " + str(i)
    
    else:
        x = i
        while x >0:
            if (x % 10) == 3:
                o = o + " " + str(i)
                break
            x //= 10
    
print(o)

Measured memory_bytes: 7640
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 3e5 + 11;
const int mod=998244353;

double eps = 1e-9;

unordered_map<int,int>mpp2[1000],mpp5[1000];
int mx;
LL cal2(int a,int b){
    LL res = 0;
    fo(i,0,a) {
        for(auto to:mpp2[i]){
            if(i+b+to.first>=0) res+=to.second;
        }
    }
    fo(i,a+1,mx){
        for(auto to:mpp2[i]){
            if(a+b+to.first>=0) res+=to.second;
        }
    }
    return res;
}
LL cal5(int a,int b){
    LL res = 0;
    fo(i,0,a) {
        for(auto to:mpp5[i]){
            if(i+b+to.first>=0) res+=to.second;
        }
    }
    fo(i,a+1,mx){
        for(auto to:mpp5[i]){
            if(a+b+to.first>=0) res+=to.second;
        }
    }
    return res;
}


char s[maxn];
int main(){
//    op;
    int n;
    read(n);
    LL ans = 0;
    fo(i,1,n){
        scanf("%s",s);

        int len = strlen(s);
        LL nw = 0;
        int d=0;

        fo(i,0,len-1){
            if(s[i]=='.') d = i-len+1;
            else{
                nw = nw*10+s[i]-'0';
            }
        }
        int n2=0,n5=0;
        while(nw%2==0) n2++,nw/=2;
        while(nw%5==0) n5++,nw/=5;


        int mi = min(n2,n5);
        n2-=mi;n5-=mi;
        mx=max(mx,n2);
        mx=max(mx,n5);
        d+=mi;


        if(n2){
            ans+=cal5(n2,d);
        }
        else{
            ans+=cal2(n5,d);
        }
        mpp2[n2][d]++;
        mpp5[n5][d]++;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3916
n,m=map(int,input().split())
q=[None]*m
for i in range(m):
  a,b=map(int,input().split())
  q[i]=[a,b]
q=sorted(q,key=lambda x:x[1])
cut=-1
ans=0
for i in range(m):
  if q[i][0]>=cut:
    ans+=1
    cut=q[i][1]
print(ans)

Measured memory_bytes: 22108
#include<iostream>
        #include <string>
       #include <algorithm>
        using namespace std; 
         
        int main(){
        std :: string A,B,C;
        int lenA,lenB, lenC;
        int i, j, k;
        char turn;
        cin >> A >> B >>C;
        lenA = A.size();
        lenB = B.size();
        lenC = C.size();
        i = j = k =0;
       turn ='a';
        while(1){
        if(i == lenA &&(turn =='a')){
        cout << 'A';
        break;
        }
        else if(j == lenB&&(turn =='b')){
        cout << 'B';
        break;
        }
        else if(k == lenC&&(turn =='c')){
        cout << 'C';
        break;
        }
        else if (turn == 'a'){
        turn = A[i];
        i++;
        }
       else if (turn == 'b'){
        turn = B[j];
        j++;
        }  else if (turn == 'c'){
        turn = C[k];
        k++;
        }
     }
        return 0;
    }

Measured memory_bytes: 256