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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 

using ll = long long;

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

constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i < v.size()-1)s<<", ";}s<<']';return s;}

int main(){

    int a, b;
    scanf("%d%d", &a, &b);
    ppp(lcm(a, b));




    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

ll va[41];

int pre(){
    for(int i = 0;i < 41;++i){
        ll temp = 0;
        for(int j = 1; j <= i;++j)
            temp += ((ll)1<<j);
        va[i] = temp + 1ll;
    }
    return 1;
}

int main(){
    pre();
    ll h;
    scanf(" %lld",&h);
    int ma = -1;
    while(h){
        ++ma;
        h>>=1;
    }
    printf("%lld\n",va[ma]);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
using namespace std;


int main(){
int n,w;
int va[110],we[110];
cin>>n>>w;
for(int i=0;i<n;i++) cin>>va[i]>>we[i];
int dp[10010]={0};
for(int i=0;i<n;i++){
for(int j=w;j>=0;j--){
if(j-we[i]>=0) dp[j]=max(dp[j-we[i]]+va[i],dp[j]);
}
}


cout<<dp[w]<<endl;
return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    sort(all(S));
    for(int i=1;i<S.size();++i){
        if(S[i]==S[i-1]){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

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

		System.out.println(solve(peopleCount));

	}

	static int solve(int[] peopleCount) {
		if (peopleCount[0]>0) {
			return 0;
		}
		for (int i=1;i<=11;i++) {
			if (peopleCount[i]>2) {
				return 0;
			}
		}
		if (peopleCount[12]>1) {
			return 0;
		}

		int ans = 0;

		for (int i=0;i<2048;i++) {
			boolean[] used = new boolean[24];
			used[12]=true;
			for (int j=1;j<=11;j++) {
				if (peopleCount[j]==2) {
					used[12+j]=true;
					used[12-j]=true;
				} else if (peopleCount[j]==1) {
					if ((i & (1<<(j-1))) > 0) {
						used[12+j]=true;
					} else {
						used[12-j]=true;
					}
				}
			}
			if(peopleCount[12]==1) {
				used[0]=true;
			}
			int s = 24;
			int pos = -1;
			for(int j=0;j<48;j++) {
				if(used[j%24]) {
					if(pos >= 0) {
						s=Math.min(j-pos, s);
					}
					pos = j;
				}
			}

			ans = Math.max(s, ans);

		}
		return ans;
	}

}


Measured memory_bytes: 23892
from operator import itemgetter
a = int(input())
shop_list = []
for i in range(a):
    b, c = input().split()
    c_num = int(c)
    shop_list.append([i+1, c_num, b])
shop_list.sort(key=itemgetter(1), reverse=True)
shop_list.sort(key=itemgetter(2))
for shop in shop_list:
    print(shop[0])

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

int main() {
    int n; cin >> n;
    string out = "No";

    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i * j == n) {
                out = "Yes";
                break;
            }
        }
        if (out == "Yes") break;
    }

    cout << out << endl;

    return 0;
}


Measured memory_bytes: 256
s = gets.chomp.gsub('?', '.')
t = gets.chomp

if t.size > s.size
  puts 'UNRESTORABLE'
  exit
end

(s.size - t.size).downto(0) do |i|
  if Regexp.new(s[i, t.size]).match(t)
    puts s[0, i].gsub('.', 'a') + t + s[(i + t.size)..-1].gsub('.', 'a')
    exit
  end
end

puts 'UNRESTORABLE'


Measured memory_bytes: 1916
#include <iostream>

void swap(int& a, int& b);

int main(){
    int N;
    std::cin >> N;
    
    int cards[N];
    for(int i = 0; i < N; i++){
        std::cin >> cards[i];
    }
    
    int sum_A = 0;
    int sum_B = 0;
    
    for(int i = 0; i < N - 1; i++){
        for(int j = 0; j < N - (i + 1); j++){
            if(cards[i] < cards[i + j + 1]){
                swap(cards[i], cards[i + j + 1]);
            }
        }
    }
    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            sum_A += cards[i];
        }else{
            sum_B += cards[i];
        }
    }
    std::cout << sum_A - sum_B;
}

void swap(int& a, int& b){
    int c = a;
    a = b;
    b = c;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int ans;
    cin>>ans;
    char c; cin>>c;
    if(c=='+'){
        int t; cin>>t;
        ans+=t;
    }else{
        int t; cin>>t;
        ans-=t;
    }
    
    cout<<ans<<endl;
    
    return 0;
}


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

typedef long long LL;

struct node {
  int id;
  LL cost;
  LL now_min;
};

int N, Q, K;
vector<node> all_nodes[100005];
LL min_to_vertex[100005];

