akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;i++)
int k,n,h[110000],ans,te;
int main(){
	scanf("%d%d",&n,&k);
	fo(i,1,n) scanf("%d",&h[i]);
	sort(h+1,h+n+1);
	ans=h[k]-h[1];
	fo(i,2,n-k+1){
		te=h[i+k-1]-h[i];
		if (te<ans) ans=te;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
H,W=list(map(int,raw_input().split()))
a = []
for i in range(H):
    a.append(list(raw_input()))
#print a

dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]

cnt=0
for i in range(H):
	for j in range(W):
		if a[i][j]==".":
			cnt=0
			for k in range(8):
				#print dx[k],dy[k]
				x=i+dx[k]
				y=j+dy[k]
				if x>=0 and x<H and y>=0 and y<W and a[x][y]=="#":
					cnt+=1
			a[i][j]=cnt
			#print i,j,cnt


for i in range(H):
	print ''.join(map(str,a[i]))
					

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

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

int main() {
    int N;
    cin >> N;

    vector<int> s = {111, 222, 333, 444, 555, 666, 777, 888, 999};

    int i;
    for (i = 0; i < s.size(); i++) {
        if (N <= s.at(i))
            break;
    }

    cout << s.at(i) << endl;
}


Measured memory_bytes: 256
//D
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
int main(){
    int N;
    cin >> N;
    LL A[200005];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    LL ans = 0;
    LL tmp = 0;
    int itr = 0;
    for(int i=0; i<N; i++){
        while((tmp + A[i]) != (tmp ^ A[i])){
            tmp -= A[itr];
            ans += i - itr;
            itr++;
        }
        tmp += A[i];
    }
    while(itr != N){
        ans += N - itr;
        itr++;
    }
        
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int count = 0;
    int A;
    int B;
    int AB;
    int C;
    int sqrtAB;
    for(C=1; C<N; C++){
        AB = N-C;
        if(AB==1){
            count++;
            continue;
        }
        sqrtAB = ceil(sqrt(AB));
        if(pow(sqrtAB, 2)==AB){
            sqrtAB += 1;
        }
        for(B=1; B<sqrtAB; B++){
            if(AB%B!=0){
                continue;
            }
            A = AB/B;
            if(A==B){
                count++;
                continue;
            }
            count += 2;
        }   
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3628
import numpy as np
import math
import fractions
gcd = math.gcd if hasattr(math, "gcd") else fractions.gcd
lcm = lambda x, y: (x * y) // gcd(x, y)

lcm_ufunc = np.frompyfunc(lcm, 2, 1)

N = int(input())
a = np.array([int(i) for i in input().split()])
m = lcm_ufunc.reduce(a) - 1
print(np.mod(m, a).sum())

Measured memory_bytes: 13560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	int ce = x - a;
	cout << ce - (ce / b) * b << endl;
}	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	int a,b,c,d;
	int e,f;
	cin>>n;
	a=n/1000;
	b=n%1000;
	c=b/100;
	d=b%100;
	e=d/10;
	f=d%10;
	int total=0;
	if(a==2){
		total++;
	}
	if(c==2){
		total++;
	}
	if(e==2){
		total++;
	}
	if(f==2){
		total++;
	}
	cout<<total<<endl;
	return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  string s; cin >> s;
  cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void) {
    ll n, t_sum = 0, a_sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll t, a;
        cin >> t >> a;
        ll mx = pow(10, 18) / max(a, t);
        
        if (i == 0) {
            t_sum = t;  a_sum = a;
        }
        else {
            ll low = 0, high = mx;
            while (high - low > 1) {
                ll mid = (low + high) / 2;
                if (t * mid < t_sum || a * mid < a_sum) low = mid;
                else high = mid;
            }
            t_sum = t * high;
            a_sum = a * high;
            //cout << t_sum <<" " << a_sum << endl;
        }
    }
    cout << t_sum + a_sum << endl;
}

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


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<lint> h(n + 2); for (int i = 0; i < n; i++) cin >> h[i + 1];
  V<lint> a = h;
  h[0] = h[n + 1] = -1;
  auto add = [&] {
    stack<int> s;
    s.push(0);
    for (int i = 1; i < n + 1; i++) {
      while (h[s.top()] >= h[i]) s.pop();
      a[i] += h[i] * (i - s.top() - 1);
      s.push(i);
    }
  };
  add();
  reverse(h.begin(), h.end());
  reverse(a.begin(), a.end());
  add();
  cout << *max_element(a.begin(), a.end()) << '\n';
}


