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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO() \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

#define what_is(args ...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename ...Args>
void err(istream_iterator<string> it, T a, Args ...args) {
    cerr << *it << " = " << a << endl;
    err(++it, args ...);
}


int main() {
    int N;
    cin >> N;
    vi a(N);
    for (auto &i : a)   cin >> i;
    int n = 303;
    vector<vector<vector<ld>>> dp(n+1, vector<vector<ld>>(n+1, vector<ld>(n+1, 0.0)));
    for (int k = 0; k <= N; ++k) {
        for (int j = 0; j <= N; ++j) {
            for (int i = 0; i <= N; ++i) {
                if (i+j+k <= 0 || i+j+k > N) continue;
                dp[i][j][k] = 0;
                if (i >= 1)
                    dp[i][j][k] += ld(i) * dp[i-1][j][k];
                if (j >= 1)
                    dp[i][j][k] += ld(j) * dp[i+1][j-1][k];
                if (k >= 1)
                    dp[i][j][k] += ld(k) * dp[i][j+1][k-1];
                assert(i + j + k > 0);
                dp[i][j][k] = (dp[i][j][k] + N)/(i + j + k);
                //cerr << i << " " << j << " " <<k << " -> " << dp[i][j][k] << endl;
            }
        }
    }
    int i, j, k;
    i = j = k = 0;
    for (auto x : a) {
        if (x == 1) ++i;
        else if (x == 2) ++j;
        else    if (x == 3) ++k;
    }
    assert(i + j + k >= 0 && i + j + k <= N);
    cout << fixed << setprecision(12);
    cout << dp[i][j][k] << endl;
    return 0;
}


Measured memory_bytes: 446336
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int grid[2][100];

int dp[2][100];

int n;

int solve(int row, int col)
{
    if (row == 2) return 0;
    if (col == n) return 0;
    
    if (dp[row][col]) return dp[row][col];

    return dp[row][col] = max(solve(row+1, col)+grid[row][col], solve(row, col+1)+grid[row][col]);
}

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    
    cin >> n;
    
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < n; j++) cin >> grid[i][j];
    
    cout << solve(0,0) << '\n';
    
    return 0;
    
}




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