void bfs(int s_vertex) {
  queue<node> search_queue;

  min_to_vertex[s_vertex] = 1;
  search_queue.push(node {s_vertex, 0, 1});

  while (!search_queue.empty()) {
    node now_node = search_queue.front();
    search_queue.pop();

    auto &neighbor = all_nodes[now_node.id];
    
    for(auto &n: neighbor) {
      if (!min_to_vertex[n.id]) {
	n.now_min = now_node.now_min + n.cost;
	min_to_vertex[n.id] = now_node.now_min + n.cost;
	search_queue.push(n);
      }
    }
  }
}

int main() {
  cin >> N;

  int a, b;
  LL c;
  for(int i = 0; i < N-1; i++) {
    cin >> a >> b >> c;

    all_nodes[a].push_back(node{b, c, 0});
    all_nodes[b].push_back(node{a, c, 0});
  }

  cin >> Q >> K;

  bfs(K);

  int x, y;
  for(int i = 0; i < Q; i++) {
    cin >> x >> y;

    cout << min_to_vertex[x] + min_to_vertex[y] - 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 12848
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    L = 1000

    N = NI()
    if N == 0:
        print(0)
        exit(0)

    s = 1 if N > 0 else -1
    n = abs(N)

    bit = [0] * L

    i = 0
    while n > 0:
        if n % 2:
            bit[i] += 1
            if s > 0 and i % 2 == 1 or s < 0 and i % 2 == 0:
                bit[i+1] += 1
        n //= 2
        i += 1

    for i in range(L-2):
        b = bit[i]
        if b > 1:
            b1 = bit[i+1]
            if b1 > 0:
                if b1 >= b//2:
                    bit[i+1] -= b//2
                    bit[i] = b % 2
                else:
                    bit[i+1] = 0
                    bit[i] -= b1 * 2
            if bit[i] > 1:
                bit[i+2] += bit[i] // 2
                bit[i+1] += bit[i] // 2
                bit[i] = bit[i] % 2

    bit.reverse()
    i = bit.index(1)
    print(*bit[i:],sep='')

if __name__ == '__main__':
    main()

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

using namespace std;

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

    if(N%2)
        cout<<setprecision(7)<<(N+1.0)/(2.0*N);

    else
        cout<<setprecision(7)<<0.5;

    return 0;
}

Measured memory_bytes: 3772
import sys
input = sys.stdin.readline
n = int(input())
a = [input().rstrip() for i in range(n)]
ls0 = []
ls25 = []
for i in range(n):
  s = a[i]
  l = len(s)
  if "." in s:
    pt = s.index(".")
    ls0.append(l-pt-1)
    x = s[:pt]+s[pt+1:]
  else:
    ls0.append(0)
    x = s
  ix = int(x)
  c2 = 0
  while ix%2 == 0:
    c2 += 1
    ix //= 2
  c5 = 0
  ix = int(x)
  while ix%5 == 0:
    c5 += 1
    ix //= 5
  ls25.append((c2-ls0[-1],c5-ls0[-1]))
ls25.sort()
ls2 = list(zip(*ls25))[0]
from collections import defaultdict
import bisect
dic5 = defaultdict(int)
ans = 0
for i in range(n)[::-1]:
  if ls2[i] < 0:
    break
  ind = bisect.bisect_left(ls2,-ls2[i])
  if i == n-1:
    for j in range(ind,n-1):
      dic5[ls25[j][1]] += 1
    ptr = ind
  else:
    for j in range(ptr,ind):
      dic5[ls25[j][1]] -= 1
    dic5[ls25[i][1]] -= 1
    ptr = ind
  for v,num in dic5.items():
    if v+ls25[i][1] >= 0:
      ans += num
print(ans)

Measured memory_bytes: 130220
#include <bits/stdc++.h>
#define db double
#define ll long long
#define X first
#define Y second
#define pii pair<int, int>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define REP(i, y) rep(i, 0, y - 1)
#define pb push_back
#define mp make_pair
using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int a[100010];
int main()
{
	int n = read();
	rep(i, 1, n)
		a[i] = read();
	int ans = 0;
	rep(i, 1, n)
		if(a[i] == i)
			swap(a[i], a[i + 1]), ans ++;
	cout << ans;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
    int n,m,i,a,b,x,y,r;
    scanf("%d%d",&n,&m);
    scanf("%d%d",&a,&b);
    for(i=m-1;i--;){
        scanf("%d%d",&x,&y);
        a=a<x?x:a;
        b=y<b?y:b;
    }
    r=b-a+1>0?b-a+1:0;
    printf("%d",r);
    return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s;
    cin >> s;
    int mi = INF;
    FOR(i, 2, s.size() - 1)
    {
        int t = 0;
        FOR(j, i - 2, i)
            t = t * 10 + (s[j] - '0');
        mi = min(mi, abs(753 - t));
    }
    cout << mi;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        WeightedUnionFind uf;
        int n, m;
        int l, r, d;

        n = sc.nextInt();
        m = sc.nextInt();

        uf = new WeightedUnionFind(n + 1);

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            d = sc.nextInt();

            if (uf.isSameGroup(l, r) &&
                uf.diff(l, r) != d) {
                System.out.println("No");
                return;
            }
            else {
                uf.unite(l, r, d);
            }
        }

        System.out.println("Yes");
    }
}