Measured memory_bytes: 4832
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); //入出力高速化
	int N,M,R; cin >> N >> M >> R;
	vector<int> r(R);
	rep(i,R) {
		cin >> r[i];
		r[i]--;
	}
	vector<vector<ll>> d(N, vector<ll>(N,1e18));
	rep(i,N) d[i][i] = 0;
	rep(i,M) {
		ll A,B,C; cin >> A >> B >> C;
		A--; B--;
		d[A][B] = d[B][A] = C;
	}

	rep(k,N) {
		rep(i,N) {
			if (d[i][k] == 1e18) continue;
			rep(j,N) {
				if (d[k][j] == 1e18) continue;
				chmin(d[i][j],d[i][k] + d[k][j]);
			}
		}
	}

	vector<int> v(R);
	rep(i,R) v[i] = i;
	ll ans = 1e18;
	do {
		ll dd = 0;
    rep(i,R-1) dd += d[r[v[i]]][r[v[i+1]]];
		chmin(ans,dd);
	} while (next_permutation(all(v)));
	
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define pll  pair<ll,ll>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

void solve()
{
	int x,a,b;
	cin>>x>>a>>b;
	if(b<=a)
		cout<<"delicious";
	else if(x+a>=b)
		cout<<"safe";
	else
		cout<<"dangerous";
}            
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3584
while 1:
     H, W = map(int,input().split())
     if H == 0 and W == 0:
        break
     for i in range (H):
         if i!=0:
            print()
         for j in range (W):
             print('#',end="")
             if i == H-1 and j == W-1:
                 print()
                 print()



Measured memory_bytes: 7000
import sys
input = sys.stdin.readline
N=int(input())
A=[0]
a=list(map(int,input().split()))
for i in range(N):
    A.append(a[i])
A.append(0)
#print(A)
l=0
for i in range(N+2):
    l+=abs(A[i]-A[i-1])
#print(l)
for i in range(1,N+1):
    ans=l
    if (A[i+1]-A[i])*(A[i]-A[i-1])<0:
        ans=l-2*min(abs(A[i+1]-A[i]),abs(A[i]-A[i-1]))
    print(ans)

"""if amin>0:
    for i in range(N):
        if A[i]!=amax:
            print(amax*2)
        else:
            print(amax2*2)
elif amax<0:
    for i in range(N):
        if A[i]!=amin:
            print(-amin*2)
        else:
            print(-amin2*2)
else:
    for i in range(N):
        if A[i]!=amax:
            if A[i]!=amin:
                print("A",amax*2-amin*2)
            else:
                if amin2>=0:
                    print(amax*2)
                else:
                    print(amax*2-amin2*2)
        else:
            if amax2<0:
                print(-amin*2)
            else:
                print(-amin*2+amax2*2)"""


Measured memory_bytes: 62572
#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[200001],b[200001],c[200001];
int i,j,x,y,cnt=0;
int leng[100001],par[100001],kurabu[100001]={0};
int main(void)
{
	bool  flg=false;
	
	cin>>n>>m>>k;
	
	for(i=1;i<=k;i++) cin>>a[i]>>b[i]>>c[i];
	
	for(j=1;j<=n;j++) {leng[j]=1,par[j]=j;}
	
	for(i=1;i<=k;i++){
		if(a[i]==1){
		
			if(b[i]>c[i]) x=c[i];
			else x=b[i];
			
			while(x!=par[x]) x=par[x];
			
			if(b[i]>c[i]) y=b[i];
			else y=c[i];
			
			while(y!=par[y]) y=par[y];
			
			if(x!=y){
			
				if(leng[x]>leng[y]){
					par[y]=x;
					if(kurabu[y]==0){
						kurabu[y]=kurabu[x];
					}
					else if(kurabu[y]!=0&&kurabu[x]!=0&&
								kurabu[y]!=kurabu[x]){
						cnt=i;
						flg=true;
						break;
					}
				}	
				
				else if(leng[x]<leng[y]){
						par[x]=y;
					if(kurabu[x]==0){
						kurabu[x]=kurabu[y];
					}
					else if(kurabu[x]!=0&&kurabu[y]!=0&&
								kurabu[x]!=kurabu[y]){
						cnt=i;
						flg=true;
						break;
					}
				}	
				
				else {
					par[y]=x,leng[x]++;
					if(kurabu[x]==0){
						kurabu[x]=kurabu[y];
					}
					else if(kurabu[x]!=0&&kurabu[y]!=0&&
								kurabu[x]!=kurabu[y]){
						cnt=i;
						flg=true;
						break;
					}
				}
				
			}
		}
		else {
		
			x=b[i];
			while(x!=par[x]) x=par[x];
			
			if(kurabu[x]==0||kurabu[x]==c[i]){
					kurabu[x]=c[i];
			}
			
			else if(kurabu[x]!=c[i]){
				cnt=i;
				flg=true;
				break;
			}	
		}
	}

	cout<<((flg)?cnt:0)<<endl;
	
	return 0;
	
}	


