akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int main(){
    int n;
    while(cin >> n, n){
        vector <pair <int, int> > mato;
        int h, r;
        for(int i = 0; i < n; i++){
            cin >> h >> r;
            mato.push_back(make_pair(h, r));
        }
        int m;
        cin >> m;
        for(int i = 0; i < m; i++){
            cin >> h >> r;
            mato.push_back(make_pair(h, r));
        }
        sort(mato.begin(), mato.end());
        int sum[n + m] = {1}, ans = 0;
        for(int i = 1; i < n + m; i++){
            int macs= 0;
            for(int j = 0; j < i; j++){
                if(mato[i].first > mato[j].first && mato[i].second > mato[j].second)
                    macs = max(macs, sum[j]);
            }
            sum[i] = macs + 1;
            ans = max(ans, sum[i]);
        }
        cout << ans << endl;
    }
    
}

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

int main()
{
    // int a,b;
    string a,b;
    cin >> a >> b;
    int plus = stoi(a+b);
    for (int i=1; i<1000; ++i)
    {
        if(plus == i*i)
        {
            cout << "Yes" << endl;
            return 0;
        } 
    }

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

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  int n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i,n) {
    cin >> a[i] >> b[i];
  }

  ll inf = 1LL << 60;
  ll mini = inf;
  ll sum = 0;
  rep(i,n) {
    if(a[i] > b[i]) chmin(mini, b[i]);
    sum += a[i];
  }
  if(mini == inf) {
    cout << 0 << "\n";
  }
  else {
    cout << sum - mini << "\n";
  }
  
  
  return 0;
}


Measured memory_bytes: 512
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]
if s[0] == 'AB'and a == 0 and b == 0:
    print('No')
elif s[0] == 'BC' and b == 0 and c == 0:
    print('No')
elif s[0] == 'AC' and a == 0 and c == 0:
    print('No')
elif a + b + c >= 2:
    print('Yes')
    ans = []
    for i in range(n):
        if i < n - 1:
            if a == b == 1 and c == 0 and s[i] == 'AB':
                if s[i + 1] == 'AB' or s[i + 1] == 'AC':
                    ans.append('A')
                    a += 1
                    b -= 1
                else:
                    ans.append('B')
                    a -= 1
                    b += 1
                continue
            elif b == c == 1 and a == 0 and s[i] == 'BC':
                if s[i + 1] == 'AB' or s[i + 1] == 'BC':
                    ans.append('B')
                    c -= 1
                    b += 1
                else:
                    ans.append('C')
                    c += 1
                    b -= 1
                continue
            elif a == c == 1 and b == 0 and s[i] == 'AC':
                if s[i + 1] == 'AB' or s[i + 1] == 'AC':
                    ans.append('A')
                    a += 1
                    c -= 1
                else:
                    ans.append('C')
                    a -= 1
                    c += 1
                continue
        if s[i] == 'AB':
            if a <= b:
                ans.append('A')
                a += 1
                b -= 1
            else:
                ans.append('B')
                a -= 1
                b += 1
        elif s[i] == 'BC':
            if b <= c:
                ans.append('B')
                b += 1
                c -= 1
            else:
                ans.append('C')
                b -= 1
                c += 1
        else:
            if a <= c:
                ans.append('A')
                a += 1
                c -= 1
            else:
                ans.append('C')
                a -= 1
                c += 1
    for c in ans:
        print(c)
elif a == b == c == 0:
    print('No')
else:
    ans = []
    if a == 1:
        t = 0
    elif b == 1:
        t = 1
    else:
        t = 2
    for i in range(n):
        if s[i] == 'AB' and t == 2 or s[i] == 'BC' and t == 0 or s[i] == 'AC' and t == 1:
            print('No')
            exit(0)
        elif s[i] == 'AB':
            if t == 0:
                ans.append('B')
                t = 1
            else:
                ans.append('A')
                t = 0
        elif s[i] == 'BC':
            if t == 1:
                ans.append('C')
                t = 2
            else:
                ans.append('B')
                t = 1
        else:
            if t == 0:
                ans.append('C')
                t = 2
            else:
                ans.append('A')
                t = 0
    print('Yes')
    for c in ans:
        print(c)


