akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;

int n, k;
vector<int> a;
int dp[101][100*1000+1];
const int M = pow(10, 9) + 7;

int main()
{
	cin >> n >> k;
	a.resize(n);
	for(int i=0;i<n;++i)cin>>a[i];
    for (int i=0;i<=n;++i)dp[i][0] = 1;
	for (int i=1;i<=n;++i)
	{
		int sum = 0;
		for (int j=0;j<=k;++j)
		{
    		if (j<=a[i-1])
    		{
    	    	sum += dp[i-1][j];
		        sum %= M;
		        dp[i][j] = sum;
    		}
		    else
		    {
		        sum += dp[i-1][j];
		        sum %= M;
		        sum = (M+sum - (dp[i-1][j-a[i-1]-1]%M))%M;
		        dp[i][j] = sum%M;
		    }
		}
	}
//	for (int j=0;j<=k;++j)cout<< dp[j] << " ";
//	cout << endl;
  /*  for (int i=0;i<=n;++i)
    {
        for (int j=0;j<=k;++j)cout<<dp[i][j]<<" ";
        cout << endl;
    }*/
	cout << dp[n][k]%M << endl;
	return 0;
}


Measured memory_bytes: 39296
from collections import Counter

N=int(input())
a=list(map(int,input().split()))

A=Counter(a)
B=list(A.keys())
C=list(A.values())

ans=sum(c*(c-1)//2 for c in C)

for k in range(1,N+1):
    print(ans-A[a[k-1]]+1)

Measured memory_bytes: 34148
/*
 *Author - Bhanu Pratap
 */
#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define all(c) c.begin(), c.end()
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
const ll mod = 1e9 + 7;
const ld PI = 3.141592653589793;

void solve () {
	ll m,d;
	cin>>m>>d;
	ll ans=0;
	while (m>0) {
		int cnt=0;
		for (int i=2; i<=9; i++) {
			for (int j=2; j<=9; j++) {
				if (i*10+j>d) {cnt++; break;}
				if (i*j==m) ans++;
			}
			if (cnt) break;
		}
		m--;
	}
	cout<<ans;
}
main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    solve();
    return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
/*
oxxoxoo
xxxooxxox
*/

int main(){
	string str="";
	char c;
	
	cin>>c;
	str+=c;
	
	while(cin>>c)if(str[str.size()-1]!=c)str+=c;
	for(char i='o';str.size()>1;){
		string tmp="";
		if(str[0]!=i)for(int i=1;i<str.size();i++)tmp+=str[i];
		else if(str[str.size()-1]!=i)for(int i=0;i<str.size()-1;i++)tmp+=str[i];
		else tmp=str;
		
		str=tmp;
		if(i=='o')i='x';
		else i='o';
	}
	cout<<str<<endl;
	return 0;
}


Measured memory_bytes: 1192
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count = 0;
		for (int i = 0; i < 3; i++) {
			if (s.charAt(i) == 'o') {
				count++;
			}
		}
		System.out.println(700 + (count * 100));
	}
}


Measured memory_bytes: 35728
import sys
input = sys.stdin.readline

def main():
    H, W, A, B = map(int, input().split())

    MOD = int(1e9) + 7

    kai = [1] * (max(H-A+W, A+W-B) + 1)
    for i in range(1, len(kai)):
        kai[i] = kai[i-1] * i
        kai[i] %= MOD
    
    up = [0] * (W-B)
    down = [0] * (W-B)

    t1 = H-A-1
    for i in range(W-B):
        t2 = B + 1 + i-1
        # print(t1, t2)
        up[i] = kai[t1 + t2] * pow(kai[t1], MOD-2, MOD) * pow(kai[t2], MOD-2, MOD)
        up[i] %= MOD
    t1 = A-1
    for i in range(W-B):
        t2 = W-B-i-1
        # print(t1, t2)
        down[i] = kai[t1 + t2] * pow(kai[t1], MOD-2, MOD) * pow(kai[t2], MOD-2, MOD)
        down[i] %= MOD
    
    ans = 0
    for i in range(W-B):
        ans += (up[i] * down[i])
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18356
n, m, x = map(int,input().split())
a = set(map(int,input().split()))

b = a
for i in range(1,x,1):
  b = b - {i}

c = a
for i in range(x+1,n,1):
  c = c - {i}

print(min(len(b),len(c)))

Measured memory_bytes: 3064
//AtCoder ABC068 B - Break Number
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N;
    cin>>N;
    ll ans=1;
    ll max_cnt=0;
    auto check_func = [](ll v){
        ll cnt=0;
        while(v%2==0&&v>1){
            v/=2;
            ++cnt;
        }
        return cnt;
    };
    for(ll i=1;i<=N;++i){
        ll cnt=check_func(i);
        if(cnt>max_cnt){
            max_cnt=cnt;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
var
	N,sum,i:Longint;
	A:Array[0..100001]of Longint;
begin
	read(N);
	for i:=1 to N do read(A[i]);
	for i:=1 to N+1 do begin
		if A[i]>A[i-1] then inc(sum,A[i]-A[i-1])else inc(sum,A[i-1]-A[i]);
	end;
	for i:=1 to N do writeln(sum-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]));