Measured memory_bytes: 6548
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(){
  int a,b;
  cin>>a>>b;
  if(a%2==0 || b%2==0){
    cout<<"Even"<<endl;
  }
  else{
    cout<<"Odd"<<endl;
  }
	

return 0;
}



Measured memory_bytes: 256
k = int(input())
l = list(map(int,input().split()))
for i in range(k-1,-1,-1):
    if i == k-1:
        if l[i] == 2:
            ans = [2,3]
        else:
            ans = [-1]
            break
    else:
        if l[i] > ans[1]:
            ans = [-1]
            break
        else:
            if l[i] >= ans[0]:
                ans[0] = l[i]
            else:
                b0 = ans[0]
                c = l[i]
                if b0%c == 0:
                    ans[0] = b0
                else:
                    if (b0//c+1)*c > ans[1]:
                        ans = [-1]
                        break
                    else:
                        ans[0] = (b0//c+1)*c
            b1 = ans[1]
            c = l[i]
            if b1%l[i] == 0:
                ans[1] = b1+l[i]-1
            else:
                ans[1] = (b1//c)*c+c-1
    
    #print(ans)
for i in ans:
    print(i,end=" ")

Measured memory_bytes: 63856
N = int(input())
v = list(map(int, input().split()))
v.sort()

sum = 0.0
h = [0.0]*N

for i in range(2): #0, 1
    h[i] = ((0.5)**(N-1))*v[i]

for i in range(2,N):
    h[i] = ((0.5)**(N-i))*v[i]

for i in range(N):
    sum = sum + h[i]
    
print(sum)

Measured memory_bytes: 3064
import numpy as np
a,b,h,m=map(int,input().split())
# print([a,b,h,m])

hour_theta= np.pi*(60*h+m)/360
minute_theta=np.pi*m/30

theta = abs(hour_theta-minute_theta)
# print(hour_theta)
# print(minute_theta)
# print(theta)
# print(np.cos(2.356194490192345))
ans=np.sqrt((a**2)+(b**2)-2*a*b*np.cos(theta))
print('{:.11f}'.format(ans))

Measured memory_bytes: 27192
N = gets.to_i
V = gets.split.map(&:to_i)

counts = Array.new(2) { Hash.new(0) }
V.each_with_index do |v, idx|
  counts[idx % 2][v] += 1
end

sorted1 = counts[0].sort_by { |k, v| -v }
sorted2 = counts[1].sort_by { |k, v| -v }

# p N
# p counts
# p sorted1
# p sorted2

ans = Float::INFINITY
0.upto(1) do |i|
  0.upto(1) do |j|
    next if sorted1[i] && sorted2[j] && sorted1[i][0] == sorted2[j][0]
    next if sorted1[i].nil? && sorted2[j].nil?
    # puts "i:#{i}, j:#{j}, #{sorted1[i]} #{sorted2[j]}"

    a = (N / 2 - (sorted1[i] ? sorted1[i][1] : 0)) + (N / 2 - (sorted2[j] ? sorted2[j][1] : 0))
    ans = a if ans > a
  end
end

puts ans

Measured memory_bytes: 20472
#include <bits/stdc++.h>
#define ll long long
ll mod=1000000007;
#define vl vector<ll>
#define pl pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define RFOR(i,a,b) for(ll i=b-1;i>=a;i--)
#define rsort(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
set<string>s;
int main(){
    ll n;
    cin>>n;
    rep(i,n){
        string S;
        cin>>S;
        if(S=="find"){
           cin>>S;
           cout<<(s.find(S)!=s.end()?"yes":"no")<<endl;
        }else{
            cin>>S;
            s.insert(S);
        }
    }
}


Measured memory_bytes: 32148
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int dp[100001] = {0};
  for (int i = 0; i <= K; i++) {
    if (dp[i] == 0) {
      for (int j = 0; j < N; j++) {
        int ni = i + a[j];
        if (ni > K) continue;
        dp[ni] = 1;
      }
    }
  }

  // for (int i = 0; i <= K; i++) {
  //   cout << dp[i];
  // }cout << endl;

  cout << (dp[K] == 1 ? "First" : "Second") << endl;

  return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] b = new int[m];
		int[][] A = new int[n][m];
		int[] c = new int[n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				A[i][j] = scan.nextInt();
			}
		}
		for(int i = 0; i < m; i++){
			b[i] = scan.nextInt();
		}

		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				c[i] += A[i][j] * b[j];
			}
			System.out.printf("%d\n", c[i]);
		}
	}
}