/**
 * 重み付きUnionFind木.
 * アーベル群まで拡張したいけどパフォが気になるので保留
 * ArrayList\<Integer\>がint[]よりだいぶ遅い
 */
class WeightedUnionFind {
    /** 親を示す 自身が根の場合は -(集合の大きさ) を持つ */
    private int[] parent;
    
    /** ノードの重み (親との差分) */
    private int[] diff_weight;

    public WeightedUnionFind(int nmemb) {
        parent = new int[nmemb];
        diff_weight = new int[nmemb];

        Arrays.fill(parent, -1);
        Arrays.fill(diff_weight, 0);
    }

    /** 根を求める */
    private int root(int x) {
        if (parent[x] < 0) {
            return x;
        }

        // 累積和的に重みを再計算
        int r = root(parent[x]);
        diff_weight[x] += diff_weight[parent[x]];
        parent[x] = r;

        return parent[x];
    }

    private int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    public int diff(int x, int y) {
        return weight(y) - weight(x);
    }
    
    public boolean isSameGroup(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * x->yの重みをwとして併合.
     * 即ち, weight(y) = weight(x) + w が成り立つ
     * x, yが既に同じグループのときは何もしない
     */
    public void unite(int x, int y, int w) {
        if (isSameGroup(x, y)) {
            return;
        }

        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
    
        parent[y] = x;
        diff_weight[y] = w;
    }

    public int groubSize(int x) {
        return -parent[root(x)];
    }
}


Measured memory_bytes: 153664
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define f first
#define s second
signed main()
{
    FAST;
    
     int i=0,j=0,k=0,n=0,m=0,count=0,temp=0,z;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,anss=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,zz=0,d=0,val=0;
    
    cin>>n;
    
    temp = n/500;
    
    n = n - (temp*500);
    
    ans = ans + (1000*temp);
    
    temp = n/5;
    
    ans = ans + (5*temp);
    
    cout<<ans<<endl;
    
        
        
    
    
    
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define EPS 1e-7

/*
 * O(N)でやりたい
 * a'の前半の要素はa[0:2n]の中に、後半の要素はa[n:3n]の中にしかありえない。
 * 前半と後半の区切れ目を固定すると、そのうちで最大のものは自動的に決まる
 * priority queueを使うと、A[0:N+i]のなかから選んだN個の和の最大値が求まる
 * INT_MAXは使える
 */

int main(){
  ll n;
  ll a[300003];
  cin>>n;
  rep(i,3*n){
    cin>>a[i];
  }

  priority_queue<ll, vector<ll>, greater<ll> > L;
  priority_queue<ll> R;
  ll sL[100002], sR[100002]; // sL[i]=a[0:n+i)での和の最大値 sR[i]=a[n+i:3n)での和の最小値

  // 初期値
  sL[0]=0; 
  rep(i,n) { 
    L.push(a[i]);
    sL[0]+=a[i];
  }
  /* cout<<sL[0]; */
  rep(i,n) {
    L.push(a[n+i]);
    ll m = L.top(); L.pop();
    sL[i+1] = sL[i] - m + a[n+i];
    /* dbg(i+1); */
  }

  sR[n]=0;
  rep(i,n) {
    R.push(a[3*n-i-1]);
    sR[n]+=a[3*n-i-1];
  }
  /* cout<<sR[n]; */

  rep(i,n) {
    R.push(a[2*n-1-i]);
    ll m = R.top(); R.pop();
    sR[n-1-i] = sR[n-i] - m + a[2*n-1-i];
    /* dbg(n-1-i); */
  }

  /* dumparr(sR,n+1); */
  /* dumparr(sL,n+1); */

  ll m = sL[0]-sR[0];
  repl(i,1,n+1){
    m = mmax(sL[i]-sR[i], m);
  }
  cout<<m<<endl;
  return 0;
}


Measured memory_bytes: 6516
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

using ll = long long;

template <class T>
using grid = vector<vector<T>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

map<ll, ll> ans;
vector<int> a;
int n;
void f(ll i, ll s) {
  if (i == n) {
    ans[s] = true;
    return;
  }
  FOR(j, i, n - 1) {
    f(j + 1, s + a[j]);
  }
  f(i + 1, s);
}

int main() {
  int input(N);
  n = N;
  a = vector<int>(n);
  REP(i, n) cin >> a[i];

  f(0, 0);

  int input(q);
  REP(i, q) {
    ll input(m);
    cout << (ans[m] ? "yes" : "no") << endl;
  }
}



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

int main()
{
	int N;
	string S;

	cin >> N >> S;

	int answer = 0;

	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
		{
			answer++;
	    }
	}

	cout << answer;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1LL<<60);

ll dp[200005];
ll n;
ll a[200005];

int main(){
  
  for(int i=0;i<200005;i++)
    dp[i]=-INF;
  ll ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    dp[ a[i] ]=1;
    dp[ a[i] ]=max(dp[ a[i] ],dp[ a[i]-1 ]+1);
    ans=max(ans, dp[ a[i] ]);
  }
  cout<<n-ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define N 3003
#define P 1000000007
using namespace std;
int n,q,a[N],f[N][N];
struct upd{int x,y,z;};
upd pkg(int x,int y,int z){
    upd res;
    res.x=x,res.y=y,res.z=z;
    return res;
}
queue <upd> Q;
bool b[N][N];
int pow(int x,int y){
    int res=1;
    for(;y;y>>=1,x=1LL*x*x%P)
        if(y&1)res=1LL*res*x%P;
    return res;
}
int main(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)f[i][j]=a[i]>a[j];
    int tot=pow(2,q),inv=pow(2,P-2);
    while(q--){
        int x,y;
        scanf("%d%d",&x,&y);
        for(int i=1;i<=n;++i)
            if(i!=x && i!=y){
                Q.push(pkg(i,x,(int)(1LL*(f[i][x]+f[i][y])*inv%P)));
                Q.push(pkg(x,i,(int)(1LL*(f[x][i]+f[y][i])*inv%P)));
                Q.push(pkg(i,y,(int)(1LL*(f[i][y]+f[i][x])*inv%P)));
                Q.push(pkg(y,i,(int)(1LL*(f[y][i]+f[x][i])*inv%P)));
            }
        Q.push(pkg(x,y,(int)(1LL*(f[x][y]+f[y][x])*inv%P)));
        Q.push(pkg(y,x,(int)(1LL*(f[y][x]+f[x][y])*inv%P)));
        while(!Q.empty()){
            upd cur=Q.front();
            f[cur.x][cur.y]=cur.z;
            Q.pop();
        }
    }
    int ans=0;
    for(int i=1;i<n;++i)
        for(int j=i+1;j<=n;++j){
            ans+=1LL*f[i][j]*tot%P;
            if(ans>=P)ans-=P;
        }
    printf("%d\n",ans);
}