Measured memory_bytes: 86052
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define EREP(i,n) for (ll i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1
 
#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {X=X;}
#define TF(f) {f=f;}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 10000000000000000;
#define NMAX 50
#define MAX 10
int N, K;
ll A[20];
ll ans = 0;
int binary(int bina) {
	int ans = 0;
	for (int i = 0; bina>0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
int_fast8_t popcount(uint32_t bits) {
#ifdef __GNUC__
	return __builtin_popcount(bits);
#endif
	bits = bits - (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = bits + (bits >> 4) & 0x0f0f0f0f;
	bits = bits * 0x01010101;
	return bits >> 24;
}
int main() {
	cin >> N >> K;
	REP(i, N)cin >> A[i];
	ans = INF;
	REP(bit, (1 << N)) {
		if (popcount(bit)<K/* || ((bit >> (N - 1)) & 1)*/) { continue; }
		ll count = 0, front = A[0];
		//cout<<binary(bit)<<endl;
		REP(i, N) {
			if(i==0){continue;}
			if ((bit >> i) & 1) {
				if (front<A[i]) { front = A[i]; }
				else {
					front++;
					count += front - A[i];
				}
			}
			else {
				if (front<A[i]) { count = INF; break; }
			}
			DEB(count)DEB(front)END
		}
 
		/*if (count != INF)*/ans = min(ans, count);
}
	cout << ans << endl;
}

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
a = gets.split.map &:to_i
a.sort!
d = []
b = a[0]
(1...m).each do |i|
  d << (a[i] -b).abs
  b = a[i]
end
d.sort!.reverse!
(n-1).times do
  d.shift
end
s = d.inject(:+)
if s.nil?
  puts 0
else
  puts s
end

Measured memory_bytes: 9968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s;
  in(s);
  rep(i, 3){
    if(s[i] == '1')
      s[i] = '9';
    else if(s[i] == '9')
      s[i] = '1';
  }
  out(s);
  memi;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
const int INF = 1001001001;
vector<int>to[100005];
int main() {
    int n,m;
    cin >> n >> m;
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        --a;--b;
        to[a].push_back(b);
        to[b].push_back(a);
    }   
    queue<int> q;
    vector<int>dist(n,INF);
    vector<int>pre(n,-1);
    dist[0] = 0;
    q.push(0);
    while(!q.empty()) {
        int v = q.front();q.pop();
        for(int u:to[v]) {
            if(dist[u] != INF) continue;
            dist[u] += dist[v]+1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    rep(i,n) {
        if(i==0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
}

Measured memory_bytes: 10728
#define P(x) cout << #x " = " << x << endl
#define PP(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl

#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<queue>

using namespace std;
bool visited[1000][1000];
using PA = pair<int, pair<int, int>>;
int grid[1000][1000];
int h, w;
int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};
queue<PA> q;

void push_a(int i, int j) {
    for (int k = 0; k < 4; ++k) {
        int ni = di[k] + i;
        int nj = dj[k] + j;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w || visited[ni][nj]) continue;
        visited[ni][nj] = true;
        // PPP(grid[i][j] + 1, ni, nj);
        q.push(make_pair(grid[i][j] + 1, make_pair(ni, nj)));
    }
}

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if (c == '#') {
                grid[i][j] = 0;
                visited[i][j] = true;
            } else {
                grid[i][j] = -10;
                visited[i][j] = false;
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j] == 0) push_a(i, j);
        }
    }
    int ans = 0;
    while(!q.empty()) {
        auto top = q.front();
        q.pop();
        int k = top.first;
        int i = top.second.first;
        int j = top.second.second;
        // PPP(k, i, j);
        grid[i][j] = k;
        ans = max(ans, k);
        push_a(i, j);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11008
import sys
sys.setrecursionlimit(10**7)
 
N, Q = map(int, input().split())
root = [[] for _ in range(N)]
ans = [0]*N
 
for _ in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  root[a].append(b)
  root[b].append(a)

for _ in range(Q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
visit = [False]*N
def dfs(n):
  visit[n] = True
  for go in root[n]:
    if visit[go]:
      continue
    ans[go] += ans[n]
    dfs(go)

dfs(0)
print(*ans)

Measured memory_bytes: 223392
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for(int i=0;i<n;i++) {
			ans += sc.nextInt() - 1;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 25448
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,a,b,x[100005]={},ans=0;
  cin >> n >> a >> b;
  for(int i=0; i<n; i++) {
    cin >> x[i];
  }
  for(int i=0; i<n-1; i++) {
    ans+=min((x[i+1]-x[i])*a,b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<P> A(N);
  REP(i, N) {
    cin >> A[i].first;
    A[i].second = i + 1;
  }
  sort(all(A));
  REP(i, N) { cout << A[i].second << endl; }
  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

// cout << fixed << setprecision(12)

int main(){
  
  lint D; cin >> D;
  vi c(26); // contest 0-25
  for(lint i=0; i<26; i++) cin >> c[i];
  vvi s(D+1, vi(26)); // day 0-D
  for(lint d=1; d<=D; d++){
    for(lint j=0; j<26; j++){
      cin >> s[d][j];
    }
  }
  /*
  vi t(D+1); // day 0-D
  
  for(lint d=1; d<=D; d++){
    cin >> t[d];
    t[d]--;
  }
  */
  
  vi last(26,0);
  
  // lint ans = 0;
  vi ans(D+1);
  
  for(lint d=1; d<=D; d++){
    vi diff(26);
    
    for(lint i=0; i<26; i++){ // if contest i (0-25)
      // ans += s[d][t[d]];
      lint plus = s[d][i];
    
      // last[t[d]] = d;
      lint oldlast = last[i];
      last[i] = d;
    
      lint minus = 0;
    
      for(lint j=0; j<26; j++){
        // ans -= c[j] * (d - last[j]);
        minus += c[j] * (d - last[j]);
      }
      
      last[i] = oldlast;
      diff[i] = plus - minus;
    }
    
    vi oldiff = diff;
    sort(ALL(diff));
    lint t = -1;
    for(lint j=0; j<26; j++){
      if(oldiff[j] == diff[25]) t = j;
    }
    // cout << t+1 << endl;
    ans[d] = t+1;
    last[t] = d;
    
  }
  /*
  sort(ALL(c));
  lint tmp = 18; // delete suru kosuu
  for(lint j=0; j<tmp; j++) c.pop_back();
          
  for(lint d=1; d<=D; d++){
    cout << c[d%(26-tmp)] << endl;
  }
  */
  
  lint times = 1;
  for(lint i=0; i<times; i++){
    lint rd = rand()%25;
    swap(ans[rd], ans[rd+1]);
  }
  
  for(lint d=1; d<=D; d++) cout << ans[d] << endl;
}
      
      
    
  
  
  
  


Measured memory_bytes: 3684
N,K = gets.split.map(&:to_i)
  p   = gets.split.map(&:to_i)


  pExp = [] #期待値配列
  N.times do |i|
    pExp[i] = (p[i]+1) / 2.to_f
  end

  pSum = [] #期待値合計配列
  pSum[0] = pExp[0,K].inject(:+)
  (1..(N-K)).each do |i|
    pSum[i] = pSum[i-1] - pExp[i-1] + pExp[i+K-1]
  end

  puts pSum.max


Measured memory_bytes: 18512
x1,y1,x2,y2=map(int,input().split())
vecAB=[x2-x1,y2-y1]
vecAD=[-vecAB[1],vecAB[0]]
print(x2+vecAD[0],y2+vecAD[1],x1+vecAD[0],y1+vecAD[1],)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
//using namespace __gnu_pbds;


#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

bool issort(vector <int> &A)
{
    vector <int> B;
    B=A;
    sort(B.begin(),B.end());
    return (B==A);

}

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector <int> a;
        a.resize(n);
        for(int i=0;i<n;i++)
            {  cin>>a[i];
                }
        for(int i=0;i<n;i++)
            {
                for(int j=i;j<n;j++)
                {   
                    swap(a[i],a[j]);
                    if(issort(a))
                        {
                            cout<<"YES"<<'\n';
                            return 0;
                        }
                     swap(a[i],a[j]);   

                }
            }
            cout<<"NO"<<'\n';
            return 0;
    }

   return 0;
}

Measured memory_bytes: 256
from math import gcd

def gcdx(x,y,z):
    return gcd(gcd(x,y),z)
n = int(input())
a = 0
longp = []

for i in range(1,n+1):
    for j in range(1,n+1):
        for p in range(1,n+1):
            a += gcdx(i,j,p)
           
print(a)


Measured memory_bytes: 68056
import java.io.*;
import java.text.*;
import java.util.*;

public class Main{

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

        public String snl() throws IOException {
            return br.readLine();
        }

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        long maxi = Integer.MAX_VALUE;
        long mod = (long) (1e9 + 7);

        long pro(long a, long b) {
            return (a % mod * b % mod) % mod;
        }

        long add(long a, long b) {
            return (a + b) % mod;
        }

        void solve() {
            String s = sc.sn();
            StringBuilder sb = new StringBuilder(s);
            int n = s.length();
            String s1 = s.substring(0, (int) Math.ceil((n - 1) / 2.0));
            String s2 = s.substring((n + 3) / 2 - 1);
//            out.println(s1 + " " + s2);
            StringBuilder sb1 = new StringBuilder(s1);
            StringBuilder sb2 = new StringBuilder(s2);
            sb.reverse();
            sb1.reverse();
            sb2.reverse();
            if (sb.toString().equals(s) && sb1.toString().equals(s1) && sb2.toString().equals(s2))
                out.println("Yes");
            else
                out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
//#include<stdlib.h>
//int sort(const int *a,const int*b){
//return *b-*a;
//}
int main(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int a[n];
  double sum=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
   // printf("%lf\n",sum);
  }
 // qsort(a,n,sizeof(int),sort);
  int c=0;
  for(int i=0;i<n;i++){
	if(a[i]>=sum/4.0/m)c++;
  }
  if(c>=m)printf("Yes");
  else printf("No");
  return 0;
}
  


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

const ll INF = 1e17;
ll N, M, L;
Matrix e, e2;

void make_graph1() {
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        e[a][b] = e[b][a] = c;
    }
    rep(i, N+1) e[i][i] = 0;
}

void warshall_floyd(Matrix& x) {
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                x[j][k]= x[k][j] = min(x[j][k], x[j][i] + x[i][k]);
            }
        }
    }
}

void make_graph2() {
    rep(i, N+1) e2[i][i] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = i+1; j <= N; j++) {
            if (e[i][j] <= L) e2[i][j] = e2[j][i] = 1;
        }
    }
}