Measured memory_bytes: 40328
#include <iostream>
using namespace std;
int h,w,k;
char g[10][10];
int main(){
    cin>>h>>w>>k;
    for(int i=0;i<h;i++){
        cin>>g[i];
    }
    int ans=0;
    for(int s=0;s<1<<h+w;s++)
	{
        int c=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                c+=!(s>>i&1)&&!(s>>h>>j&1)&&g[i][j]=='#';
            }
        }
        ans+=c==k;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int dl[100010],dr[100010],px[100010],py[100010];
std::pair<int,int>s[100010];
int f[100010],udr[100010],t[100010];
void update(int x,int d){while(x<=*udr)inc(t[x],d),x+=x&-x;}
int query(int x){int r=0;while(x)inc(r,t[x]),x-=x&-x;return r;}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi();
	for(int i=1;i<=n;++i)px[i]=gi();
	for(int i=1;i<=m;++i)py[i]=gi();
	int l=1,r=n;
	while(l<=n&&px[l]<py[1])++l;
	while(r&&px[r]>py[m])--r;
	if(l>r)puts("1"),exit(0);
	for(int i=l;i<=r;++i)px[i-l+1]=px[i];
	n=r-l+1;
	for(int i=1,j=1;i<=n;++i){
		while(py[j]<px[i])++j;
		dr[i]=py[j]-px[i];
	}
	for(int i=n,j=m;i;--i){
		while(py[j]>px[i])--j;
		dl[i]=px[i]-py[j];
	}
	for(int i=1;i<=n;++i)s[i]={dl[i],dr[i]},udr[i]=dr[i];
	std::sort(udr+1,udr+n+1),*udr=std::unique(udr+1,udr+n+1)-udr-1;
	for(int i=1;i<=n;++i)s[i].se=std::lower_bound(udr+1,udr+*udr+1,s[i].se)-udr;
	std::sort(s+1,s+n+1);n=std::unique(s+1,s+n+1)-s-1;
	for(int l=1,r;l<=n;l=r+1){
		r=l;while(r<n&&s[r+1].fi==s[r].fi)++r;
		for(int i=r;i>=l;--i)update(s[i].se,1+query(s[i].se-1));
	}
	printf("%d\n",(query(*udr)+1)%mod);
	return 0;
}


Measured memory_bytes: 3072
<?php
// Your code here!
$input = (int)fgets(STDIN);
$sum = array();
for($i = 1; $i<=9; $i++){
    for($j=1; $j <=9; $j++){
        $sum[] = $i * $j;
    }
}
if(array_search($input,$sum) !== false){
    echo "Yes".PHP_EOL;
}else{
    echo "No".PHP_EOL;
}

Measured memory_bytes: 4728
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(3*n);
    rep(i,3*n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    for(int i = 3*n-2; i >= n; i -= 2){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
import sys
import  math
from heapq import *
import fractions
import bisect
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
ans_l=[0]*(10**5+5)
for i in A:
    ans_l[i]+=1

a_sum=0
for i in range(len(ans_l)):
    a_sum+=(i*ans_l[i])

Q=int(input())
for i in range(Q):
    B,C=nm()
    ans_l[C]+=ans_l[B]
    a_sum-=ans_l[B]*B
    a_sum+=ans_l[B]*C
    ans_l[B]=0
    print(a_sum)
    


        
    

Measured memory_bytes: 85392
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010;
const int Y=2500;
ll dp[N][N];
int n,x;
int a[N];
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%d%d",&n,&x);
	dp[0][Y]=1;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]-=x;
	for(int i=1;i<=n;i++){
		for(int j=-Y;j<=Y;j++){
			dp[i][j+Y+a[i]]+=dp[i-1][j+Y];
			dp[i][j+Y]+=dp[i-1][j+Y];
		}
	}
	printf("%lld\n",dp[n][Y]-1);
	return 0;
}

Measured memory_bytes: 2176
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

sys.setrecursionlimit(10 ** 6)

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))


def switch(bit, ans):
    check = [(bit >> i) & 1 for i in range(N)]
    light = 0
    for i in range(M):
        num = 0
        for l in s[i]:
            if check[l - 1] == 1:
                num += 1
        if num % 2 == p[i]:
            light += 1
    if light == M:
        ans += 1
    if bit == 1:
        return ans
    else:
        return switch(bit - 1, ans)


print(switch(2 ** N, 0))


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

using namespace std;