Measured memory_bytes: 36224
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

S = input()
Wlist = ['Sunny', 'Cloudy', 'Rainy']
print(Wlist[(Wlist.index(S)+1)%3])

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

using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> done(n);
    vector<int> wa_cnt(n);
    for (int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (s == "AC") done.at(p) = true;
        else if (!done.at(p)) {
            wa_cnt.at(p)++;
        }
    }

    int wc = 0;
    int ac = 0;
    for (int i = 0; i < n; i++) {
        if (done.at(i)) {
            ac++;
            wc += wa_cnt.at(i);
        }
    }
    cout << ac << " " << wc << endl;
}

Measured memory_bytes: 640
s = input()
t = input()

dict_st = {}
dict_ts = {}

for x, y in zip(s, t):
    if x not in dict_st:
        dict_st[x] = y
    else:
        if dict_st[x] != y:
            print("No")
            break

    if y not in dict_ts:
        dict_ts[y] = x
    else:
        if dict_ts[y] != x:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 3632
h, w = gets.split.map(&:to_i)

a = Array.new(h+1) {Array.new(w+1, ?#)}
1.upto(h) do |i|
    gets.chomp.each_char.with_index(1) {|c,j| a[i][j] = c}
end

d = Array.new(h+1) {Array.new(w+1, 0)}
d[0][1] = 1
1.upto(h) do |i|
    1.upto(w) do |j|
        d[i][j] = d[i-1][j] + d[i][j-1] if a[i][j] == ?.
    end
end

p d[h][w] % (10 ** 9 + 7)

Measured memory_bytes: 242660
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n;
ll q[15], x[15];
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  ll a = 1, b = 0;
  for(int i = 0; i < n; i++) {
    cin >> q[i] >> x[i];
    if(q[i] == 1) {
      // (aX + b) x = axX + bx
      a *= x[i];
      b *= x[i];
    } else if(q[i] == 2) {
      // (aX + b) + x
      b += x[i];
    } else {
      // (aX + b) - x
      b -= x[i];
    }
  }
  cout << -b << " " << a << endl;
  return 0;
}



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

using int64 = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int64> x(n), y(n), z(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i] >> y[i] >> z[i];

  vector<int64> w(n);
  int64 ret = 0;
  for (int s = 0; s < 8; ++s) {
    for (int i = 0; i < n; ++i) {
      w[i] = ((s & 4) ? x[i] : (-x[i]))
        + ((s & 2) ? y[i] : (-y[i]))
        + ((s & 1) ? z[i] : (-z[i]));
    }
    sort(w.begin(), w.end(), greater<int64>());
    int64 v = accumulate(w.begin(), w.begin() + m, 0LL);
    ret = max(ret, v);
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = [input() for i in range(n)]
    ans = 0
    for i in range(n):
        s = [[s[i][(j+1)%n] for j in range(n)] for i in range(n)]
        for j in range(n):
            for k in range(j):
                if s[k][j] != s[j][k]:
                    break
            else:
                continue
            break
        else:
            ans += n
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
    ll n; cin >> n;
    vector<ll> a(n), cnt(n+1);
    for(int i=0; i<n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll sum = 0;
    for(int i=1; i<=n; i++) sum += cnt[i] * (cnt[i] - 1) / 2;
    for(int i=0; i<n; i++) {
        ll num = sum;
        num -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cnt[a[i]]--;
        num += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        cout << num << "\n";
        cnt[a[i]]++;
    }
}

Measured memory_bytes: 6404
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int target = sc.nextInt();
			int number = sc.nextInt();
			Integer[] atari = new Integer[number];
			for (int i=0; i<number; i++) {
				atari[i] = sc.nextInt();
				sc.nextInt();
			}
			Arrays.sort(atari, Comparator.reverseOrder()); // 降順になる
			int money = 0;
			for (int i=0; i<number-1; i++) {
				if (atari[i]<target) {
					money += target - atari[i];
				}
			}
			System.out.println(money);
		}
	}
}