int main() {
  int a, b, c, d, e;
  
  cin >>  a >>  b >> c >> d >> e;
  
  if (a != 1) {
    cout << 1 << endl;
  }
  else if  (b != 2) {
    cout << 2 << endl;
  }
  else if  (c != 3) {
    cout << 3 << endl;
  }
  else if  (d != 4) {
    cout << 4 << endl;
  }
  else if  (e != 5) {
    cout << 5 << endl;
  }
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  vector<int> sa(s.size()+1, 0);
  vector<int> ta(t.size()+1, 0);
  rep(i, s.size()){
    sa.at(i+1) = sa.at(i);
    if(s.at(i) == 'A') sa.at(i+1)++;
    else sa.at(i+1) += 2;
  }
  rep(i, t.size()){
    ta.at(i+1) = ta.at(i);
    if(t.at(i) == 'A') ta.at(i+1)++;
    else ta.at(i+1) += 2;
  }

  int q;
  cin >> q;
rep(_q, q){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a--; c--;
  int gs = sa.at(b) - sa.at(a);
  int gt = ta.at(d) - ta.at(c);
  if(gs % 3 == gt % 3) cout << "YES" << endl;
  else cout << "NO" << endl;
}
  return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

typedef pair<int, int> P;

vector<P> v;

bool issquare(int i, int j) {
    P p1 = v[i]; P p2 = v[j];
    int p1top2x = p2.first - p1.first;
    if (p1top2x <= 0) return false;
    int p1top2y = p2.second - p1.second;
    if (p1top2y > 0) return false;
    P q1 = make_pair(p1.first - p1top2y, p1.second + p1top2x);
    P q2 = make_pair(p2.first - p1top2y, p2.second + p1top2x);
    if (binary_search(v.begin() + i, v.end(), q1) &&
        binary_search(v.begin() + j, v.end(), q2)) {
        return true;
    }else {
        return false;
    }
}

void solve18(int a) {
    v.clear();
    REP(i,a) {
        int p, q;
        scanf("%d%d", &p, &q);
        v.push_back(make_pair(p,q));
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < a - 1; i++) {
        for(int j = i + 1; j < a; j++) {
            if (issquare(i, j)) {
                int r = v[i].first - v[j].first;
                int s = v[i].second - v[j].second;
                ans = max(ans, r*r + s*s);
            }
        }
    }
    cout << ans << endl;
}


int main() {
    int a;
    while(cin >> a, a) {
        solve18(a);
    }
    return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <cstdio>
#include <algorithm>
#define M 200009
using namespace std;
int k,n,a[M],d[M];
int main(){
  scanf("%d%d",&k,&n);
  for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
  for(int i = 1; i <= n; i++) d[i] = a[i] - a[i-1];
  d[1] = k - a[n] + a[1];
  cout << k - *max_element(d+1,d+n+1);
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int mxr[205];
bool calc()
{
	for(int i=1;i<=n;i++)
	{
		if(mxr[i]%2!=0)
			return false;
	}
	return true;
}
int main()
{
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&mxr[i]);
	while(1)
	{
		if(calc()) ans++;
		else{
			printf("%d\n",ans);
			break;
		}
		for(int i=1;i<=n;i++)
			mxr[i]/=2;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
Z = [0 for _ in range(n)]
ans = 0
for begin in range(n):
    Z[begin] = n-begin
    i = begin + 1
    j = 0
    while i < n:
        while i+j < n and s[begin+j] ==s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+Z[begin+k] < j:
            Z[i+k] = Z[begin+k]
            k += 1
        i += k
        j -= k
    for i in range(begin,n):
        l = min(i-begin,Z[i])
        ans = max(ans,l)
print(ans)


Measured memory_bytes: 49116
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;
  pair<pair<string, int>,int> rest[SIZE];

  cin >> n;

  for(int i=0; i<n; i++) {
    int p;
    string s;

    cin >> s >> p;

    rest[i] = {{s, -p}, i+1};
  }

  sort(rest, rest+n);

  for(int i=0; i<n; i++)
    cout << rest[i].second << endl;


  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;
    int ans = INF;
    for (int i = 0; i < (int)S.size(); i++) {
        if (i + (int)T.size() > (int)S.size()) break;
        int cnt = 0;
        for (int j = 0; j < (int)T.size(); j++) {
            if (S[i + j] != T[j]) cnt++;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


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

int counts=0;

void print(int a[],int n){
  for(int i=0;i<n;i++){
      cout<<a[i]<<endl;
  }
}

void insertionSort(int a[],int n,int g){ //小さい順に並べる
  int i,j;
  for(i=g;i<n;i++){
    int v=a[i];
    j=i-g;
    while(j>=0&&a[j]>v){
      a[j+g]=a[j];
      j-=g;
      counts++;
    }
    a[j+g]=v;
  }
}

void shellSort(int a[],int n){
    int m=0,G[101],i;

    G[0]=0;
    while(1){
        if(G[m]*3+1>n)break;
        G[m+1]=G[m]*3+1;
        m++;
    }

    cout<<m<<endl;
    for(i=m;i>0;i--){
        if(i<m)cout<<" "<<G[i];
        else cout<<G[i];
        insertionSort(a,n,G[i]);
    }
    cout<<endl<<counts<<endl;
    print(a,n);
}

int main(){
  int i,j,v,n,a[1000001];
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  
  shellSort(a,n);

  return 0;
}


Measured memory_bytes: 7008
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

struct edge{
  int to, cost;
};
vector<edge> g[MAX];
int N, M;

bool used[MAX];
int d[MAX];
bool ans;

void bfs(int v, int dist){
  if(used[v] && d[v] != dist) {
    // DEBUG(v);
    // DEBUG(dist);
    ans = false;
  }
  if(used[v]) return;
  d[v] = dist;
  used[v] = true;
  for(edge u : g[v]){
    bfs(u.to, dist + u.cost);
  }
}

int main(int argc, const char * argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  cin >> N >> M;
  ans = true;
  rep(i, M){
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    g[l].push_back({r, d});
    g[r].push_back({l, -d});
  }

  memset(d, -1, sizeof(d));
  memset(used, 0, sizeof(used));
  rep(i, N){
    if(used[i]) continue;
    bfs(i, 0);
  }

  if(ans){
    cout <<  "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}  


Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

ll gcd(ll x, ll y) {
	int r = 0;
	if (x < y) swap(x, y);

	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int cur;
	cin >> cur;
	REP(i, N - 1) {
		int a;
		cin >> a;
		cur = gcd(a, cur);
	}
	cout << cur <<  endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        mut v: [usize; n]
    }
    v.sort();
    for i in 0..n - 1 {
        if v[i] == v[i + 1] {
            println!("NO");
            return;
        }
    }
    println!("YES");
}


Measured memory_bytes: 6396
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            String s = in.nextString();
            String[] arr = s.split("-");
            if (arr.length == 2 && arr[0].length() == n && arr[1].length() == m)
                out.println("Yes");
            else out.println("No");
        }

    }

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

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 24788
n = gets.to_s.to_i
a = gets.to_s.split.map{|t| t.to_i }.sort

c = a.dup
(n-1).times{ |i| c[i+1] += c[i] }

ans = 1
2.upto(n) do |i|
  
  if a[-i] == a[-i+1]
    ans += 1
  else
    if a[-i+1] <= c[-i] * 2
      ans += 1
    else
      break
    end
  end
end

puts ans

Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int r = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i]) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
S = list(input())
C_cnt,low,upp = 0,0,0
if S[0] != "A" or S[-1].isupper() or S[1].isupper():
  print("WA")
  sys.exit()
for i in range(2,len(S)-1):
  if S[i] == "C":
    C_cnt += 1
  elif S[i].islower():
    low += 1
  elif S[i].isupper():
    upp += 1
if C_cnt == 1 and low == len(S)-4 and upp == 0:
  print("AC")
else :
  print("WA")


Measured memory_bytes: 9020
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
string s, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> s >> t;
  s[n] = ' ', t[n] = ' ';

  REP(i, n + 1) {
    if(s.substr(i) == t.substr(0, (n - i))) {
      cout << (i * 2) + (n - i) << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,num[ohara],syu;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
set<ll> st;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n){
        cin>>a;
        num[a]++;
        st.insert(a);
    }
    syu=Size(st);
    sort(num,num+200000);
    rep(i,200001){
        if(syu<=k)break;
        if(num[i]==0)continue;
        syu--;
        ans+=num[i];
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9


int main(){
    ll h,w,n;
    cin>>h>>w>>n;
    map<pair<ll,ll>,int> m;
    rep(i,n){
        int y,x;cin>>y>>x;
        range(j,0,3)range(k,0,3){
            if(3<=y+j&&y+j<=h&&3<=x+k&&x+k<=w){
                //cout<<y+j<<","<<x+k<<endl;
                auto p=mp(y+j,x+k);
                if(m.find(p)==m.end()){
                    m[p]=0;
                }
                m[p]++;
            }
        }
    }
    vector<ll> a(10,0);
    ll total=0;
    for(auto p:m){
        a[p.second]++;
        total++;
    }
    a[0]=(h-2)*(w-2)-total;
    for(auto i:a)cout<<i<<endl;
	return 0;
}


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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> p(N);
  for (int i=0;i<N;i++){
    cin >> p[i];
    p[i]--;
  }
  UnionFind tree(N);
  for (int i=0;i<M;i++){
    int x,y;
    cin >> x >> y;
    tree.unite(x-1,y-1);
  }
  int ans=0;
  for (int i=0;i<N;i++){
    if (tree.same(i,p[i])){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
    string s;
    std::cin >> s;
    
    ll n =s.size();
    
    for (int i = n/2-1; i >=1; i--) {
        bool ok = true;
        for (int j = 0; j < i; j++) {
            if(s[j]!=s[j+i]){
                ok = false;
            }
        }
        if(ok){
            std::cout << i*2 << std::endl;
            return 0;
        }
    }
}



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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //  cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        int a[n];
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        sort(a, a + n);
        int ans = 0;
        for (int i = 0; i < m; ++i)
            ans += a[i];
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  if(s[0]==s[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
int a[5], k;
int main() {
	for (int i = 0; i < 5; i++) {
		scanf("%d", &a[i]);
	}
	scanf("%d", &k);
	if (a[4] - a[0] > k) {
		printf(":(\n");
	}
	else {
		printf("Yay!\n");
	}
	return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<P> job(n);
    for(int i=0; i<n; i++){
        ll x,l;cin>>x>>l;
        job[i]=P(x+l,x-l);
    }
    sort(job.begin(),job.end());
    ll ans=0, end = -INF;
    for(int i=0; i<n; i++){
        if(end>job[i].second)continue;
        else{ans++;end=job[i].first;}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> a >> b;
  if (b >= a)
  {
    cout << "unsafe" << endl;
  }
  else
  {
    cout << "safe" << endl;
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;


    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(n):
    if i==0:
        dp[i] = 0
    elif i==1:
        dp[i] = abs(h[i]-h[i-1])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

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

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

int size;
vector<int> dat,lazy;

void init(int n){
  size = 1;
  while(size<n) size *= 2;
  dat.assign(2*size-1,INF);
  lazy.assign(2*size-1,-1);
}
void update(int a,int b,int x,int k,int l,int r){
  if(b<=l||r<=a) return;
  else if(a<=l&&r<=b){
    dat[k] = lazy[k] = x;
  }else{
    if(lazy[k]>=0&&k<size-1){
      lazy[2*k+1] = lazy[2*k+2] = lazy[k];
      dat[2*k+1] = dat[2*k+2] = lazy[k];
      lazy[k] = -1;
    }
    update(a,b,x,2*k+1,l,(l+r)/2);
    update(a,b,x,2*k+2,(l+r)/2,r);
    dat[k] = min(dat[2*k+1],dat[2*k+2]);
  }
}
int query(int a,int b,int k,int l,int r){
  if(b<=l||r<=a) return INF;
  else if(a<=l&&r<=b) return dat[k];
  else{
    if(lazy[k]>=0&&k<size-1){
      lazy[2*k+1] = lazy[2*k+2] = lazy[k];
      dat[2*k+1] = dat[2*k+2] = lazy[k];
      lazy[k] = -1;
    }
    return min(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }
}

int main(){
  int n,q;
  scanf("%d %d",&n,&q);
  init(n);
  for(int i=0;i<q;i++){
    int cmd;
    scanf("%d",&cmd);
    if(cmd==0){
      int s,t,x;
      scanf("%d %d %d",&s,&t,&x);
      update(s,t+1,x,0,0,size);
    }else if(cmd==1){
      int s,t;
      scanf("%d %d",&s,&t);
      printf("%d\n",query(s,t+1,0,0,size));
    }
  }
  return 0;
}

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

int main() {
    int A,B,K;
    cin >> A >> B >> K;
    for(int i=1;i<=K;i++){
        if(i%2==1){
            A/=2;
            B+=A;
        }
        else{
            B/=2;
            A+=B;
        }
    }
    cout << A << " " << B << endl;

}

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

using namespace std;

const int N = 1e5 + 5;
int a[N] , n;
long long c[N] , k;

pair<bool , long long> can (int m) {
    long long g = 0 , g_cnt = 0 , ge_cnt = 0;
    for (int i = 0 ;i < n ;i++) {
        int l = 0 , r = n - 1 , ind = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (a[i] + a[mid] > m) {
                ind = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }

        if (~ind) {
            int len = ind + 1;
            g_cnt += len;
            g += a[i] * 1ll * len + c[ind];
        }

        l = 0 , r = n - 1 , ind = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (a[i] + a[mid] >= m) {
                ind = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }

        if (~ind) {
            int len = ind + 1;
            ge_cnt += len;
        }
    }

    if (ge_cnt >= k)
        return {1 , g + (k - g_cnt) * m};

    return {0 , 0};
}

int main() {
    cin >> n >> k;
    for (int i = 0 ;i < n ;i++)
        cin >> a[i];

    sort(a , a + n , greater<int>());

    c[0] = a[0];
    for (int i = 1 ;i < n ;i++)
        c[i] = a[i] + c[i - 1];

    long long ans = -1;
    int l = 2 , r = 2e5 + 5;
    while (l <= r) {
        int mid = (l + r) / 2;
        auto g = can(mid);
        if (g.first) {
            ans = g.second;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }

    cout << ans;
}

Measured memory_bytes: 1408
import bisect
N = int(input())
ans = 0
L = list(map(int,input().split()))
L = sorted(L)
for i in range(N-1):
    for j in range(i+1,N):
        a = bisect.bisect(L,L[i]+L[j]-1)
       
        ans += a-j-1

print(ans)        
         
        

Measured memory_bytes: 3316
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			long ans = 0;
			long pre = 0;
			for (int i = 0; i < n; i++) {
				long count = cin.Long();
				if (count == 0) {
					pre = 0;
					continue;
				}

				count += pre;
				ans += count / 2;
				pre = count % 2;
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 15308
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int    
#define mod 1000000007
using namespace std;
int main()
{	
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans = 0;
	if(k<=a)
		ans=k;
	else if(k<=a+b)
	{
		ll x=k-a;
		ans = a;
	}
	else
	{
		ll x=k-a-b;
		ans=a+x*(-1);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int s[13];
    int h[13];
    int c[13];
    int d[13];
    for(int i=0;i<13;i++){
        s[i]=0;
        h[i]=0;
        c[i]=0;
        d[i]=0;
    }
    for(int i=0;i<n;i++){
        char a;
        int x;
        cin>>a>>x;
        if(a=='S'){
            s[x-1]++;
        }
        else if(a=='H'){
            h[x-1]++;
        }
        else if(a=='C'){
            c[x-1]++;
        }
        else{
            d[x-1]++;
        }
    }
    for(int i=0;i<13;i++){
        if(s[i]){
            ;
        }
        else{
            cout<<"S "<<i+1<<endl;
        }
    }
    for(int i=0;i<13;i++){
        if(h[i]){
            ;
        }
        else{
            cout<<"H "<<i+1<<endl;
        }
    }
    for(int i=0;i<13;i++){
        if(c[i]){
            ;
        }
        else{
            cout<<"C "<<i+1<<endl;
        }
    }
    for(int i=0;i<13;i++){
        if(d[i]){
            ;
        }
        else{
            cout<<"D "<<i+1<<endl;
        }
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
struct point
{
	int x,y,c;
	operator int()const{return x;}
}p[1000];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=2*n;i++)cin>>p[i].x>>p[i].y,p[i].c=i>n;
	sort(p+1,p+1+n+n);
	set<int> s;
	int ans=0;
	for(int i=1;i<=2*n;i++)
		if(p[i].c&&!(s.empty()||*s.begin()>p[i].y))s.erase(--s.lower_bound(p[i].y)),ans++;
		else if(!p[i].c)s.insert(p[i].y);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
nums = [0 for _ in range(N+1)]

for n in range(1, N+1):
    if n % 2 == 0:
        nums[n] = nums[n//2] + 1

ans = 0
max_nums = max(nums)
for n in range(1, N+1):
    if nums[n] == max_nums:
        print(n)
        break


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

std::string s;
int g_cou, p_cou, ans;

int main()
{
	std::cin >> s;

	for (auto& i : s)
	{
		if (i == 'g')
		{
			if (p_cou >= g_cou)
			{
				++g_cou;
			}
			else
			{
				++ans;
				++p_cou;
			}
		}
		else
		{
			if (p_cou >= g_cou)
			{
				--ans;
				++g_cou;
			}
			else
			{
				++p_cou;
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


std::vector<LL> dijkstra(int s,int N,vector<Edge> E){
    std::vector<LL> ans(N,LINF);
    std::vector<std::vector<Edge>> Edges(N);
    for(auto e : E){
        Edges.at(e.from).push_back(e);
    }
    priority_queue<pair<LL,LL>, std::vector<pair<LL,LL>>, greater<pair<LL,LL>>> que;
    ans.at(s)= 0;
    que.push(make_pair(0,s));
    while(!que.empty()){
        pair<LL,LL> p = que.top();que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
                if(ans.at(p.second) + Edges.at(p.second).at(i).value < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).value;
                que.push(make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}
int main(){
    int n,m;cin >> n >> m;
    vector<Edge> vec;
    for(int a = 0;a < m;a++){
        int b,c;cin >> b >> c;
        b--,c--;
        for(int i = 0;i < 3;i++){
            vec.push_back(Edge(b + i*n, c + (((i+1)%3)*n), 1));
        }
    }
    int a,b;cin >> a >> b;
    a--,b--;
    /*
    for(int i = 0;i < vec.size();i++){
        cout<<vec.at(i).from<<" "<<vec.at(i).to<<endl;
    }
    */

    vector<LL> dist = dijkstra(a,3*n+1,vec);
 //   cout<<"A"<<endl;
    if(dist.at(2*n+b) == LINF){
        cout<<-1<<endl;
    }else{
        cout<<dist.at(b)/3<<endl;
    }
}


Measured memory_bytes: 27756
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto i = (m).begin(); i != (m).end(); ++i)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int dfs(ll n, ll up, bool a, bool b, bool c) {
  ll ans = 0;
  if (n <= up) {
    if (a && b && c)
      ans++;
    ans += dfs(n * 10 + 3, up, true, b, c);
    ans += dfs(n * 10 + 5, up, a, true, c);
    ans += dfs(n * 10 + 7, up, a, b, true);
  }

  return ans;
}

int main() {
  ll N, ANS = 0;
  vector<ll> A;
  cin >> N;
  cout << dfs(0, N, false, false, false) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    long MOD = 1_000_000_007;
    void solve(Scanner sc, PrintWriter pw) {
        int K = sc.nextInt();
        String S = sc.next();
        int L = S.length();
        long combination = 1;
        long a = 1;
        long b = power(26, K);
        long result = (combination * a * b) % MOD;
        long inverse26 = power(26, MOD - 2);
        //System.out.println(String.format("%d %d %d", combination, a, b));
        for (int w = 1; w <= K; w++) {
            combination = (((combination * (w - 1 + L)) % MOD) * power(w, MOD - 2)) % MOD;
            a = (a * 25) % MOD;
            b = (b * inverse26) % MOD;
            result = (result + (combination * ((a * b) % MOD))%MOD) % MOD;
            //System.out.println(String.format("%d %d %d", combination, a, b));
        }
        pw.println(result);
    }

    private long power(int v, long k) {
        if (k == 0) {
            return 1;
        }
        long part = power(v, k / 2);
        long candidate = (part * part) % MOD;
        if ((k % 2) > 0) {
            candidate = (candidate * v) % MOD;
        }
        return candidate;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 46596
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
int main()
{
  int N;
  std::cin >> N;

  std::vector<std::pair<int, int>> a;
  for (int i = 1; i <= N; i++) {
    int no;
    std::cin >> no;
    a.push_back(std::make_pair(no, i));
  }

  std::sort(std::begin(a), std::end(a));

  for (auto & p : a) {
    std::cout << p.second << " ";
  }
  std::cout << std::endl;

  return 0;

}



Measured memory_bytes: 1780
def main():
	import sys
	input=sys.stdin.readline
	h,w,n=map(int,input().split())
	ans=[0]*10
	p=set()
	q=set()
	for i in range(n):
		a,b=map(int,input().split())
		for j in range(-1,2):
			for k in range(-1,2):
				if 2<=a+j<=h-1 and 2<=b+k<=w-1:
					r=(a+j)*(10**10)+b+k
					p.add(r)
		q.add(a*(10**10)+b)
	p=list(p)
	for x in p:
		cnt=0
		for j in range(-1,2):
			for k in range(-1,2):
				if x+j*(10**10)+k in q:
					cnt+=1
		ans[cnt]+=1
	print((h-2)*(w-2)-sum(ans[1:]))
	for i in range(1,10):
		print(ans[i])
if __name__ == '__main__':
	main()

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

long long int w[51];
long long int b[51];
long long int p[51];

void burg(int n){
    w[0]=1; b[0]=0; p[0]=1;
    for(int i=0;i<n;i++){
        b[i+1]=2+2*b[i];
        p[i+1]=1+2*p[i];
        w[i+1]=b[i+1]+p[i+1];
    }
}
long long int answer(long long int y,int level){
    if(y==0)return 0;
    else if(y==w[level] || y==w[level]-1)return p[level];
    else if(y==1)return 0;
    else if(y>=2+w[level-1])return 1+p[level-1]+answer(y-2-w[level-1],level-1);
    else return answer(y-1,level-1);
}
int main(){
    int n;
    long long int x;
    cin >> n >> x;
    burg(n);
    cout << answer(x,n) << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)

int main()
{
	string w;
	cin >> w;
	unordered_map<char, int> m;

	rep(i, w.size())
	{
		++m[w[i]];
	}

	bool isBeautiful = true;
	for (auto e : m)
	{
		if (e.second % 2 == 1)
		{
			isBeautiful = false;
			break;
		}
	}

	cout << (isBeautiful ? "Yes" : "No") << endl;

	return 0;
}

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

Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define SQ 320
//#define N 1000005
typedef long long ll;
using namespace std;
ll n,i,j,k,x,y,z,q,r,timer,mx,m;

ll a[100500], used[100500];
vector<ll> g[100500];
void dfs(ll v, ll p)
{
    if (used[v])
    {
        if ((p^a[v]) != 0)
        {
            cout << n*(n-1)/2-m << endl;
            exit(0);
        }
        return;
    }
    used[v] = 1;
    a[v] = p;
    for (int i = 0; i < g[v].size(); i++)
        dfs(g[v][i], 1-p);
}
int main() {
    //freopen("input.txt","r",stdin);
    cin >> n >> m;
    for (i = 0; i < m; i++)
    {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1, 0);
    x = 0;
    for (i = 1; i <= n; i++)
        x += a[i];
    cout << (n-x)*x-m << endl;
    return 0;
}


Measured memory_bytes: 8192