long x[3][1111], d[1111][1111];
long f(int k, int l, int a) {
	if (!l) return 0;
	if (k < l) return -1e17;
	if (d[k][l] < 1e16)
		return d[k][l];
	return d[k][l] = max(f(k - 1, l, a), f(k - 1, l - 1, a)
		+ x[0][k - 1] * (1 - (a & 4) / 2) + x[1][k - 1] * (1 - (a & 2)) + x[2][k - 1] * (1 - 2 * (a & 1)));
}
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			cin >> x[j][i];
	long r = 0;
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < n + 1; j++)
			for (int k = 0; k < n + 1; k++)
				d[j][k] = 1e17;
		r = max(r, f(n, m, i));
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 8960
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
 
int main(void){
  int n;
  cin>>n;
  cin.ignore();
  string line;
  string s = "Hoshina";
  while(getline(cin, line)){
    while(line.find("Hoshino")!=string::npos){
      line.replace(line.find("Hoshino"), s.size(), s);
    }
    cout<<line<<endl;
  }
  return 0;
}


Measured memory_bytes: 3004
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt();
		BT tree=new BT();
		
		for(int i=0;i<n;i++) {
			String odr=in.next();
			
			if(odr.equals("insert")) {
				int key=Integer.parseInt(in.next());
				tree.insert(key);
			}
			
			else if(odr.equals("print")) {
				Queue<Integer> Q=new ArrayDeque<>(tree.walk('I'));
				PrintWriter out=new PrintWriter(System.out);
				while(!Q.isEmpty())out.print(" "+Q.remove());
				out.println();
				Q=tree.walk('F');
				while(!Q.isEmpty())out.print(" "+Q.remove());
				out.println();
				out.flush();
			}
		}
	}

}

class BTNode{
	int key;
	BTNode Parent,Left,Right;
	
	BTNode(int k){
		key=k;
	}
}

class BT{
	BTNode root,dummy;
	int NIL=-2000000001;
	int size=0;
	
	Queue<Integer> Q;
	
	BT(){
		root=new BTNode(NIL);
		dummy=new BTNode(NIL);
		root.Parent=dummy;
		root.Left=dummy;
		root.Right=dummy;
	}
	
	void insert(int k) {
		if(size==0) {
			root.key=k;
			size++;
			return;
		}
		
		BTNode node=new BTNode(k),s=root,p=root;
		node.Left=dummy;node.Right=dummy;
		
		while(s!=dummy) {
			p=s;
			if(k<s.key)s=s.Left;
			else s=s.Right;
		}
		
		node.Parent=p;
		size++;
		
		if(k<p.key)p.Left=node;
		else p.Right=node;
	}
	
	Queue<Integer> walk(char odr) {
		Q=new ArrayDeque<>();
		if(odr=='F')preWalk(root);
		else if(odr=='I')inWalk(root);
		return Q;
	}
	
	void preWalk(BTNode node) {
		Q.add(node.key);
		if(node.Left!=dummy)preWalk(node.Left);
		if(node.Right!=dummy)preWalk(node.Right);
	}
	
	void inWalk(BTNode node) {
		if(node.Left!=dummy)inWalk(node.Left);
		Q.add(node.key);
		if(node.Right!=dummy)inWalk(node.Right);
	}
	
}



Measured memory_bytes: 212452
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

	public Main() {
		FastScanner scanner = new FastScanner();
		long X = scanner.nextLong();
		long K = scanner.nextLong();
		long D = scanner.nextLong();

		long A = -(X/D);

		if ( Math.abs(D*A+X) > Math.abs(D*(A+1)+X)) {
			A = A + 1;
		}

		if ( K <= Math.abs(A) ){
			if (A < 0){
				System.out.println( Math.abs(D*(-K)+X) );
			} else {
				System.out.println( Math.abs( D*K+X ) );
			}
		} else {
			if ( (K-A) % 2 == 0){
				System.out.println( Math.abs(D*A+X) );
			}  else {
				if( Math.abs( D*(A+1)+X ) > Math.abs( D*(A-1)+X ) ){
					System.out.println( Math.abs( D*(A-1)+X ));
				} else {
					System.out.println( Math.abs( D*(A+1)+X ) );
				}
			}
		}

	}

	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 32548
#include <iostream>
#include <bits/stdc++.h>
#define mod 998244353
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    while(a[0]=='0'){
        a.erase(a.begin());
    }
    if(a=="")a="0";
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int check(string a, string b){
    for(int i=0; i<a.size(); i++){
        if(a[i]>b[i])return 1;
        if(b[i]>a[i])return -1;
    }
    return 0;
}
class data{
public:
    ll v,d,p;
    data(){}
    data(ll vv, ll dd, ll pp){
        v=vv;  d=dd; p=pp;
    }
};