Measured memory_bytes: 33440
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int n, ans = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0) {
			if (a[i] & 1) ans++;
		}
	}

	cout << ans << '\n';
}

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

burger = [1]
pati = [1]
for i in range(1,52):
    burger.append(burger[i-1]*2+3)
    pati.append(pati[i-1]*2+1)
    
def calc(l, eat):
    if l == 0:
        return 1
    elif eat == 1:
        return 0
    elif eat <= burger[l-1]+1:
        return calc(l-1, eat-1)
    elif eat == burger[l-1]+2:
        return pati[l-1] + 1
    elif eat <= (burger[l-1]+1)*2:
        return calc(l-1, eat-(2+burger[l-1])) + pati[l-1] + 1
    elif eat == (burger[l-1]*2) + 3:
        return (2*pati[l-1]) + 1

print(calc(N, X))

Measured memory_bytes: 3064
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
for i in range(N-1):
    if x >= a[i]:
        x -= a[i]
        ans += 1
    else:
        break
if a[N-1]==x:
    ans += 1
print(ans)



Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int a[3000],b[3000];
	int i=0;
	while(1){
		scanf("%d %d", &a[i], &b[i]);
		if(a[i]==0 && b[i]==0)break;
		i = i + 1;
	}
	
	for(int j=0; j<i; j++){
	if(a[j] < b[j]){
			printf("%d %d\n", a[j], b[j]);
		}else{
			printf("%d %d\n", b[j], a[j]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 2632
// https://atcoder.jp/contests/abc151/tasks/abc151_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

vector<vector<int>> grid_bfs(vector<string> &s, char start,
                             const char &wall = '#') {
    const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
    vector<vector<int>> min_cost(s.size(), vector<int>(s[0].size(), -1));
    queue<pair<int, int>> que;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < s[i].size(); j++) {
            if (s[i][j] == start) {
                que.emplace(i, j);
                min_cost[i][j] = 0;
            }
        }
    }
    while (!que.empty()) {
        auto p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int ny = p.first + vy[i], nx = p.second + vx[i];
            if (nx < 0 || ny < 0 || nx >= s[0].size() || ny >= s.size())
                continue;
            if (min_cost[ny][nx] != -1)
                continue;
            if (s[ny][nx] == wall)
                continue;
            min_cost[ny][nx] = min_cost[p.first][p.second] + 1;
            que.emplace(ny, nx);
        }
    }
    return min_cost;
}

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

    int h, w;
    cin >> h >> w;
    vector<string> vs(h);
    for (int i = 0; i < h; i++) {
        cin >> vs[i];
    }

    // 最大値を探す
    int maxv = 0;
    REP(i, h) REP(j, w) {
        if (vs[i][j] == '.') {
            vector<string> t = vs;
            t[i][j] = 'S';
            vector<vector<int>> ret = grid_bfs(t, 'S');
            for (auto &x : ret) {
                for (auto &y : x) {
                    maxv = max(maxv, y);
                }
            }
        }
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    string s;
    cin >> s;

    int len = s.length();

    char abc[27] = "abcdefghijklmnopqrstuvwxyz";
    int v[26] = {0};
    rep(i, len){
        rep(j, 27){
            if(s[i] == abc[j]){
                v[j]++;
            }
        }
    }
    int tmp = 30;
    rep(i, 26){
        if(v[i] == 0){
            tmp = i;
            break;
        }
    }
    if(tmp == 30){
        printf("None");
    }
    else{
        cout << abc[tmp];
    }
    return 0;
}

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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int a;
	cin >> a;
	string ans = a < 1200 ? "ABC" : "ARC";
	P(ans);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int a,b,A,B;
    in>>a>>b;
    fr(i,10000){
       A=i*108/100-i;
       B=i*110/100-i;
       if(A==a&&B==b) return cout<<i<<endl,0;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
struct coord {
    int y, x;
};
using namespace std;
using ll = long long;
int main() {
    int H, W, D;
    cin >> H >> W >> D;
    unordered_map<int, coord> pos;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int n; cin >> n;
            n--;
            pos[n] = {i, j};
        }
    }

    int N = H*W;
    vector<ll> acc(N);
    for (int i = 0; i < D; i++) {
        for (int j = i+D; j < N; j += D) {
            acc[j] = acc[j-D] + abs(pos[j].y - pos[j-D].y) + abs(pos[j].x - pos[j-D].x);
        }
    }

    int Q; cin >> Q;
    for (int q = 0; q < Q; q++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << acc[r] - acc[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 5668
#include<iostream>
#include<algorithm>
using namespace std;
int x[101],y[101];
int main()
{
	int n,m;
	int X,Y;
	cin>>n>>m>>X>>Y;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
	}
	x[++n]=X;
	sort(x+1,x+n+1);
	int z=x[n]+1;
	for(int i=1;i<=m;i++)
	{
		cin>>y[i];
	}
	sort(y+1,y+m+1);
	if(z>y[1]||z>Y)
	{
		cout<<"War";
		return 0;
	}
	cout<<"No War";
	return 0;
}

Measured memory_bytes: 256
x=gets.to_i

(0...1000).each{|b|(b...1000).each{|a|
    a5 = a**5
    b5 = b**5
    [[a5+b5,a,-b],[a5-b5,a,b]].each{|(v,a,b)|
        if v == x
            print "#{a} #{b}"
            exit
        end
    }
}}

Measured memory_bytes: 14304
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
# from functools import lru_cache
# @lru_cache(maxsize=None)


n = int(input())
h = list(map(int, input().split()))
cost = [0]*n

cost[0] = 0
cost[1] = abs(h[1]-h[0])

for i in range(2,n):
    cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]))