int main() {
    cin >> N >> M >> L;
    e = e2 = Matrix(N+1, vector<ll>(N+1, INF));
    make_graph1();
    warshall_floyd(e);
    make_graph2();
    warshall_floyd(e2);
    int Q;
    cin >> Q;
    rep(i, Q) {
        int s, t;
        cin >> s >> t;
        if (e2[s][t] < INF) cout << e2[s][t] - 1 << endl;
        else cout << -1 << endl;
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll A[100004];
ll n;
ll dp[100004];
ll solve(ll i){
    if(i > n){
        return MOD;
    }
    if(i == n){
        return 0;
    }
    if(dp[i] != -1)
        return dp[i];
    dp[i] = min((abs(A[i] - A[i+1]))+solve(i+1),
                (abs(A[i] - A[i+2]))+solve(i+2));
    return dp[i];
}
int main(){
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(ll i = 1; i <= n; i++){
        cin>>A[i];
    }
    cout<<solve(1);
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

struct SA{
	int n;
	vi sa,as,lcp;
	template<class t> SA(t s):n(s.size()),sa(n),as(n),lcp(n-1){
		rep(i,n)sa[i]=n-1-i;
		stable_sort(all(sa),[&](int a,int b){return s[a]<s[b];});
		vi c(n);
		rep(i,n)c[i]=s[i];
		for(int w=1;w<n;w*=2){
			vi d(c);
			rep(i,n){
				if(i&&sa[i-1]+w<n&&d[sa[i-1]]==d[sa[i]]&&d[sa[i-1]+w/2]==d[sa[i]+w/2])
					c[sa[i]]=c[sa[i-1]];
				else
					c[sa[i]]=i;
			}
			vi e(sa),f(n);
			iota(all(f),0);
			rep(i,n){
				int j=e[i]-w;
				if(j>=0)sa[f[c[j]]++]=j;
			}
		}
		//as
		rep(i,n)as[sa[i]]=i;
		//lcp
		int w=0;
		for(auto i:as){
			if(w)w--;
			if(i<n-1){
				while(max(sa[i],sa[i+1])+w<n&&s[sa[i]+w]==s[sa[i+1]+w])w++;
				lcp[i]=w;
			}
		}
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	string s;cin>>s;
	SA sa(s);
	dmp(sa.sa);
	int n=s.size();
	
	int q;cin>>q;
	rep(_,q){
		string p;cin>>p;
		const auto cmp=[&](int x){
			int i=0,y=n-x,z=min(y,int(p.size()));
			while(i<z&&s[x+i]==p[i])i++;
			if(i==z){
				if(y<int(p.size()))return -1;
				if(y>int(p.size()))return 1;
				return 0;
			}else
				return s[x+i]<p[i]?-1:1;
		};
		const auto cmp2=[&](int x){
			int i=0,y=n-x,z=min(y,int(p.size()));
			while(i<z&&s[x+i]==p[i])i++;
			return i==z&&y>=int(p.size());
		};
		int lw=-1,up=n;
		while(up-lw>1){
			int m=(up+lw)/2;
			if(cmp(sa.sa[m])<0)lw=m;
			else up=m;
		}
		dmp(up);
		if(up<n&&cmp2(sa.sa[up]))
			cout<<1<<"\n";
		else
			cout<<0<<"\n";
	}
}



Measured memory_bytes: 59512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,T; cin>>N>>T;
    vector<P> AB0;
    vector<P> ABn0;
    rep(i,N){
        ll a,b; cin>>a>>b;
        if(a==0) AB0.emplace_back(a,b);
        else ABn0.emplace_back(a,b);
    }

    SORT(AB0);

    //sort(ALL(ABn0),[](P &a, P &b){return (ld)(a.first)/(a.second+1)>(ld)(b.first)/(b.second+1);});
    sort(ALL(ABn0),[](P &a, P &b){return (a.first)*(b.second+1)>(b.first)*(a.second+1);});
    //sort(ALL(ABn0),[](P a, P b){return (b.first+1)*(a.second+1)+b.second>(a.first+1)*(b.second+1)+a.second;});

    vector<ll> dp(33,INF);
    dp[0]=0;

    rep(i,ABn0.size()){
        repr(j,31,0){
            mini(dp[j+1],(dp[j]+1)*ABn0[i].first+dp[j]+1+ABn0[i].second);
        }
    }
    vector<ll> dp2(202020,INF);
    dp2[0]=0;
    rep(i,AB0.size()){
        dp2[i+1]=dp2[i]+1+AB0[i].second;
    }

    ll ans=0;
    rep(i,32){
        rep(j,AB0.size()+1){
            if(dp[i]+dp2[j]>T) break;
            maxi(ans,i+j);
        }
    }
    cout<< ans <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 6384
input_n = input()
price1  = input()
price2  = input()
min_price = min(price1,price2)
max_profit = price2-price1
for i in xrange(input_n-2):
    input_profit = input()
    tmp = input_profit-min_price
    if max_profit<tmp:
        max_profit = tmp
    if min_price>input_profit:
        min_price = input_profit
print max_profit

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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  deque< int > appear(N);
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ++appear[--x];
  }
  sort(begin(appear), end(appear));
  int ret = 0;
  while(appear.size() > K) {
    ret += appear.front();
    appear.pop_front();
  }
  cout << ret << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



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

    llong n,c,k; cin>>n>>c>>k;
    vector<llong> t(n,0);
    REP(i,n) cin>>t[i];
    llong ans=0;
    sort(t.begin(),t.end());

    for(int i=0; i<n;)
    {
       ++ans;
       int  start=i;
       while (i<n&&t[i]-t[start]<=k&&i-start<c)
       {
        ++i;
       }
    }
    cout<<ans<<endl;
    return  0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N;
ll p[200000][3];
ll dp[200000][3];

signed main() {
  cin >> N;
  rep(i, N)
    rep(j, 3)
      cin >> p[i][j];
  rep(j, 3)
    dp[0][j] = p[0][j];
  for (ll i=0; i<N-1; i++) rep(j, 3) rep(nj, 3) {
    if (j == nj)
      continue;
    ll ni = i+1;
    chmax(dp[ni][nj], dp[i][j] + p[ni][nj]);
  }
  ll ans = 0;
  rep(j,3)
    chmax(ans, dp[N-1][j]);
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    
    int n; cin >> n;
    long long result=1;
    long long num[100001];
    for (int i=0; i<n; i++){//0を見つけた瞬間0
        cin >> num[i];
        if (num[i]==0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i=0; i<n; i++){
        long long now = num[i];
        if (double(log10(result))+double(log10(now))<=18 && result*now<=1000000000000000000) {
            //cout << double(log10(result)) << " " << double(log10(now)) << endl;
            result*=now;//結果が10^8以下ならば
        }
        else {
            cout << -1 << endl;
            return 0;
        }
        //cout << "now is " << now << "result is " << result << endl;
    }
    cout << result << endl;
}

Measured memory_bytes: 4724
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>

using namespace std;

int main(void)
{
	bool check[26] = { false, };
	string s;

	cin >> s;

	for (int i = 0; i < s.length(); i++)
	{
		check[s[i] - 'a'] = true;
	}

	for (int i = 0; i < 26; i++)
	{
		if (check[i] == false)
		{
			cout << char(i + 'a') << endl;
			return 0;
		}
	}

	cout << "None" << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;
 
int main()
{
    IOS();
    
    ll a,b=0,n,c,i,j;
    cin>>a>>n;
    ll aa[n+1];
    f(i,0,n)
    {
        cin>>aa[i];
        b+=aa[i];
    }
    if(b>=a)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

// ac
func main() {
	N := getStdinInt64()
	if N >= 30 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func sumfrom1(val int64) int64 {
	var a int64 = 0
	var i int64 = 0
	for i = 0; i < val; i++ {
		a += i + 1
	}
	return a
}

func sortString(w string) string {
	s := strings.Split(w, "")
	sort.Strings(s)
	return strings.Join(s, "")
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}

func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}

func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

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

int main()
{
    string s;
    string a ="AKIHABARA";
    cin>>s;
    int n=s.size();
    bool ok=true;
    if(n>9)
    {
        ok=false;
    }
    else
    {
        int ap=0;
        int sp=0;
        while (sp<n && ap<9)
        {
            if(s[sp]==a[ap])
            {
                ap++;
                sp++;
            }
            else if(a[ap]=='A')
            {
                ap++;
            }
            else
            {
                ok=false;
                break;
            }            
        }
        if(sp<n) ok=false;
        if(ap<8) ok=false;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

int cnt[N], a[N];

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

    long long sum = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        sum += 0ll + a[i];
    }
    int q;
    cin >> q;
    for (int i = 0, b, c; i < q; i++) {
        cin >> b >> c;
        sum += 1ll * (c - b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << '\n';
    }
}


Measured memory_bytes: 4392
import itertools as itr

n, m = map(int, input().split())
a = [list(map(float, input().split())) for i in range(n)]
ans = 0
for p in itr.combinations(a, m):
    sm = 0
    for i in range(m):
        for j in range(i + 1, m):
            for k in range(3):
                sm += (p[i][k] - p[j][k]) ** 2
    ans = max(ans, sm)
print(ans)

Measured memory_bytes: 7756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            var line = Input.ReadIntArray();
            int A = line[0];
            int B = line[1];
            if (A >= 13) Console.WriteLine(B);
            else if(A >= 6) Console.WriteLine(B / 2);
            else Console.WriteLine(0);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

# define con continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vld vector < ld >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < long , long >
# define pDD pair < D , D >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    int n ; cin >> n ;
    vi v ( n ) ;

    for ( int i=0 ; i < n ; i++ ) cin >> v[i] ;

    int i=0 ;
    int ans = 0 ;

    for ( ; i < n ; )
    {
        int j = i ;
        for ( ; i < n-1 && v[i+1] <= v[i] ; i++ ) ;

        ans = max ( ans , i - j ) ;
        i++ ;
    }

    cout << ans ; line
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 640
n=int(input())
mass=[input()]
mass.append(input())
MOD=10**9+7
if mass[0][0]==mass[1][0]:
    ans=3
    x=0
    y=1
    yoko=False
else:
    ans=6
    x=0
    y=2
    yoko=True
while y<n:
    if x==0:
        if mass[x][y]==mass[x+1][y]:#縦
            yoko=False
            if mass[0][y-1]==mass[1][y-1]:
                ans*=2
                y+=1
            else:
                y+=1
        else:#横
            if yoko:
                ans*=3
            else:
                ans*=2
            yoko=True
            y+=2
print(ans%MOD)


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

#define rep(i, n) for(int i = 0; i < n; i++)
#define MAX 100
typedef pair<int, int> P;
 
int N, M;
int scene[MAX][MAX];
int s[MAX/2][MAX/2], rotate_s[MAX/2][MAX/2][4];
 
void rotate()
{
    rep (i, 3) {
	rep (j, M) {
	    rep (k, M) {
		rotate_s[j][k][i+1] = s[M-k-1][j];
	    }
	}
     
	rep (j, M) {
	    rep (k, M) { 
		s[j][k] = rotate_s[j][k][i+1];
	    }
	}
    }
}
 
void solve()
{
    vector<P> v;
 
    rep (i, N-M+1) {
	rep (j, N-M+1) {
	    rep (k, 4) {
		bool flg = true;
		rep (l, M) {
		    rep (n, M) {
			if (rotate_s[l][n][k] == -1) {
			    continue;
			}
 
			if (scene[i+l][j+n] != rotate_s[l][n][k]) {
			    flg = false;
			    goto next;
			}
		    }
		}
	    next:;
		if (flg) {
		    rep (l, M) {
			bool found = false;
			rep (n, M) {
			    if (rotate_s[l][n][k] != -1) {
				v.push_back(P(i+l+1, j+n+1));
				found = true;
				break;
			    }
			}
			if (found) {
			    break;
			}
		    }
		}
	    } 
	}
    }
 
    sort(v.begin(), v.end());
 
    if (!v.size()) {
	cout << "NA" << endl;
    } else {
	cout << v[0].second << " " << v[0].first << endl;
    }
}
 
int main()
{
    while (cin >> N >> M, (N | M)) {
	rep (i, N) {
	    rep (j, N) {
		cin >> scene[i][j];
	    }
	}
 
	rep (i, M) {
	    rep (j, M) {
		cin >> s[i][j];
		rotate_s[i][j][0] = s[i][j];
	    }
	}
	rotate();
	solve();
    }
    return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
#include <functional>
#include <string.h>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int,int> pi; 
typedef double db;

const int mod=1e9+7;
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
#define MP make_pair
#define FF first
#define SS second
#define LB lower_bound
#define UB upper_bound
#define PB push_back
#define lc ((p<<1)+1)
#define rc ((p<<1)+2)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define all(v) (v).begin(),(v).end()
#define clean(v,a) memset(v,a,sizeof(v))
#define get(a) scanf("%d",&a)
#define get2(a,b) scanf("%d%d",&a,&b)
#define get3(a,b,c) scanf("%d%d%d",&a,&b,&c)

/*
 * high precision: printf("%.12lf",(db)ans);
 *
 * clear output buffer: fflush(stdout);
 *
 * sync off: ios::sync_with_stdio(false);
 *
 */

typedef pair<pi,int> ppi;

const int Maxn=2e5+5;

int a[Maxn];
int b[Maxn];
int n;

bool check(int x)
{
	for(int i=1;i<2*n;i++)
	{
		b[i]=(a[i]>=x)?1:0;
	}
	vector<ppi> v;
	v.PB(ppi(pi(0,0),0));
	for(int i=2,cur=1;i<2*n;i++)
	{
		if(b[i]==b[i-1])
		{
			cur++;
			if(i==2*n-1)
			{
				if(cur>1) v.PB(ppi(pi(i-cur+1,i),b[i]));
			}
		}
		else
		{
			if(cur>1)
			{
				v.PB(ppi(pi(i-cur,i-1),b[i-1]));
			}
			cur=1;
		}
	}
	v.PB(ppi(pi(2*n,2*n),0));
	if(v.size()==2)
	{
		if(n%2) return b[n]==1;
		else return b[n]==0;
	}
	for(int i=0;i<v.size()-1;i++)
	{
		if(v[i].FF.FF<=n&&v[i].FF.SS>=n)
		{
			return v[i].SS==1;
		}
		if(v[i].FF.SS<=n&&n<=v[i+1].FF.FF)
		{
			if(n-v[i].FF.SS<v[i+1].FF.FF-n)
			{
				return v[i].SS==1;
			}
			else
			{
				return v[i+1].SS==1;
			}
		}
	}
}

int main()
{
	scanf("%d",&n);
	rep(i,1,2*n-1) scanf("%d",a+i);
	int ub=2*n,lb=1,mi;
	while(ub-lb>1)
	{
		mi=(ub+lb)>>1;
		if(check(mi)) lb=mi;
		else ub=mi;
	}
	printf("%d\n",lb);
	return 0;
}

Measured memory_bytes: 3204
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
h, w = MAP()

print(H*W - H*w - h*W + h*w)

Measured memory_bytes: 60652
#include<stdio.h>
#include<algorithm>
#define reg register
#define ri reg int
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define nrep(i, x, y) for(ri i = x; i >= y; --i)
#define DEBUG 1
#define ll long long
#define max(i, j) (i) > (j) ? (i) : (j)
#define min(i, j) (i) < (j) ? (i) : (j)
struct IO {
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
	char buf[MAXSIZE], *p1, *p2;
	char pbuf[MAXSIZE], *pp;
	#if DEBUG
	#else
		IO() : p1(buf), p2(buf), pp(pbuf) {}
		~IO() {
			fwrite(pbuf, 1, pp - pbuf, stdout);
		}
	#endif
	inline char gc() {
		#if DEBUG
    		return getchar();
		#endif
    	if(p1 == p2)
			p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
    	return p1 == p2 ? ' ' : *p1++;
	}
	inline bool blank(char ch) {
    	return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
	}
	template <class T>
	inline void read(T &x) {
    	register double tmp = 1;
    	register bool sign = 0;
    	x = 0;
    	register char ch = gc();
    	for(; !isdigit(ch); ch = gc())
    		if(ch == '-') sign = 1;
    	for(; isdigit(ch); ch = gc())
			x = x * 10 + (ch - '0');
    	if(ch == '.')
			for(ch = gc(); isdigit(ch); ch = gc())
        		tmp /= 10.0, x += tmp * (ch - '0');
    	if(sign) x = -x;
	}
	inline void read(char *s) {
		register char ch = gc();
		for(; blank(ch); ch = gc());
		for(; !blank(ch); ch = gc())
			*s++ = ch;
    	*s = 0;
	}
	inline void read(char &c) {
    	for(c = gc(); blank(c); c = gc());
	}
	inline void push(const char &c) {
		#if DEBUG
    		putchar(c);
		#else
    		if(pp - pbuf == MAXSIZE) {
				fwrite(pbuf, 1, MAXSIZE, stdout);
				pp = pbuf;
			}
    		*pp++ = c;
		#endif
	}
	template <class T>
	inline void write(T x) {
    	if(x < 0) {
			x = -x;
			push('-');
		}
    	static T sta[35];
    	T top = 0;
    	do{
			sta[top++] = x % 10;
			x /= 10;
    	}while(x);
    	while(top)
			push(sta[--top] + '0');
	}
	template <class T>
	inline void write(T x, char lastChar) {
    	write(x);
		push(lastChar);
	}
} io;
int a[110], n, ans;
int main() {
	io.read(n);
	rep(i, 1, n * 2) io.read(a[i]);
	std::sort(a + 1, a + 2 * n + 1);
	rep(i, 1, n) ans += a[2 * i - 1];
	io.write(ans);
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main() {
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    multiset<int> ms;
    ms.insert(a[0]);
    rep(i,n-1){
        auto index=ms.lower_bound(a[i+1]);
        if (index!=ms.begin()){
            ms.erase(--index);
        }
        ms.insert(a[i+1]);

    }
    cout<<ms.size()<<endl;

    

    return 0;
}


Measured memory_bytes: 5376
from itertools import combinations
n = int(input())
l = [[] for _ in range(n)]
for i in range(n):
    for _ in range(int(input())):
        l[i].append(list(map(int, input().split())))

people = list(range(1, n + 1))

for res in people[::-1]:
    for c in combinations(people, res):
        s = set(c)
        valid = True
        for i in c:
            for p, y in l[i - 1]:
                if y == 0:
                    valid &= not p in s
                else:
                    valid &= p in s
            if not valid:
                break
        if valid:
            print(res)
            exit()
print(0)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
const int N=205;
int n,id,D[N],flag,vis[N],fa[N*2];
char a[N][N];
vector<int>g;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int find(int x)
{
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
void bfs(int u,int dep)
{
	D[u]=dep;
	queue<int>q;
	q.push(u);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i=1;i<=n;i++)
			if(a[u][i]=='1'&&!D[i])
			{
				D[i]=D[u]+1;
				q.push(i);
			}
	}
}
void dfs(int u)
{
	vis[u]=id;
	for(int i=1;i<=n;i++)
		if(a[u][i]=='1'&&(!vis[i]))dfs(i);
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
	if(n==2){cout<<2;return 0;}
	for(int i=1;i<=n;i++)fa[i]=i,fa[i+n]=i+n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i][j]=='1')
			{
				if(find(i)==find(j)||find(i+n)==find(j+n)){puts("-1");return 0;}
				fa[find(i)]=find(j+n);
				fa[find(j)]=find(i+n);
			}
	int ans=-1;
	for(int i=1;i<=n;i++)
	{
		g.clear();
		memset(D,0,sizeof(D));
		memset(vis,0,sizeof(vis));
		bfs(i,1);
		id=0;
		for(int j=1;j<=n;j++)
			if(a[i][j]=='1'&&!vis[j])
			{
				id++;
				dfs(j);
				int ma=0;
				for(int k=1;k<=n;k++)
					if(vis[k]==id)ma=max(ma,D[k]);
				g.push_back(ma);
			}
		if(g.size()==0)continue;
		sort(g.begin(),g.end());
		if(g.size()==1)ans=max(ans,g[0]);
		else ans=max(ans,g[0]+g[1]-1);
//		if(ans==5){cout<<g[0]<<" "<<g[1]<<" "<<i<<endl;}
	}
	cout<<ans;
}

Measured memory_bytes: 384