int primeFactors(int n)
{
    ll c=0;
    while (n % 2 == 0)
    {
        c++;
        n = n/2;
    }
    for (int i = 3; i*i <= n; i = i + 2)
    {
        while (n % i == 0)
        {
            c++;
            n = n/i;
        }
    }
    if (n > 2)
        c++;
    return c;
}

int main()
{
    Fastio();
    ll n,x; cin>>n>>x;
    ll w[n+1]={0},p[n+1]={0};
    for(int i=1; i<=n; i++){
        cin>>w[i]>>p[i];
    }
    ll dp[n+1][x+1];
    memset(dp,0,sizeof(dp));
    for(int i=1; i<=n; i++){
        for(int y=0; y<=x; y++){
            if(w[i]<=y)dp[i][y]=max(dp[i-1][y], dp[i-1][y-w[i]]+p[i]);
            else dp[i][y]=dp[i-1][y];
        }
    }
    cout<<dp[n][x]<<'\n';

    return 0;
}


Measured memory_bytes: 79232
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines[0]);
  console.log(' ' + buildMaxHeap(lines[1].split(' ')).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



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

int main() {
  long A, B, K;
  
  cin >> A >> B >> K;

  cout << max(A-K,0L) << ' ' <<  max(min(B-(K-A),B),0L) <<  endl;
  return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    stack<ll> st;
    ll now = n;
    while(now){
        for(i = m;i >= 1;--i){
            if(now-i < 0) continue;
            else if(s.at(now-i) == '0'){
                st.push(i);
                now -= i;
                break;
            }
        }
        if(i == 0){
            cout << -1 << endl;
            return 0;
        }
    }
    while(!st.empty()){
        cout << st.top() << endl;
        st.pop();
    }
    return 0;
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N, M, D;
    vector<int> A;
    vector< vector<int> > R;
    void input() {
        cin >> N >> M >> D;
        A.resize(M); cin >> A;
        R.resize(D);
        for (int i = 0; i < D; i++) {
            R[i].resize(M); cin >> R[i];
        }
    }

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

    bool check(int n, int d) {
        for (int i = 0; i < M; i++) {
            if (R[d][i] < 0) continue;
            if (n % A[i] != R[d][i]) return false;
        }
        return true;
    }

    void solve() {

        ll x = N;
        for (int d = 0; d < D; d++) {
            int a = 0;
            int m = -1;
            ll L = 1;
            for (int i = 0; i < M; i++) {
                if (R[d][i] < 0) continue;
                L = lcm(L, A[i]);
                if (a < A[i]) {
                    a = A[i];
                    m = i;
                }
            }
            if (m < 0) continue;
            int n = R[d][m];
            for (; ; n += A[m]) {
                if (n > x) {
                    cout << -1 << endl;
                    return;
                }
                if (check(n, d)) {
                    break;
                }
            }
            x = (x - n) / L * L + n;
        }
        cout << x << endl;

    }
}

int main() {
    input(); solve();
    return 0;
}
 

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int total = 0;
    rep(i,n) {
        cin >> a[i];
        total += a[i];
    }
    int count = 0;
    rep(i,n) {
        if (a[i]*4*m < total) continue;
        count++;
    }
    if (count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

int r,c,q;
bool ri[50001];bool ci[50001];
bool rd[50001];bool cd[50001];
int A[50001];
int B[50001];
int order[50001];

void solve(){
    while(cin>>r>>c>>q&&!(r==0&&c==0&&q==0)){
        fill(ri,ri+50001,false);
        fill(ci,ci+50001,false);
        fill(rd,rd+50001,false);
        fill(cd,cd+50001,false);
        int yokod=0;
        int tated=0;
        for(int i = 0; i < q; i++)
            cin>>A[i]>>B[i]>>order[i];
        ll sum=0;
        // t©ç©Ä¢­
        for(int i = q-1; i >= 0; i--){
            // sÉ½¢µÄs¤
            if(A[i]==0){
                // Àç¹é®ìðs¤
                if(order[i]==0){
                    // ÈOsÁ½±Æª é
                    if(rd[B[i]]){
                        // ¡ã±ÌsðÊéN§½ßÍ³øÆÈé

                    }
                    // Ü¾
                    else{
                        rd[B[i]]=true;
                        if(!ri[B[i]])
                            yokod++;
                    }
                }
                // §½¹é
                else{
                    // ÈOsÁ½±Æª é
                    if(ri[B[i]]){
                        // nothing
                    }
                    else{
                        ri[B[i]]=true;
                        // àµÁ³êé®ìªsíêÄ¢È¢ÈçAÕç·
                        if(!rd[B[i]]){
                            sum+=-tated+c;
                            yokod++;
                        }
                    }
                }
            }
            // ñÉÎµÄs¤
            else{
                // Àç¹é®ìðs¤
                if(order[i]==0){
                    // ÈOsÁ½±Æª é
                    if(cd[B[i]]){
                        // ¡ã±ÌsðÊéN§½ßÍ³øÆÈé

                    }
                    // Ü¾
                    else{
                        cd[B[i]]=true;
                        if(!ci[B[i]])
                            tated++;
                    }
                }
                // §½¹é
                else{
                    // ÈOsÁ½±Æª é
                    if(ci[B[i]]){
                        // nothing
                    }
                    else{
                        ci[B[i]]=true;
                        // àµÁ³êé®ìªsíêÄ¢È¢ÈçAÕç·
                        if(!cd[B[i]]){
                            sum+=-yokod+r;
                            tated++;
                        }
                    }
                }
            }
        }
        cout<<sum<<endl;
    }
}

int main(){

    solve();

    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    int a = 1;
    REP(i, n) {
        a = min(a * 2, a + k);
    }
    cout << a << endl;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string  s; cin >> s; 
    int  n = sz(s),ans=0; 
    vi l(n+3,0),r(n+3,0);
    for (int i=0,c=0;i<n;i++){
    	if (s[i]=='<') c++;
    	else c=0;
    	l[i+1]=c;
    }
    for (int i=n-1,c=0;i>=0;i--){
    	if (s[i]=='>') c++;
    	else c=0;
    	r[i]=c;
    }
    for (int i=0;i<=n;i++) ans += max(l[i],r[i]);
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 11640
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n<1200)
            printf("ABC\n");
        if(n>=1200&&n<2800)
            printf("ARC\n");
        if(n>=2800)
            printf("AGC\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, M; cin >> N >> M;
	vector<pii>Q(M);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		Q[i].first = b;
		Q[i].second = a;
	}
	sort(Q.begin(), Q.end());
	int ans = 1;
	int t = Q[0].first;
	for (int i = 1; i < M; ++i) {
		if (Q[i].second >= t) {
			ans++;
			t = Q[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n;
VI pena;
VVI gain;
int pena_sum;
int eval(VI &order)
{
    VI last(26, -1);
    int ret = 0;
    int cur_pena = pena_sum;
    rep(i, n)
    {
        ret += gain[i][order[i]];
        cur_pena -= pena[order[i]] * (i - last[order[i]]);
        last[order[i]] = i;
        ret -= cur_pena;
        cur_pena += pena_sum;
    }
    return ret;
}
int eval_diff(VI &order, int start, VVI &log)
{
}
void print(VI &order)
{
    for (auto &&x : order)
    {
        cout << x + 1 << endl;
    }
}

int choice_weighted()
{
    int r = mt() % pena_sum;
    rep(i, 26)
    {
        r -= pena[i];
        if (r <= 0)
            return i;
    }
}

void search()
{
    auto starttime = clock();
    typedef pair<int, VI> Tact;
    priority_queue<Tact> pque;
    VI base(n);
    VI last(26, -1);
    rep(i, n)
    {
        int cur = -IINF;
        int penasum = 0;
        rep(j, 26)
        {
            penasum += pena[j] * (i - last[j]);
        }
        rep(j, 26)
        {
            if (cur < gain[i][j] - penasum + pena[j] * (i - last[j]))
            {
                base[i] = j;
                cur = gain[i][j] - penasum + pena[j] * (i - last[j]);
            }
        }
        last[base[i]] = i;
    }
    auto best = base;
    int bscore = eval(base);
    pque.push({eval(base), base});
    int width = 20;
    cerr << bscore << endl;
    int loopnum = 0;
    while (double(clock() - starttime) / CLOCKS_PER_SEC < 1.9)
    {
        auto next = pque;
        while (!pque.empty())
        {
            auto cur = pque.top();
            pque.pop();
            rep(i, 2)
            {
                cur.second[mt() % n] = choice_weighted();
                cur.first = eval(cur.second);
                next.push(cur);
            }
        }
        rep(i, min(width, (int)next.size()))
        {
            pque.push(next.top());
            next.pop();
        }
        loopnum++;
    }
    cerr << "ok" << endl;
    best = pque.top().second;
    bscore = pque.top().first;
    print(best);
    cerr << bscore << endl;
    cerr << loopnum << endl;
}
int main()
{
    cin >> n;
    pena = VI(26);
    gain = VVI(n, VI(26));
    rep(i, 26)
    {
        cin >> pena[i];
        pena_sum += pena[i];
    }
    rep(i, n)
    {
        rep(j, 26)
        {
            cin >> gain[i][j];
        }
    }
    search();
    return 0;
}

Measured memory_bytes: 3820
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let c: String = read();
    let all: &str = "abcdefghijklmnopqrstuvwxyz";

    let i = all.find(&c).unwrap();
    println!("{}", all.chars().nth(i + 1).unwrap());
}


Measured memory_bytes: 4352
n=int(input())
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  s=input()[0:1]
  if s=="M":m+=1
  elif s=="A":a+=1
  elif s=="R":r+=1
  elif s=="C":c+=1
  elif s=="H":h+=1
ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  int aa = 0;
  for (int j = 0; j < n; j++) {
    std::cin >> a[j];
    aa ^= a[j];
  }
  for (int i = 0; i < n; i++) {
    int now = a[i] ^ aa;
    cout << now << endl;
  }
  return 0;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int count=0;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(i==j){
        continue;
      }else{
        count += d[i]*d[j];
      }
    }
  }
  cout << count << endl;
      
}

Measured memory_bytes: 256
N=gets.to_i
CSFS=[]
(N-1).times do
    c,s,f=gets.chomp.split(" ").map(&:to_i)
    CSFS.push([c,s,f])
end

MEMO={}
def calc(n, second)
    key = "#{n}_#{second}"
    return MEMO[key] if MEMO[key]

    c,s,f=CSFS[n]
    if s >= second
        ret = s+c
        MEMO[key] = ret
        return ret
    else
        rest=second%f
        ret = rest==0 ? second+c : second+f-rest+c
        MEMO[key] = ret
        return ret
    end
end

rets=[0]
while rets.length < N do
    rets = rets.map {|r| calc(rets.length-1, r) }
    rets.push(0)
end
rets.each do |r|
    puts r
end


Measured memory_bytes: 29820
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000003LL)
typedef long long Int;