print(cost[n-1])


Measured memory_bytes: 13976
import java.io.*;
import java.math.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		String a = sc.next();
		String b = sc.next();

		BigInteger ba = new BigInteger(a);
		BigInteger bb = new BigInteger(b);

		if (ba.compareTo(bb) == 0) {
			pr.println("EQUAL");
		} else if (ba.compareTo(bb) > 0) {
			pr.println("GREATER");
		} else {
			pr.println("LESS");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    double x = 0.08;
    double y = 0.1;
    ll ok = 0;
    for(ok = 0; ok < 1e6; ok++)
        if((ll)(ok*x) == a and (ll)(ok*y) == b)break;
    cout << ((ll)(ok*x) == a and (ll)(ok*y) == b? ok : -1) << endl;
    return 0;
}



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

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

int cur;
bool val[12];

bool formula(string f)
{
    bool b;
    switch(f[cur])
    {
        case 'T': ++cur; return true;
        case 'F': ++cur; return false;
        case '-': ++cur; return !formula(f);
        case '(':
            ++cur;
            b = formula(f);
            switch(f[cur])
            {
                case '*':
                    ++cur;
                    b &= formula(f);
                    break;
                case '+':
                    ++cur;
                    b |= formula(f);
                    break;
                case '-':
                    cur += 2;
                    b = !b | formula(f);
                    break;
            }
            ++cur;
            return b;
        default: return val[f[cur++]-'a'];
    }
}