end.


Measured memory_bytes: 1408
#include<stdio.h>
int main(void){ 
 int a, h, m, s, b; 
 scanf("%d",&a); 
 h=a/3600; 
 b=a%3600;  
 m=b/60;  
 s=b%60;    
 printf("%d:%d:%d\n", h, m, s); 
 return 0;
 }

Measured memory_bytes: 592
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#endif

using namespace std;


typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}


#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back


#define MOD 1000000007LL
#define EPS 1e-8

int main() {
  int K, S;
  cin >> K >> S;
  int res = 0;
  for (int Z = 0; Z <= K; ++Z) {
    int t = S - Z;
    for (int Y = 0; Y <= K; ++Y) {
      int u = t - Y;
      if (0 <= u && u <= K) res++;
    }
  }
  cout << res << endl;
  return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

void Main() {
  int n = read<int>();
  n--;
  int m = 2 * n + 1;
  vi A(m);
  rep(i, m) A[i] = read<int>();

  int ok = 2;
  int ng = m-1;

  auto check = [&](int x) -> bool {
    vb B(m);
    rep(i, m) B[i] = A[i] >= x;
    //cout << "B:"; rep(ii,sz(B)) cout << ' ' << B[ii]; cout << endl;

    rep(i, 1, n+1) {
      bool r = B[n+i];
      bool l = B[n-i];
      if (i % 2) {
        if (B[n] == r || B[n] == l) return B[n];
      }
      else {
        if (B[n] != r || B[n] != l) return !B[n];
      }
    }
    return B[0];
  };

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    bool c = check(mid);
    // cout << "ok: " << ok << ", ng: " << ng << ", ";
    // cout << "check(" << mid << ") -> " << c << endl;
    if (c) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

int main() {

  long long A, B, N;
  cin >> A >> B >> N;

  long long x;
  x = min(N, B - 1);
  x %= B;

  A *= x;

  long long answer = (A - A % B) / B;
  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 3528
N=int(input())
L=list(map(int,input().split()))
S=sum(L)

R=[S-L[0]]
for i in range(1,N):
    R.append(R[-1]-L[i])
#print(R)

mod=10**9+7
ans=0
for i in range(N):
    ans += L[i]*R[i]
    ans%=mod
print(ans)

Measured memory_bytes: 31564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)
const int mxn=1e9+5;
int main()
{
    fast;
    long double n,d,cnt=0;
    cin>>n>>d;
    for(long double i=0;i<n;i++)
    {
        long double a,b;
        cin>>a>>b;
        long double ans=(long double)sqrt(a*a+b*b);
        cnt=ans<=d?cnt+1:cnt;
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<bool> div(1e6+1, true);
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int num = a[i];
        if(div[num])
        {
            if(i == n-1) ans++;
            if(i < n-1 && a[i+1] != a[i]) ans++;
            for(int j = num; j <= 1e6; j += num)
            {
                div[j] = false;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 4308
#include<bits/stdc++.h>
inline int read(){
	int x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		ch=getchar();
		if (ch=='-') w=-1;	
	}
	while (ch<='9' && ch>='0'){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*w;
}
using namespace std;
typedef long long ll;
const int N=2e4+5;
const ll inf=1e18;
int n,now;
struct node{
	int w,s,v;
	inline bool operator < (const node &u)const{
		return w+s>u.w+u.s;
	}	
}a[N];
ll dp[2][N];
int main(){
	n=read();
	for (int i=1;i<=n;++i)
		a[i].w=read(),a[i].s=read(),a[i].v=read();
	sort(a+1,a+n+1);
	for (int j=0;j<N-5;++j) dp[0][j]=-inf;
	for (int i=1;i<=n;++i){
		now^=1;
		for (int j=0;j<N-5;++j) dp[now][j]=-inf;
		for (int j=0;j<=N-5;++j){
			if (dp[now^1][j]<0) continue;
			if (j>=a[i].w) dp[now][min(j-a[i].w,a[i].s)]=max(dp[now][min(j-a[i].w,a[i].s)],dp[now^1][j]+a[i].v); 
			dp[now][j]=max(dp[now][j],dp[now^1][j]);
		}
	}
	ll ans=-inf;
	for (int i=0;i<=N-5;++i) ans=max(ans,dp[now][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> a(N + 1), cur(N + 5);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) a[i]--;

    for (int i = 0; i < N + 2; i++) {
        cur[i+1] = a[cur[i]];
    }
    ll nonLoop = 0;
    ll loop = 0;
    vector<int> visited(N+1, -1);
    for (int i = 0; i < N; i++) {
        if (cur[i+1] == 0) {
            loop = i+1;
            nonLoop = 0;
            break;
        }
        else if (visited[cur[i+1]] != -1) {
            loop = i - visited[cur[i+1]] + 1;
            nonLoop = visited[cur[i+1]] - 1;
            break;
        }
        visited[cur[i+1]] = i+1;
    }

    vector<int> nL(nonLoop), L(loop);
    for (int i = 0; i < nonLoop; i++) nL[i] = cur[i+1];
    for (int i = nonLoop; i < nonLoop + loop; i++) L[i - nonLoop] = cur[i+1];

    K -= 1;
    if (nonLoop > K) {
        cout << nL[K] + 1 << '\n';
    }
    else {
        K -= nonLoop;
        K %= loop;
        cout << L[K] + 1<< '\n';
    }
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i+=2){
		if (S[i] != 'R' && S[i] != 'U' && S[i] != 'D') {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = 1; i < S.size(); i+=2){
		if (S[i] != 'L' && S[i] != 'U' && S[i] != 'D') {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using namespace std; using INT = int64_t; using II = pair<INT, INT>;
template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;

signed main() {
  int a, b, k; cin >> a >> b >> k;
  int cnt = 0;
  for (int i = min(a, b); i >= 0; i--) {
    if (a % i == 0 && b % i == 0) {
      cnt++;
      if (cnt == k) {
        cout << i << endl; return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vl s;
    for (int i = 0; i < n; ++i) {
        ll sum = a[i];
        s.push_back(sum);
        for (int j = i + 1; j < n; ++j) {
            sum += a[j];
            s.push_back(sum);
        }
    }
    ll ret = 0;
    for (ll d = 40; d >= 0; --d) {
        int cnt = 0;
        for (auto &ss : s) {
            if (((ret + (1LL << d)) & ss) == (ret + (1LL << d)))
                cnt++;
        }
        if (cnt >= k)
            ret += 1LL << d;
    }
    cout << ret << "\n";
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const int nmax = 100010;
ll x[nmax],v[nmax];

ll rdmax[nmax];

ll n,c;
ll ans = 0LL;

void proc(){
	{
		ll csum = 0LL;	
		rrep(i,n){
			csum += v[i];
			rdmax[i] = csum - 2LL * (c - x[i]);
			chmax(rdmax[i],rdmax[i+1]);
		}
	}

	{
		ll csum = 0LL;
		rep(i,n){
			csum += v[i];
			const ll cur = csum - x[i] + rdmax[i + 1];
			chmax(ans,cur);
		}
	}
}


int main(void){
	cin >> n >> c;
	
	rep(i,n) cin >> x[i] >> v[i];

	proc();
	reverse(x,x+n);
	reverse(v,v+n);
	rep(i,n) x[i] = c - x[i];
	proc();

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

Measured memory_bytes: 2560
def solve():
    N = int(input())

    L = [list(map(int, input().split())) for n in range(N)]

    p_t = 0
    p_x = 0
    p_y = 0
    for n in range(N):
        t, x, y = L[n]

        mt = t - p_t
        
        mp = abs(x-p_x) + abs(y-p_y)
        # print('mp',mp)
        # print('mt',mt)

        if mp <= mt and ((mp - mt)%2 == 0):
            p_t = t
            p_x = x
            p_y = y
        else:
            print('No')
            return

    print('Yes')


if __name__ == "__main__":
    solve()



Measured memory_bytes: 27324
h,w=map(int,input().split())
a=[input() for i in range(h)]
row=[False]*h
col=[False]*w
for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      row[i]=True
      col[j]=True
for i in range(h):
  for j in range(w):
    if row[i]==True and col[j]==True:
      print(a[i][j],end="")
  if row[i]:
    print()

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

// @@ !! LIM()

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

  auto solve = [&]() -> bool {
    ll N; cin >> N;
    vector<ll> see(N+1);
    for (ll i = 0; i < N; i++) {
      ll a; cin >> a;
      see[a]++;
    }
    for (ll i = 0; i < N; i++) {
      if (see[i] == 0) continue;
      for (ll j = i + 2; j < N; j++) {
	if (see[j] > 0) return false;
      }
      if (see[i+1] == 0) {
	if (see[i] == i + 1) return true;
	if (see[i] >= i * 2) return true;
	return false;
      }
      if (see[i] <= i && see[i+1] >= 2 * (i + 1 - see[i])) return true;
      return false;
    }
    assert(0);
  };
  cout << (solve() ? "Yes\n" : "No\n");

  return 0;
}



Measured memory_bytes: 3972
/*input
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

pii p[maxn];
set<double> st;
vector<pii> v;
int main()
{
	//IOS;
	int m,n;
	cin>>m>>n;
	REP(i,n) cin>>p[i].F>>p[i].S;
	REP(i,n) p[i].S=-p[i].S;
	sort(p,p+n);
	REP(i,n) p[i].S=-p[i].S;
	for(int i=0;i<n;i++){
		while(SZ(v)&&p[i].S<v.back().S) v.pop_back();
		v.pb(p[i]);
	}
	double pre=-1;
	int cnt=0;
	for(pii i:v){
		if(i.F>pre){
			pre=i.S-0.5;
			cnt++;
		}
	}
	cout<<cnt<<'\n';
	return 0;
}


Measured memory_bytes: 2168
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scan(&S)

	var num int
	for _, s := range strings.Split(S, "") {
		if s == "+" {
			num++
		} else {
			num--
		}
	}

	fmt.Println(num)
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

struct rq{
	int l;
	int r;

	bool operator<(const rq &in) const{
		return r!=in.r ? r<in.r : l<in.l;
	};
};

int main(){

	int n, m, ans=0, del=0;
	vector<rq> v;

	cin>> n >> m;
	v.resize(m);

	rep(i, m) {
		int il, ir;
		cin>> il >> ir;
		v[i].l=il;
		v[i].r=ir;
	}
	sort(v.begin(), v.end());
	//rep(i, m) cout<< v[i].l << " " << v[i].r <<endl;

	rep(i, m){
		if(v[i].l+1<=del && del<=v[i].r) continue;
		del=v[i].r;
		ans++;
		//cout<< del <<endl;
	}

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

Measured memory_bytes: 4068
n = int(input())
a = [0 for _ in range(n)]
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        s,t = map(int,input().split())
        x[i].append(s)
        y[i].append(t)
ans = 0
for i in range(2**n):
    karishoujiki = []
    shoujiki = []
    usotuki = []
    for j in range(n):
        if (i>>j)&1:
            karishoujiki.append(j)
            for k in range(a[j]):
                if y[j][k] == 1:
                    shoujiki.append(x[j][k]-1)
                else:
                    usotuki.append(x[j][k]-1)
    flag = 1
    shoujikiflag = [0 for _ in range(n)]
    karishoujikiflag = [0 for _ in range(n)]
    usotukiflag = [0 for _ in range(n)]
    for i in range(len(shoujiki)):
        shoujikiflag[shoujiki[i]] = 1
    for i in range(len(karishoujiki)):
        karishoujikiflag[karishoujiki[i]] = 1
    for i in range(len(usotuki)):
        usotukiflag[usotuki[i]] = 1
    
    for i in range(n):
        if shoujikiflag[i] and not karishoujikiflag[i]:
            flag = 0
        if usotukiflag[i] and karishoujikiflag[i]:
            flag = 0
    
    if flag:
        ans = max(ans,len(karishoujiki))

print(ans)

Measured memory_bytes: 9320
#include "bits/stdc++.h"

using namespace std;

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

    int n,r;
    while(cin>>n>>r,n&&r){
        vector<int> old_cards(n),new_cards(n);
        for(int i=0;i<n;i++) old_cards[i]=n-i;
        for(int j=0;j<r;j++){
            int p,c;cin>>p>>c;
            for(int i=0;i<c;i++) new_cards[i]=old_cards[p-1+i];
            for(int i=c;i<p-1+c;i++) new_cards[i]=old_cards[i-c];
            for(int i=p-1+c;i<n;i++) new_cards[i]=old_cards[i];

            for(int i=0;i<n;i++) old_cards[i]=new_cards[i];
        }
        cout<<old_cards[0]<<endl;
    }
}

Measured memory_bytes: 3064
import std;

alias UV = Tuple!(int, "node", int, "a", int, "b");
alias CD = Tuple!(int, "c", int, "d");

alias T = Tuple!(int, "node", long, "cost", long, "coin");
alias MinHeap = BinaryHeap!(Array!T, "a.cost > b.cost");

alias MemoKey = Tuple!(int, "node", long, "coin");

void calc(int n, int s, UV[][] uv, CD[] cd) {

    auto q = new MinHeap;
    q.insert(T(1, 0, s));

    bool[MemoKey] used;

    auto ans = new long[n + 1];
    ans[] = -1;
    while (!q.empty) {
        auto t = q.front; q.popFront();

        if (MemoKey(t.node, t.coin) in used) continue;
        used[MemoKey(t.node, t.coin)] = true;

        if (ans[t.node] == -1)
            ans[t.node] = t.cost;

        // all ok
        bool ok = true;
        for (int i = 1; i <= n; i++) {
            if (ans[i] == -1) {
                ok = false;
                break;
            }
        }
        if (ok) break;

        foreach (u; uv[t.node]) {
            if (t.coin >= u.a) {
                q.insert(T(u.node, t.cost + u.b, t.coin - u.a));
            }
        }

        // 全てのノードを回るのに必要な銀貨の枚数は、全ノード数(50) * 銀貨MAX(50) = 2500
        if (t.coin < 2500) {
            // 金貨と銀貨を交換
            q.insert(T(t.node, t.cost + cd[t.node].d, t.coin + cd[t.node].c));
        }
    }

    for (int i = 2; i <= n; i++) {
        writeln(ans[i]);
    }
}

void main() {
    int n, m, s; scan(n, m, s);
    UV[][] uv;
    for (int i = 0; i <= n; i++) uv ~= [[]];
    foreach (_; 0..m) {
        int u, v, a, b; scan(u, v, a, b);
        uv[u] ~= UV(v, a, b);
        uv[v] ~= UV(u, a, b);
    }
    auto cd = new CD[n + 1];
    foreach (i; 0..n) {
        int c, d; scan(c, d);
        cd[i+1] = CD(c, d);
    }

    calc(n, s, uv, cd);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 24776
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int tap = sc.nextInt();
      int over = sc.nextInt();
      int outlet = 1;
      int ans = 0;
        while (outlet < over) {
          --outlet;
          outlet += tap;
          ans++;
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 23252
def exp(x):
  return (1+x) / 2

n, k = map(int, input().split())
p = list(map(int, input().split()))
  
sum = 0
for i in range(k):
  sum += exp(p[i])
max = sum

for i in range(n-k):
  sum += exp(p[i+k]) - exp(p[i])
  if max < sum:
    max = sum

print(max)

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

using namespace std;
using ll = long long;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ng = 0, ok = 1e9;
  while (ok - ng > 1) {
    int m = (ok + ng) / 2;
    auto f = [&](int x) {
      ll now = 0;
      rep(i, n) now += (a[i] - 1) / x;
      return now <= k;
    };

    if (f(m))
      ok = m;
    else
      ng = m;
  }

  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 3944
function main(input) {
  const inputs =input.split('\n')
  const [N] = inputs[0].split(' ').map(Number)
  const A = inputs[1].split(' ').map(Number)
  const Asorted = A.sort((a, b) => { return a < b ? -1 : 1 })
  const Amap = Array.from(new Set(A))
  let mem = []

  // console.log(Asorted)
  let count = 0
  for (let i = 0; i <= N-1; i++) {
    const n = Asorted[i]
    if (mem[n] === 0) {
      mem[n] = 1
      count++
      continue
    }
    if (mem[n] === 1) continue
    mem[n] = 0
    for (let j = 1; j * n <= Asorted[N-1]; j++) {
      mem[j * n] = 0
    }
  }
  // console.log(mem)
  console.log(Amap.length - count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

const int INF = 1000000000;

struct TSPSuffix {
    int n;
    vector<vector<int>> graph;

    TSPSuffix(int n) : n(n) {
        graph.assign(n, vector<int>(n, INF));
    }

    void addEdge(int u, int v, int w) {
        graph[u][v] = w;
    }

    int search() {
        int m = (1 << n) - 1;

        vector<vector<int>> memo(m + 1, vector<int>(n, -1));

        memo[m][0] = 0;

        return dp(0, 0, memo);
    }

    int dp(int s, int i, vector<vector<int>>&memo) {
        if (memo[s][i] != -1) {
            return memo[s][i];
        }
        int result = INF;
        for (int j = 0; j < n; j++) {
            if ((s & (1 << j)) == 0) {
                int l = dp(s ^ (1 << j), j, memo);
                result = min(result, graph[i][j] + l);
            }
        }
        memo[s][i] = result;

        return result;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    TSPSuffix tsp(n);
    for (int i = 0; i < m; i++) {
        int from, to, w;
        cin >> from >> to >> w;
        tsp.addEdge(from, to, w);
    }

    int ans = tsp.search();

    cout << (ans == INF? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 6144
#include<stdio.h>
int a[100],n;
void insertionSort(){
  int i,v,j;
  for(i=1;i<n;++i){
    v=a[i];
    j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      --j;
    }
    a[j+1]=v;
    for(j=0;j<n;++j){
      if(j) printf(" ");
      printf("%d",a[j]);
    }
    printf("\n");
  }
}
int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;++i) scanf("%d",&a[i]);
  for(i=0;i<n;++i){
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
  insertionSort();
  return 0;
}



Measured memory_bytes: 2692
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int u, k;
        cin >> u >> k;
        int *ary = new int[n+1];
        for(int j=1; j<=n; j++) {
            ary[j] = 0;
        }
        for(int j=0; j<k; j++) {
            int v;
            cin >> v;
            ary[v] = 1;
        }
        for(int j=1; j<=n; j++) {
            if(j != 1) cout << " ";
            cout << ary[j];
        }
        cout << "\n";
        delete[] ary;
    }
}



Measured memory_bytes: 3120
n = int(input())
a = []
for i in range(25):
	a.append((i+1)*4)
b = []
for i in range(14):
	b.append((i+1)*7)
c = []
for i in range(25):
	for j in range(14):
		if(a[i]+b[j] <= 100):
			c.append(a[i]+b[j])
d = []
d.extend(a)
d.extend(b)
d.extend(c)
e = []
e = list(set(d))
e.sort()
if n in e:
	print ("Yes")
else:
	print ("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll 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(ret);
  return (ret);
}

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

bool s(P l, P r) {
  return l.second < r.second;
}

signed main() {
  init();
  ll N, K;
  cin >> N >> K;

  map<ll, ll> m;
  rep(i, N) {
    ll a;
    cin >> a;
    m[a]++;
  }

  vector<P> P;
  for (auto mm : m) {
    P.pb({mm.first, mm.second});
  }

  sort(ALL(P), s);

  ll s = P.size() - K;
  ll ans = 0;
  rep(i, s) {
    ans += P[i].second;
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 19752
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	e=a*b;
	f=c*d;
	if(e>f){
		printf("%d",e);
	}
	else if(f>e){
		printf("%d",f);
	}
	else{
		printf("%d",e);
	}
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ts := strings.Repeat(".", w)
	rr := make([]bool, h)  // 圧縮可能な行
	rc := make([]bool, w)  // 圧縮可能な列
	a := make([]string, h) // 入力行
	for i := range a {
		fmt.Scan(&a[i])
		if a[i] == ts { // i行目は圧縮可能
			rr[i] = true
		}
	}
	// 列をチェックする
	for i := 0; i < w; i++ {
		ok := true
		for j := 0; j < h; j++ {
			if a[j][i] != '.' {
				ok = false
				break
			}
		}
		if ok { // i列目は圧縮可能
			rc[i] = true
		}
	}
	for i := 0; i < h; i++ {
		if !rr[i] {
			for j := 0; j < w; j++ {
				if !rc[j] {
					fmt.Print(string(a[i][j]))
				}
			}
			fmt.Println()
		}
	}
}


Measured memory_bytes: 768
def resolve():
    a, b = map(int, input().split())
    if a < 0 and b < 0:
        print("Positive" if (b - a) % 2 else "Negative")
    elif a > 0 and b > 0:
        print("Positive")
    else:
        print("Zero")


if __name__ == "__main__":
    resolve()


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

#define int long long

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

string s;

signed main() {
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
using namespace std;

int main()
{
	int N, K,h,x;
	vector<int> H;
	cin >> N>> K;
	for (int i = 0; i < N; i++) {
		cin >> h;
		H.push_back(h);
	}
	sort(H.begin(), H.end());
	int X = H[N-1] - H[0];
	for (int n = 0; n <= N - K; n++) {
		x = H[n+K-1] - H[n];
			if (x <= X) { X = x; }
	}
	cout << X << endl;

	
	return 0;
}

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

int main(){
	ll n,m,k;
	cin >> n >> m >> k;
	vector<ll> a(n+1,0);
	vector<ll> b(m+1,0);
	REP(i,n) cin >> a[i];
	REP(i,m) cin >> b[i];
	REP(i,n){
		 a[i] += a[i-1];
	}
	REP(i,m){
		 b[i] += b[i-1];
	}
	ll ans = 0;
	rep(i,n+1){
		if(a[i] > k) {
			break;
		}
		ll r = m+1;
		ll l = 0;
		while(r-l>1){
			ll t = (l + r)/2;
			if(b[t] > k - a[i]){
				r = t;
			}else{
				l = t;
			}
		}
		ans = max(ans, i+l);
	}
	cout << ans << endl;
    return 0;
}



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

int main(){
  int K, A, B;
  cin >> K >> A >> B;
  if(B % K == 0 || A % K == 0 | B / K - A / K >= 1){
    cout << "OK" << "\n";
  }
  else cout << "NG" << "\n";
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-WelcomeToAtCoder.py
#
N, M = map(int, input().split())
ac_list = [0] * N
wa_list = [0] * N
ac = int(0)
wa = int(0)
is_correct = [False] * N

if M == 0:
    print("0 0")
    exit()

for i in range(M):
    p, s = input().split()
    p = int(p) - 1
    if not is_correct[p]:
        if s == "AC":
            is_correct[p] = True
            ac_list[p] += 1
        else:
            wa_list[p] += 1

for i in range(N):
    if is_correct[i]:
        ac += ac_list[i]
        wa += wa_list[i]

print(ac, wa)







Measured memory_bytes: 5364
#include <stdio.h>

int main(){
    int H,W,i,j;
    while(1){
        scanf("%d%d",&H,&W);
        if(H!=0 && W!=0){
            for(i=0;i<H;i++){
                if(i==0||i==H-1){
                    for(j=0;j<W;j++){
                        printf("#");
                    }
                }
                if(1<=i&&i<=H-2){
                    for(j=0;j<W;j++){
                        if(j==0||j==W-1){
                            printf("#");
                        }
                        else{
                            printf(".");
                        }
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
        if(H==0&&W==0){
            break;
        }
    }
    return 0;
}


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

int main(){
  int h, w;
  cin >> h >> w;
  for(int i=0; i<w+2; i++)cout << '#';
  cout << endl;
  for(int i=0; i<h; i++){
    cout << '#';
    for(int j=0; j<w; j++){
      char a;
      cin >> a;
      cout << a;
    }
    cout << '#' << endl;
  }
  for(int i=0; i<w+2; i++)cout << '#';
  return 0;
}


Measured memory_bytes: 256
import fractions
a,b,c,d = map(int,input().split())
x = b//c + b//d - b//(c*d//fractions.gcd(c,d))
y = (a-1)//c + (a-1)//d - (a-1)//(c*d//fractions.gcd(c,d))
print(b-(a-1)-x+y)


Measured memory_bytes: 5048
module.exports=function(r){var t={};function n(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=r,n.c=t,n.d=function(r,t,e){n.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:e})},n.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},n.t=function(r,t){if(1&t&&(r=n(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)n.d(e,o,function(t){return r[t]}.bind(null,o));return e},n.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(t,"a",t),t},n.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},n.p="",n(n.s=0)}([function(r,t,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,t,n){"use strict";function e(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var n=[],e=!0,o=!1,u=void 0;try{for(var i,l=r[Symbol.iterator]();!(e=(i=l.next()).done)&&(n.push(i.value),!t||n.length!==t);e=!0);}catch(r){o=!0,u=r}finally{try{e||null==l.return||l.return()}finally{if(o)throw u}}return n}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var t=e(r[0].split(" ").map(function(r){return Number(r)}),2),n=t[0],o=t[1],u=[],i=0;i<n;i++)u.push([]);for(var l=0;l<o;l++){var a=e(r[l+1].split(" ").map(function(r){return Number(r)-1}),2),f=a[0],c=a[1];u[f].push(c),u[c].push(f)}var p=function(r){var t=r.length,n=new Array(t).fill(-1),e=new Array(t).fill(-1),o=[];return function t(u,i,l){n[u]=l++;e[u]=n[u];var a=!0;var f=!1;var c=void 0;try{for(var p,s=r[u][Symbol.iterator]();!(a=(p=s.next()).done);a=!0){var y=p.value;if(-1==n[y])e[u]=Math.min(e[u],t(y,u,l)),e[y]==n[y]&&o.push({from:u,to:y});else{if(i==y)continue;e[u]=Math.min(e[u],e[y])}}}catch(r){f=!0,c=r}finally{try{a||null==s.return||s.return()}finally{if(f)throw c}}return e[u]}(0,0,0),o}(u);console.log(p.length)}},function(r,t){r.exports=require("fs")}]);

Measured memory_bytes: 7372
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using ip = pair<int,int>;
using lp = pair<ll,ll>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll atcoder = int(1e9 + 7);

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

ll ketawa(ll a) {
	if (a < 10)return a;
	return ketawa(a / 10) + a % 10;
}

int main() {
	
	int n;
	cin >> n;
	vi v (n);

	int mina = inf, maxa = -inf;
	int mini, maxi;
	bool flag = true;

	rep(i, n) {
		cin >> v[i];
		if (v[i] > maxa) {
			maxa = v[i];
			maxi = i + 1;
		}
		else if (v[i] < mina) {
			mina = v[i];
			mini = i + 1;
		}
		if (i != 0 && v[i] < v[i - 1])flag = false;
	}

	if (flag)pr(0);
	else {
		if (abs(mina) > abs(maxa)) flag = false;
		else flag = true;

		pr(2 * n - 1);

		if (flag) {
			rep(i, n)cout << maxi << ' ' << i + 1 << endl;
			for (int i = 1; i < n; i++)cout << i << ' ' << i + 1 << endl;
		}
		else {
			rep(i, n)cout << mini << ' ' << i + 1 << Endl;
			for (int i = n; i > 1; i--)cout << i << ' ' << i - 1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
int main() {
	int N = 0;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L.at(i);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (i < j && j < k) {
					if ((L.at(i) - L.at(j)) * (L.at(j) - L.at(k)) * (L.at(k) - L.at(i)) != 0) {
						if (abs(L.at(i) - L.at(j)) < L.at(k) && L.at(k) < L.at(i) + L.at(j)) {
							ans++;
						}
					}
				}
			}
		}
	}
	cout << ans;
}



Measured memory_bytes: 3576
#include <iostream>

void flip(int& a, int& b)
{
	if (a>b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
}

int main()
{
	using namespace std;
	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	for (int i = 0; i<2; i++)
		flip(a[i], a[i + 1]);

	flip(a[0], a[1]);
	cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
	cin >> a[1];
	return 0;
}

Measured memory_bytes: 3096
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if sum(A)<sum(B):
  print(-1)
else:
  D = [a-b for a,b in zip(A,B)]
  D.sort()
  
  import bisect
  i = bisect.bisect_left(D,0)
  up = - sum(D[:i])
  
  j=0
  while up>0:
    j += 1
    up -= D[-j]
    
  print(i + j)

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

using ll = long long;
vector<ll> apply(vector<int> perm, vector<ll> a){
	int n = a.size();
	vector<ll> b(n);
	for(int i = 0; i < n; i++){
		b[i] = a[perm[i]];
	}
	return b;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, x;
	cin >> n >> x;
	vector<ll> b(n), l(n), u(n);
	vector<int> ind(n);
	vector<ll> wgt(n);
	for(int i = 0; i < n; i++){
		cin >> b[i] >> l[i] >> u[i];
		ind[i] = i;
		wgt[i] = u[i] * (x - b[i]) + l[i] * b[i];
	}
	sort(ind.begin(), ind.end(), [&](int a, int b) -> bool {
		return wgt[a] > wgt[b];
	});
	b = apply(ind, b);
	l = apply(ind, l);
	u = apply(ind, u);
	ll s = -1;
	ll e = x * n;
	while (s + 1 < e){
		ll mid = (s + e) / 2;
		// study mid hours
		ll full = mid / x;
		ll part = mid - x * full;
		bool works = false;
		ll psum = 0;
		for(int i = 0; i < full; i++){
			psum += u[i] * (x - b[i]);
		}
		for(int i = full; i < n; i++){
			psum += l[i] * -b[i];
		}
		for(int i = 0; i < n; i++){
			ll diff = psum;
			if(i >= full){
				diff -= l[i] * -b[i];
			} else {
				diff -= u[i] * (x - b[i]);
				diff -= l[full] * -b[full];
				diff += u[full] * (x - b[full]);
			}
			diff += max(l[i] * (part - b[i]), u[i] * (part - b[i]));

			if(diff >= 0){
				works = true;
			}
		}
		if(works){
			e = mid;
		} else {
			s = mid;
		}
	}
	cout << e << '\n';
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  bool suc = 0;
  if(a == b && b != c) suc = 1;
  if(a == c && a != b) suc = 1;
  if(b == c && a != b) suc = 1;
  string ans = suc ? "Yes" : "No";
  cout << ans << endl;
}

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

int main(){
  int n,z,w,i,max1,max2,max;
  cin >> n >> z >> w;
  int a[n];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  if(n==1)cout << abs(a[n-1]-w);
  else{
    max1=abs(a[n-1]-w);
    max2=abs(a[n-2]-a[n-1]);
    if(max1>max2)max=max1;
    else max=max2;
    cout << max;
  }
}


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

int N,Q;
ll A[100005];int len;
ll F[100005],c[100005];

void Solve(ll d,ll w){
	int j=upper_bound(A+1,A+len+1,d)-A-1;
	if(!j) c[1]+=w,c[d+1]-=w;
	else F[j]+=d/A[j]*w,Solve(d%A[j],w);
}

int main(){
	scanf("%d%d",&N,&Q);
	A[++len]=N;
	while(Q--){
		ll Ai;scanf("%lld",&Ai);
		while(len&&A[len]>=Ai) len--;
		A[++len]=Ai;
	}
	F[len]=1;
	for(int i=len;i>=2;i--) F[i-1]+=A[i]/A[i-1]*F[i],Solve(A[i]%A[i-1],F[i]);
	c[1]+=F[1];c[A[1]+1]-=F[1];
	for(int i=1;i<=N;i++) printf("%lld\n",c[i]+=c[i-1]);
}

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    priority_queue<ll, vector<ll>, greater<ll> > que;
    vector<pair<ll,ll>> bc(m);
    rep(i, 0, n){
        cin >> a[i];
        que.push(a[i]);
    }
    rep(i, 0, m) cin >> bc[i].second >> bc[i].first;
    sort(bc.begin(),bc.end(),greater<pair<ll,ll>>());

    bool f = false;
    rep(i, 0, m){
        rep(j, 0, bc[i].second){
            ll t = que.top();
            if(t < bc[i].first){
                que.pop();
                que.push(bc[i].first);
            }else{
                f = true;
                break;
            }
        }if(f) break;
    }

    ll ans = 0;
    while(!que.empty()){
        ll t = que.top();
        ans += t;
        que.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3704