int n, mi, memo[60000*4], cs[60000][2], w[60000];
vector<int> g[60000];
bool has[60000];

void add(int p, int q) {
    if (p > q) swap(p, q);
    g[p].push_back(q);
}

int pre(int p, int q) {
    if (p+1 == q) return -1;
    const int k = mi++;
    w[k] = q-p+1;
    has[k] = false;
    if (g[p].back() == q) {
        has[k] = true;
        g[p].pop_back();
    }
    const int r = g[p].back();
    rep (b, 4) memo[k*4|b] = -1;
    cs[k][0] = pre(p, r);
    cs[k][1] = pre(r, q);
    return k;
}

int rec(int k, int b) {
    if (w[k]%2 == 1 && (b == 0 || b == 3)) return 0;
    if (w[k]%2 == 0 && (b == 1 || b == 2)) return 0;
    if (k == -1) return b == 0 || b == 3;
    const int sig = k*4|b;
    if (memo[sig] != -1) return memo[sig];
    const int x = b&2, y = b&1;
    const int p = cs[k][0], q = cs[k][1];
    Int ans = 0;
    ans += (Int)rec(p, x) * rec(q, 2|y);
    ans += (Int)rec(p, x|1) * rec(q, y);
    if (b==3 && has[k]) {
        ans += (Int)rec(p, 0) * rec(q, 2);
        ans += (Int)rec(p, 1) * rec(q, 0);
    }
    return memo[sig] = ans % MOD;
}

int main() {
    for (;;) {
        int m, a, b;
        scanf("%d%d", &n, &m);
        if (n == 0) return 0;
        rep (_, m) {
            scanf("%d%d", &a, &b);
            add(a-1, b-1);
        }
        rep (i, n) add(i, (i+1)%n);
        rep (i, n) sort(g[i].begin(), g[i].end());
        mi = 0;
        pre(0, n-1);
        printf("%d\n", rec(0, 3));
    }
}

Measured memory_bytes: 12004
#!/usr/bin/env python3
if __name__ == '__main__':
  s = str(input()).split(" ")
  N = int(s[0])
  M = int(s[1])
  A, T = list(), list()
  for i in range(0,N):
    A.append(input())
  for i in range(0,M):
    T.append(input())

  # for i in range(0,N):
  #   for j in range(0,N):
  #     print(A[i][j], end='')
  #   print()
  ans = False
  for t in range(0, N-M+1):
    for l in range(0, N-M+1):
      ok = True
      for i in range(t, t+M):
        for j in range(l, l+M):
          if A[i][j] != T[i-t][j-l]:
            ok = False
      if ok:
        ans = True
  if ans:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 3064