int main()
{
    string eq;
    
    while(cin >> eq && eq != "#")
    {
        bool equal = false;
        string lhs, rhs;
        rep(i, eq.size())
        {
            if(eq[i] == '=') equal = true;
            else if(!equal) lhs += eq[i];
            else rhs += eq[i];
        }
        
        bool res = true;
        rep(i, 1 << 11)
        {
            rep(j, 11) val[j] = 1 & (i >> j);
            cur = 0;
            bool b1 = formula(lhs);
            cur = 0;
            bool b2 = formula(rhs);
            if(b1 != b2) {
                res = false; break;
            }
        }
        
        cout << (res ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 1972
#!/usr/bin/env python3

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

    k = 0
    for v in a:
        while v % 2 == 0:
            v /= 2
            k += 1

    print(k)


if __name__ == '__main__':
    main()



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()


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

  string S;
  cin>>S;
  string yaki="YAKI";
  bool like=true;
  for(int i=0;i<yaki.size();i++){
    if(S[i]!=yaki[i])like=false;
  }
  if(like)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int l;
        cin >> l;
        if(l == 0)
            return 0;

        int ret = -1;
        for(int i=1; i<=12; ++i){
            int m, n;
            cin >> m >> n;
            l -= m;
            l += n;
            if(ret == -1 && l <= 0)
                ret = i;
        }

        if(ret == -1)
            cout << "NA" << endl;
        else
            cout << ret << endl;
    }
}

Measured memory_bytes: 0
package main

import "fmt"

func main() {
	var n, r, d int
	d = 0
	fmt.Scan(&n, &r)
	if n >= 10 {
		d = 0
	} else {
		d = 100 * (10 - n)
	}
	fmt.Println(r + d)
	return
}


Measured memory_bytes: 512
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,m = map(int,input().split())
if abs(n-m)>1:
    print(0)
else:
    if n == m:
        ans = (2*math.factorial(n%MOD)*math.factorial(m%MOD))%MOD
        print(ans)
    else:
        ans = (math.factorial(n%MOD)*math.factorial(m%MOD))%MOD
        print(ans)


Measured memory_bytes: 5464
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[5] = {0,0,0,0,0};
  int p[6];
  bool l = 1;
  for(int i = 0;i<6;i++){
    cin >> p[i];
    a[p[i]]++;
  }
  
  for(int k = 0;k<5;k++){
    if(a[k]>2){
      l = 0;
      break;
    }
  }
  if(l == 0){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
n, m = map(int, input().split())
demands = [
    tuple(map(int,
              line.strip().split())) for line in sys.stdin.readlines()
]
demands.sort(key=lambda demand: demand[1])

x = -1
cnt = 0
for ai, bi in demands:

    if ai <= x:
        continue

    else:
        x = bi - 1
        cnt += 1

print(cnt)


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


int main() {
 int n;
 cin>>n;
 vector<int> vec(n) ;
 for (int i = 0; i < n; i++)
   cin>>vec[i];
 vector<int> count(n,0);
 
 for (int i = 0; i < n-1; i++)
 {
  if(vec[i] >= vec[i+1])  count[i+1] = count[i]+1;
 }
   sort(count.begin(), count.end()); 
 cout << count[n-1] <<endl;
}

Measured memory_bytes: 4024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();

		System.out.println((a + b) * h / 2);

		sc.close();

	}

}

Measured memory_bytes: 35656
// Problem: B - Substring
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define FAST_IO                                                                                                        \
    ios::sync_with_stdio(0);                                                                                           \
    cin.tie(0);                                                                                                        \
    cout.tie(0);
#define ll long long int
#define mp make_pair
#define pb push_back
#define p pair
#define vt vector
#define F first
#define S second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define endl "\n"
#define db1(x) cout << #x << " = " << x << '\n';
#define db2(v)                                                                                                         \
    for (auto &x : v)                                                                                                  \
        cout << x << " ";
#define umap unordered_map
#define uset unordered_set
#define MOD 1000000007
using namespace std;

int main()
{
    FAST_IO;
    string s, t;
    cin >> s >> t;
    int ans = sz(t);
    for (int i = 0; i <= sz(s) - sz(t); i++)
    {
        int dif = 0;
        for (int j = 0; j < sz(t); j++)
        {
            if (t[j] != s[j + i])
            {
                dif++;
            }
        }
        ans = min(ans, dif);
    }
    cout << ans;
    return 0;
}

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

int main()
{
    int a,b; cin>>a>>b;
    int mi=min(a,b);
    int mx=max(a,b);
    int tmp=0;
    for(int i=0;i<mx;i++)
    {
        tmp*=10;
        tmp+=mi;
    }
    cout<<tmp;
    
    

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 32770
#define ll long long
#define mod 1000000007
using namespace std;
int n, m, bin[400], map[20][20], x, y, w1[20][N], w2[20][N], f[N];
int main(){
	scanf("%d%d", &n, &m);
	memset(map, 0, sizeof(map));
	for(int i=1; i<=m; i++){scanf("%d%d", &x, &y); map[x][y]=1;}
	bin[0]=1; for(int i=1; i<=n*n; i++)bin[i]=bin[i-1]*2%mod;
	for(int i=1; i<=n; i++)
		for(int j=0; j<=bin[n]-1; j++){
			w1[i][j]=w2[i][j]=0;
			for(int k=1; k<=n; k++)if(j&bin[k-1]){
				w1[i][j]+=map[i][k]; w2[i][j]+=map[k][i];
			}
		}
	f[0]=1;
	for(int i=1; i<=bin[n]-1; i++){
		f[i]=0;
		for(int j=(i-1)&i; j>=0; j=(j-1)&i){
			if(j&bin[0]&&!(j&bin[1]))continue;
			if(!(j&bin[0])&&j&bin[1])continue;
			x=1;
			for(int k=1; k<=n; k++)if(j&bin[k-1])x=(ll)x*(bin[w1[k][i-j]]-1)%mod*bin[w2[k][i-j]]%mod;
			f[i]=(f[i]+(ll)f[j]*x%mod)%mod;
			if(!j)break;
		}
	}
	printf("%d", (bin[m]-f[bin[n]-1]+mod)%mod);
	return 0;
}

Measured memory_bytes: 4736
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
class Hp
  def initialize(len)
    @main = na(len,[999999999,-1])
    @ind = 1
    @main[0] = [-99999999,-1]
    @size = len - 5
  end
  def push(n)
    p "wa" if(@ind > @size)
    @main[@ind] = n
    sind = @ind
    while(sind != 0)
      nind = sind/2
      @main[sind], @main[nind] = @main[nind], @main[sind] if(@main[sind][0] < @main[nind][0])
      sind /= 2
    end
    @ind += 1
  end
  def put()
    return @main
  end
  def pop()
    ans = @main[1]
    @main[1] = @main[@ind]
    @main[@ind] = [999999999,-1]
    sind = 1
    while(true)
      nind = sind*2
      break if(nind > @ind)
      l = @main[nind]
      nind += 1 
      if(nind > @ind)
        ind = nind-1
        if(@main[ind][0] < @main[sind][0])
          @main[sind], @main[ind] = @main[ind], @main[sind] 
        end
        break 
      end
      r = @main[nind]
      ind = (l[0] > r[0])? nind : nind-1
      if(@main[ind][0] < @main[sind][0])
        @main[sind], @main[ind] = @main[ind], @main[sind] 
      end
      sind = ind
    end
    @ind -= 1
    return ans
  end
  def res()
    @ind = 1
    @main.push([999999999,-1])
  end
end
n,m = inp
pas = na2(n+1,0)
rec = na2(n+1,n+1,999999999)

test = []
m.times do 
  a,b,c=inp
  pas[a].push([b,c])
  pas[b].push([a,c])
  test.push([a,b,c])
end
#p pas
used = na(n)
hp = Hp.new(5100)
hp.push([1,1])
(1..n).each do |s|
  hp.put
  hp.res
  rec[s][s] = 0
  ind = s
  used = na(n+1,0)
  while(ind > 0) do
    used[ind] = true;
    max = 999999
    nex = -1
    tab = pas[ind]
    tab.each do |a|
      hi = a[0]
      next if(used[hi] == true)
      kyori = rec[s][ind] + a[1]
      rec[s][hi] = kyori if rec[s][hi] > kyori
      hp.push([kyori,hi]) 
    end
    d = hp.pop[1]
    while(used[d] == true )
      d = hp.pop[1]
      break if(d == -1)
    end
    nex = d
    used[nex] = true;
    ind = nex
  #rererereerer[missmissniu] += [waawawawawwa[bugbugbubg]] if(nex < 0)
  end
end
#p rec
c = 0
test.each do|a|
  if(rec[a[0]][a[1]] != a[2])
    c +=1
  end
end
p c

Measured memory_bytes: 2812
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int mod=1000000007;
    int n;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    long long wa[n];
    wa[0]=a[0];
    for(int i=0;i<n-1;i++)wa[i+1]=(wa[i]+a[i+1])%mod;
    long long ans=0;
    for(int i=1;i<n;i++)ans=(ans+a[i]*wa[i-1])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6756
N = int(input())
D = [int(x) for x in input().split()]
D.append(0)
D.sort()
ans = []
for i in range(N + 1):
    if i % 2 == 0:
        ans.append(D[i])
    else:
        ans.append((24 - D[i]) % 24)
ans.sort()
print(min(min(ans[i + 1] - ans[i] for i in range(N)), 24 - ans[-1]))


Measured memory_bytes: 3060
def main():
    n,m = map(int, input().split())
    like = set(list(map(int, input().split()))[1:])
    for i in range(1, n):
        e = set(list(map(int, input().split()))[1:])
        like &= e
    print(len(like))

if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define LL long long
#define pii pair<int,int>
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
vector<int> v[300005];
multiset<int> s;
void solve(){
    int h,w,n;
    scanf("%d %d %d",&h,&w,&n);
    int cnth[300005],cntw[300005];
    MEM(cnth),MEM(cntw);

    for(int i = 0;i<n;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        cnth[a]++;
        cntw[b]++;
        v[a].pb(b);
    }
    for(int i = 1;i<=w;i++)s.insert(cntw[i]);
    int ans=0;
    for(int i = 1;i<=h;i++){
        for(auto it:v[i]){
            s.erase(s.find(cntw[it]));
            cntw[it]--;
            s.insert(cntw[it]);
        }
       // printf("%d %d\n",cnth[i],*s.rbegin());
        ans=max(ans,*s.rbegin()+cnth[i]);
        for(auto it:v[i]){
            s.erase(s.find(cntw[it]));
            cntw[it]++;
            s.insert(cntw[it]);
        }
    }
    printf("%d\n",ans);
}
int main()
{
    int t=1;
    //scanf("%d",&t);
    int T=1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 36624