akhauriyash/Code-Regression huggingface dataset:
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, d,k, p, q, r, x, y, u, v, n, m;
    cin>>x>>k>>d;

	x=abs(x);
	if(x/d>=k)
	{
		cout<<x-k*d;
		return 0;
	}
	y=x/d;
	x-=(y*d);
	k-=y;
	if(k%2==0)
	{
		cout<<x;
	}
	else
	{
		cout<<abs(x-d);
	}
	
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10696
#include <iostream>
using namespace std;
 
int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
  
        if (N % 2 == 0 && S.substr(0, N / 2) == S.substr(N / 2, N / 2)){
            cout << "Yes" << endl;
        } else {
		    cout << "No" << endl;
        } 
}

Measured memory_bytes: 256
e1,e2,e3,e4=map(int,input().split())
if e1==e2 and e3==e4:
    print("yes")
elif e1==e3 and e2==e4:
    print("yes")
elif e1==e4 and e2==e3:
    print("yes")
elif e1==e2 and e1==e3 and e1==e4:
    print("yes")
else:
    print("no")


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

using namespace std;
typedef long long ll;
#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define repb(i,a,b)         for(ll i=a;i>=b;i--)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define tr(c,it)            for(auto const &it : c)
#define xlr8                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sz(c)               (c).size()
#define all(c)              (c).begin(),(c).end()
#define sl(a)               scanf("%lld",&a);
#define TH                  1000
#define F                   first
#define S                   second
ll INF=1e18+10;

int main()
{
    int n;cin>>n;
    ll a[n];
    rep(i,0,n)
    cin>>a[i];

    ll m1=2*a[0];
    rep(i,1,n)
    m1 = (i&1) ? (m1-2*a[i]) : (m1+2*a[i]);

    m1/=2;
    ll m[n];
    m[0]=m1;
    rep(i,0,n-1)
    {
        m[i+1]=2*a[i]-m[i];
        cout<<m[i]<<" ";
    }
    cout<<m[n-1];
}


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

int main(){

    int n;
    cin >> n;
    int formerx = 0;
    int formery = 0;
    int formertime = 0;

    for(int i=0; i<n; i++){
        int t,x,y;
        cin >> t >> x >> y;
        int dist, disx, disy;
        dist = t - formertime;
        disx = abs(x - formerx);
        disy = abs(y - formery);
        int temp = dist - disx - disy;
        if(temp < 0 || temp & 1){
            cout << "No" << endl;
            return 0;
        }

        
        formertime = t;
        formerx = x;
        formery = y;
         
        
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
    long long n,i;
    cin >> n;
 
    long long k = 0;
    for(i=0;i<n;i++)
    {
        k = k*10+7;
        k %= n;
        if(k==0)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 ;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s,s1,s2;
    cin>>s;
    int n = s.size(),i,j,g,h,c=0;

g=(n-1)/2;
h=(n+3)/2;

for(i=0,j=h-1; i<g,j<n; ++i,++j)
{
    if(s[i] == s[j]) c=1;

    else {c=0; break;}
}
if(c==1){cout<<"Yes"<<endl;}

else {cout<<"No"<<endl;}

    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
 
class DandA {
    static void Main(string[] args) {
        int n = ReadLineInt();
        int[][] pq = ReadMLineIntArray(2);
        int a = 0;
        int b = 0;
        int wk_a = 0;
        int wk_b = 0;

        for (int i = 0;i < n - 1;i++) {
            int wk = 0;
            for (int j = i;j < n;j++) {
                if (pq[0][i] > pq[0][j]) {
                    wk++;
                }
            }
            a += sum(n - (i + 1), wk);
        }
        
        for (int i = 0;i < n - 1;i++) {
            int wk = 0;
            for (int j = i;j < n;j++) {
                if (pq[1][i] > pq[1][j]) {
                    wk++;
                }
            }
            b += sum(n - (i + 1), wk);
        }
        if (a < b) {
            Console.WriteLine(b - a);
        } else {
            Console.WriteLine(a - b);
        }
    }
    static private int sum(int arg1 ,int arg2) {
        int rtn = 1;
        for (int i = 1; i <= arg1; i++) {
             rtn *= i;
        }
        rtn *= arg2;
        return rtn;
    }
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
}

Measured memory_bytes: 13524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int k, s; std::cin >> k >> s;
    int ans = 0;
    for (int a = 0; a <= k; a++) {
        for (int b = 0; b <= k; b++) {
            int c = s - a - b;
            ans += 0 <= c && c <= k;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 256
/*  很神奇的一道题目
 * 求出k的倍数的正数x，使得x的位数和最小。
 * eg k = 6 x = 12(位数和为3) x = 30(位数和为3)
 * 
 * 考虑正数x 其变为 x+1 需要代价1.
 *    正数x 变成 x*10 需要代价0.
 * 由于我们只需要得到k的倍数，也就是说在 %k 意义下为0的点。
 * 所以只有[0,k-1]k点。对每个点建立两条边，分别为(x+1)%k 和 (x*10)%k
 */
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
struct Edge {
    int to,val;
    Edge(){}
    Edge(int _t,int _v){to = _t;val = _v;}
};
struct qNode {
    int u,val;
    qNode(){}
    qNode(int _u,int _v) {u = _u;val = _v;}
    bool operator < (const qNode &a) const{
        return val > a.val;
    }
};
vector<Edge> ways[maxn];
int dist[maxn];
bool vis[maxn];
int n;
inline void init() {
    for(int i=0;i<maxn;i++) ways[i].clear();
    memset(vis,0,sizeof(vis));
    memset(dist,inf,sizeof(dist));
}
inline void addedge(int from,int to,int val) {
    ways[from].push_back(Edge(to,val));
}
int solve(int from,int to) {
    priority_queue<qNode> qu;
    dist[from] = 1;
    qu.push(qNode(from,1));
    qNode now;
    while(!qu.empty()) {
        now = qu.top();qu.pop();
        int u = now.u;
        if(vis[u]) continue;
        vis[u] = true;
        for(auto tmp:ways[u]) {
            int v = tmp.to,cost = tmp.val;
            if(!vis[v] && dist[v] > dist[u]+cost) {
                dist[v] = dist[u] + cost;
                qu.push(qNode(v,dist[v]));
            }
        }
    }
    return dist[to];
}
int main()
{
    while(~scanf("%d",&n)){
        init();
        for(int i=1;i<n;i++) {
            addedge(i,(i+1)%n,1);
            addedge(i,(i*10)%n,0);
        }
        int ans = solve(1,0);
        printf("%d\n",ans);
    }
    return 0;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  if(N % 2 != 0){
    cout << "No" << endl;
  }else{
    bool flag = true;
    for(int i = 0; i < N/2; i++){
      if(S[i] != S[N/2+i]){
	flag = false;
      }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
  }


}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
#define int long long
#define inf 1e17
using namespace std;
priority_queue<int>q;
int n,a[200001],ans;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	sort(a+1,a+n+1,cmp);
	ans+=a[1];
	q.push(a[2]);
	q.push(a[2]);
	for(int i=3;i<=n;i++)
	{
		ans+=q.top();
		q.pop();
		q.push(a[i]);
		q.push(a[i]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 6944
# coding: utf-8
# Your code here!

import bisect

def recursive(h):
    if len(h) == 0:
        return 0
    pos_zero = [-1]
    min_h = min(h)
    count = min_h
    for i in range(len(h)):
        h[i] -= min_h
        if h[i] == 0:
            pos_zero.append(i)
    
    pos_zero.append(len(h))
    
    if len(pos_zero) > 0:
        for i in range(0, len(pos_zero)-1):
            count += recursive(h[pos_zero[i]+1:pos_zero[i+1]])

    return count
    

N = map(int, input().rstrip().split(' '))
h = list(map(int, input().rstrip().split(' ')))

count = recursive(h)

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

string S;
int n, nxt[N][26], f[N];

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> S; n = S.length();
  f[n + 1] = 1;
  for (int j = 0; j < 26; ++j) nxt[n + 1][j] = n + 1;
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < 26; ++j) nxt[i][j] = nxt[i + 1][j];
    nxt[i][S[i - 1] - 'a'] = i;
    f[i] = 1e9;
    for (int j = 0; j < 26; ++j) {
      f[i] = min(f[i], f[nxt[i][j] + 1] + 1);
    }
  }
  int cur = 1;
  while (cur <= n) {
    for (int j = 0; j < 26; ++j) {
      if (f[cur] == f[nxt[cur][j] + 1] + 1) {
        cur = nxt[cur][j] + 1;
        cout << (char)('a' + j);
        break;
      }
    }
  }
  return 0;
}

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

void open(vector<string> &map, int H, int W, int h, int w){
  int bomb = 0;
  for(int i = h - 1; i <= h + 1; i++){
    if(i < 0 || i >= H){
      continue;
    }
    for(int j = w - 1; j <= w + 1; j++){
      if(j < 0 || j >= W){
        continue;
      }
      if(map.at(i).at(j) == '#'){
        bomb++;
      }
    }
  }
  char b = '0' + bomb;
  map.at(h).at(w) = b;
}

int main() {
  int H, W;
  cin >> H;
  cin >> W;
  vector<string> S(H);
  for(int i = 0; i < H; i++){
    cin >> S.at(i);
  }
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S.at(i).at(j) == '.'){
        open(S, H, W, i, j);
      }
    }
  }
  
  for(string L : S){
    cout << L << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    int cnt[3] = {};//4 2 1
    cin >> N;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        if(a % 4 == 0)cnt[0]++;
        else if(a % 2 == 0)cnt[1]++;
        else cnt[2]++;
    }
    if(cnt[1] == N){
        cout << "Yes" << endl;
        return 0;
    }
    if(cnt[1])cnt[2]++;
    if(cnt[2] - cnt[0] <= 1)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	getline(cin, s);
	int len = s.size();
	for(int i=0; i<len; i++){
		if(s[i]>='A' && s[i]<='Z')
			s[i] += -'A'+'a';
		else if(s[i]>='a' && s[i]<='z')
				s[i] += -'a'+'A';
		cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3116
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


def read_matrix(H, W)->np.ndarray:
    '''return np.ndarray shape=(H,W) matrix'''
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

N, K = ints()
A = read_matrix(N, N)


# from numba import njit


# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)
def matmul_mod(X: np.ndarray, Y: np.ndarray)->np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    for i in range(X.shape[0]):  # Xの行
        for j in range(Y.shape[1]):  # Yの列
            tmp = (X[i, :] * Y[:, j]) % MOD
            ret[i, j] = tmp.sum() % MOD
    return ret


def matmul_mod_try(X: np.ndarray, Y: np.ndarray)->np.ndarray:
    MOD = 10**9 + 7
    # return X @ Y
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    YT = Y.T
    for i in range(X.shape[0]):  # Xの行
        Xi = X[i, :]
        tmp = (YT * Xi) % MOD
        ret[i, :] = tmp.sum(1) % MOD
    return ret


A_double = np.asanyarray(A, dtype=np.int64)
ans = np.eye(N, dtype=np.int64)
for j in range(int(K).bit_length()):
    if (K >> j) & 1:
        # t1, t2 = matmul_mod(ans, A_double), matmul_mod_try(ans, A_double)
        # assert np.array_equal(t1, t2), (t1, t2)
        ans = matmul_mod_try(ans, A_double)
    A_double = matmul_mod_try(A_double, A_double)

print(ans.sum() % MOD)


Measured memory_bytes: 27464
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

long long pow(long long a,long long b,long long mod){
    if(b==0){
        return 1;
    }else{
        if(b%2==0){
            return pow(a*a%mod,b/2,mod);
        }else{
            return pow(a*a%mod,b/2,mod)*a%mod;
        }
    }

}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

    ll mod=1e9+7;


    ll ans=0;
    ll rev=1;

    vector<ll> fact(S+1);
    vector<ll> invfact(S+1);
    fact[0]=1;invfact[0]=1;
    for(int i=1;i<S+1;i++){
        fact[i]=fact[i-1]*i%mod;
        invfact[i]=invfact[i-1]*modinv(i,mod)%mod;
    }

    for(int i=1;i<=S;i++){
        ll num=S-3*i;
        if(num<0){
            break;
        }else{
            //*
            ll comb=fact[num+i-1]*invfact[num]%mod;
            comb=comb*invfact[i-1]%mod;
            //*/
            /*
            ll comb=pow(num,i-1,mod);
            comb*=rev;
            comb%=mod;
            /*
            if(i==3){
                cout<<comb<<endl;
            }
            //*/
            //*/
            /*
            ll comb=fact[num]*invfact[num-i];
            comb*=invfact[i];
            comb%=mod;
            cout<<comb<<endl;
            //*/


            ans+=comb;
            ans%=mod;

            rev*=modinv(i,mod);
            rev%=mod;
            //cout<<rev<<endl;
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

const int pmax = 1000010;
bool p[pmax];


int main(){
    rep(i,pmax) p[i] = true;
    p[0] = p[1] = false;
    for(int i = 2; i * i < pmax; i++) {
        if(p[i]) {
            for(int j = i * 2; j < pmax; j += i) {
                p[j] = false;
            }
        }
    }

    int a,d,n;
    while(cin >> a >> d >> n,a != 0 && d != 0 && n != 0) {
        int cnt = 0;
        for(int i = a; i < pmax; i += d) {
            if(p[i]) {
                cnt++;
                if(cnt == n) {
                    cout << i << endl;
                    break;
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4060
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return(a)

a,b,c,d=map(int,input().split())
cn1=0
cn2=0
cn3=0
an1=0
an2=0
an3=0
cnt=0
ans=0
lm=(c*d)//gcd(c,d)

#bまで
cn1=b//c
cn2=b//d
cn3=b//lm
#aまで
an1=(a-1)//c
an2=(a-1)//d
an3=(a-1)//lm
#aからbまで
cn1=cn1-an1
cn2=cn2-an2
cn3=cn3-an3

cnt=cn1+cn2-cn3
ans=b-a-cnt

print(ans+1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vl a(n);
    cin>>a;
    ll ma=2,mi=2;
    REPR(i,n){
        mi=((mi+a[i]-1)/a[i])*a[i];
        ma=(ma/a[i])*a[i]+a[i]-1;
        if(mi>ma){
            print(-1);
            return 0;
        }
    }
    print(mi,ma);
}


Measured memory_bytes: 1024
#include <stdio.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
typedef long long ll;

int main()
{
    ll n;
    ll x, y;
    ll b, p;

    ll nakamura;
    ll arumakan;

    scanf("%lld", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld %lld %lld", &x, &y, &b, &p);

        nakamura = x * b + y * p;
        arumakan = x * b + y * p + x * max(0, 5 - b) + y * max(0, 2 - p);
        arumakan = arumakan / 10 * 8;

        printf("%lld\n", min(nakamura, arumakan));
    }
    
    return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

int main() {
    int n, d;
    cin >> n >> d;

    int cnt = 0;
    rep(i, 0, n) {
        ll x, y;
        cin >> x >> y;
        if (sqrt(x * x + y * y) <= d) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3676
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MAX (ll(1e6)+7)
#define MOD (ll(1e9)+7)
#define INF (ll(1e18)+7)

#define elif else if
#define def inline auto

#define for_in(a,b,c) for(ll a=(b);a<(c);++a)
#define repeat(a,b) for(ll a=0;a<(b);++a)
#define repeat_down(a,b) for(ll a=(b);a>=0;--a)

#define array_size(a) ll(sizeof(a)/sizeof(a[0]))

#define def_input(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define if_print(a,b,c) output(a?#b:#c)
#define print(a) output(#a)
#define fout(a) cout<<fixed<<setprecision(10)<<a
#define fillout(a,b,c) cout<<setfill(a)<<setw(b)<<right<<c
#define ios_boost cin.tie(0);ios::sync_with_stdio(false)

#define digit(a) to_string(a).length()
#define lcm(a,b) a*b/gcd(a,b)

char N='\n',S=' ';
const ll primes[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
ll temp_index;

inline void input(){}
template<class T,class...A>inline void input(T&&t,A&&...a){cin>>t;input(move(a)...);}
template<class T>inline void output(T&t){cout<<t<<N;}
template<class T,class...A>inline void output(T&t,A&...a){cout<<t<<S;output(move(a)...);}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>const&v)
{bool d=0;for(T x:v){if(d)o<<S<<x;else{o<<x,d=1;}}o<<N;return o;}

def get_ll(){ll x;input(x);return x;}
def gcd(ll a,ll b){ll c;while(a){c=a;a=b%a;b=c;}return b;}

inline bool is_prime(ll a){
    if(a<48){for_in(i,0,15)if(primes[i]==a)return 1;}
    elif(a<2809)return gcd(614889782588491410,a)==1;
    else {print(Error:Argument>2808);exit(1);}return 0;
}

template<class T>def sum_array(T&a,T&b){
    b[0]=a[0];
    for_in(i,1,array_size(a))b[i]=a[i]+b[i-1];
}

map<string,ll>LIST;
map<ll,string>VLIST;

def val(string a){
    auto IT=LIST.find(a);
    if(IT!=LIST.end()){
        return LIST[a];
    }
    else{
        ll v=LIST.size();
        LIST[a]=v;
        VLIST[v]=a;
        return v;
    }
}

ll a,b,c,d;
int main(){
    ios_boost;
    def_input(n,m);
    if_print(n%m,1,0);
}

//for compilation: g++ -o _ _.cpp -std=c++14 (or 17)
//
//for fastening: g++ -O2 -o _ _.cpp -std=c++14 (or 17)
//for fastening: g++ -O3 -mtune=native -march=native -o _ _.cpp -std=c++14 (or 17)


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

int a[100];
int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0;i < n;i++)scanf("%d", &a[i]);
	sort(a, a+n, greater<int>());
	int ans = 0;
	for(int i = 0;i < k;i++)ans += a[i];
	printf("%d\n", ans);
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<pair<string, int>> Guide(N+1);
	for (int i = 1; i <= N; i++) {
		string S;
		int P;
		cin >> S >> P;
		Guide[i] = { S,P };
	}
	vector<int> Index(N);
	iota(Index.begin(), Index.end(), 1);

	sort(Index.begin(), Index.end(),
		[Guide](const auto& a, const auto& b) {
		if (Guide[a].first == Guide[b].first) return Guide[a].second > Guide[b].second;
		else return Guide[a].first < Guide[b].first; });

	for (const auto& i : Index) cout << i << endl;
}

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

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; }



int main(){
    const long long INF = 0;


    long long N,W;
    cin >> N >> W;

    vector<int> weight(N);
    vector<int> value(N);

    for(int i = 0; i < N; i++){
        cin >> weight.at(i) >> value.at(i);
    }

    // DP テーブル
    long long dp[N + 10][W + 10];

    // DP テーブル全体を初期化
    for (int i = 0; i < N + 10; ++i){
        for(int j = 0; j < W + 10; ++j){
            dp[i][j] = INF;
        }
    }

    for(int i = 1; i < N+1; i++){
        for(int j = 0; j < W+1; j++){
            if(j>=weight[i-1]){
            chmax(dp[i][j],dp[i-1][j-weight[i-1]]+value[i-1]);
            }
                chmax(dp[i][j],dp[i-1][j]);
        }

    }

    cout << dp[N][W] << endl;

}


Measured memory_bytes: 89268
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int A = nextInt();
		int B = nextInt();

		int ans = 0;
		for(int i=A;i<=B;i++){
			String s = String.valueOf(i);
			if(isPalindromicStr(s)){
				ans++;
			}
		}

		System.out.println(ans);

	}

	public static boolean isPalindromicStr(String s){
		int h=0;
		int t=s.length()-1;
		while(h<=t){
			if(s.charAt(h)!=s.charAt(t)){
				break;
			}
			h++;
			t--;
		}
		if(h>t){
			return true;
		}
		return false;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 26068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[105][4]={0};
int main()
{
    int k;
    string s;
    cin>>s>>k;
    int n=s.size();
    ll ans=0;
    dp[0][1]=0;
    dp[0][2]=0;
    dp[0][3]=0;
    for(int i=1;i<=n;i++)
        dp[i][1]=9*i;
    for(int j=2;j<=3;j++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int kk=1;kk<i;kk++)
                dp[i][j]+=9*dp[kk][j-1];
        }
    }
    if(n<k)
    {
        cout<<"0\n";
        return 0;
    }
    if(k==1)
    {
        cout<<dp[n-1][1]+(s[0]-'0');
        return 0;
    }
    if(k==2)
    {
        int a1=1;
        while(s[a1]=='0') a1++;
        if(a1==n) cout<<dp[n-1][2]+(s[0]-'0'-1)*dp[n-1][1];
        else cout<<dp[n-1][2]+(s[0]-'0'-1)*dp[n-1][1]+dp[n-a1-1][1]+(s[a1]-'0');

    }
    if(k==3)
    {
        int a1=1;
        while(s[a1]=='0') a1++;
        if(a1==n)
        {
            cout<<dp[n-1][3]+(s[0]-'0'-1)*dp[n-1][2];
            return 0;
        }
        int a2=a1+1;
        while(s[a2]=='0') a2++;
        if(a2==n)
        {
            cout<<dp[n-1][3]+(s[0]-'0'-1)*dp[n-1][2]+dp[n-a1-1][2]+(s[a1]-'0'-1)*dp[n-a1-1][1];
            return 0;
        }
        else cout<<dp[n-1][3]+(s[0]-'0'-1)*dp[n-1][2]+dp[n-a1-1][2]+(s[a1]-'0'-1)*dp[n-a1-1][1]+dp[n-a1-a2][1]+(s[a2]-'0');
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.joi6ioi", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		int joi = 0, ioi = 0;
		int pos = 0;

		while ( pos = (str.find ("JOI", pos) ) + 1 ){
			++joi;
		} // end while
		pos = 0;
		while ( pos = (str.find ("IOI", pos) ) + 1 ){
			++ioi;
		} // end while

		cout << joi << endl;
		cout << ioi << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int n, c;
    cin >> n >> c;
    vector<vector<int>> v1(c + 1, vector<int>(0)), v2(c + 1, vector<int>(0));
    for (int i = 0; i < n; i++) {
        int s, t, cc;
        cin >> s >> t >> cc;
        v1[cc].push_back(s);
        v1[cc].push_back(t);
    }
    vector<int> begin(100001, 0), end(100001, 0);
    for (int i = 1; i <= c; i++) {
        sort(v1[i].begin(), v1[i].end());
        for (auto num : v1[i]) {
            if (v2[i].size() > 0 && v2[i].back() == num) {
                v2[i].pop_back();
            } else {
                v2[i].push_back(num);
            }
        }
        for (int j = 0; j < v2[i].size(); j += 2) {
            begin[v2[i][j]]++;
            end[v2[i][j + 1]]++;
        }
    }

    int res = 0;
    int r = 0;
    for (int i = 1; i <= 100000; i++) {
        r += begin[i];
        res = max(r, res);
        r -= end[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 6108
def main():
    table = [[[0]*10 for i in range (0,3)] for j in range (0,4)]

    N = int(input())
    for i in range(N):
         b_num, f_num, r_num, v_num = map(int, input().split())
         table[b_num-1][f_num-1][r_num-1] += v_num

    # print(table)

    x = 0

    for i in range(4):
        if x != 0:
            print("#"*20)
        x += 1

        for a in range(3):
            for b in range(10):
                print(" %d" % (table[i][a][b]), end="")
            print()

if __name__ == '__main__':
  main()



Measured memory_bytes: 5624
n=int(input())
s=[i for i in input()]
a=[]
for i in range(1,n):
    k=0
    x=list(set(s[:i]))
    y=list(set(s[i:]))
    for j in range(len(x)):
        if x[j] in y:
            k+=1
    a.append(k)
print(max(a))

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

int main() {
  long long A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;
  
  if (abs(B-A)<=(V-W)*T ) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
vector< vector< int > > edg;
vector< int > c, p, sz, nx;

void f(int x, int y){
    c[x] = y;
    sz[y]++;
    for(int v : edg[x]) if(c[v] == -1) f(v, 1-y);
}

int get(int x){
    int res = 0;
    if(nx[x] <= n){
        res = nx[x];
        nx[x] += 3;
    }else{
        for(int i=0;;i++){
            if(nx[i] <= n){
                res = nx[i];
                nx[i] += 3;
                break;
            }
        }
    }
    return res;
}

int main(void){
    cin >> n;
    edg.assign(n, vector<int>());
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    c.assign(n, -1);
    p.assign(n, -1);
    sz.assign(2, 0);
    nx.assign(3, 3); nx[1] = 1; nx[2] = 2;
    f(0, 0);
    if(sz[0] <= n/3){
        for(int i=0;i<n;i++) if(c[i] == 0) p[i] = get(0);
    }else if(sz[1] <= n/3){
        for(int i=0;i<n;i++) if(c[i] == 1) p[i] = get(0);
    }else{
        for(int i=0;i<n;i++){
            if(c[i] == 0) p[i] = get(1);
            if(c[i] == 1) p[i] = get(2);
        }
    }
    for(int i=0;i<n;i++){
        if(p[i] == -1) p[i] = get(0);
        cout << p[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
long long mod=pow(10,9)+7;
int main()
{
    int n,m;
    cin>>n>>m;
    char** a= new char*[n];
    for(int i=0;i<n;i++)
    a[i]=new char[m];
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    cin>>a[i][j];
    int** dp= new int*[n];
    for(int i=0;i<n;i++)
    dp[i]=new int[m];
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    dp[i][j]=0;
    int i=n-1;
    while(i>=0 && a[i][m-1]=='.')
    {
        dp[i][m-1]=1;
        i--;
    }
  
    i=m-1;
    while (i>=0 && a[n-1][i]=='.')
    {
        dp[n-1][i]=1;
        i--;
    }
 
    for(int i=n-2;i>=0;i--)
    {
        for(int j=m-2;j>=0;j--)
        {
            if(a[i][j]=='#')
            dp[i][j]=0;
            else
            {
                dp[i][j]=(dp[i+1][j]+dp[i][j+1])%mod;
            }
        }
    }
    cout<<dp[0][0];
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


ll gcd(ll a, ll b){
  return (a%b) ? gcd(b, a%b): b;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vl a(n);
  rep(i, n) cin >> a[i];

  ll wlcm = 1;
  rep(i, n){
    a[i] /= 2;
    wlcm = lcm(wlcm, a[i]);
    if ((wlcm/a[i])%2 == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  int ans = m / wlcm;
  ans = (ans + 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		switch(compareTo(scan.nextInt(), scan.nextInt())) {
		case -1:
			System.out.println("a < b");	break;
		case 0:
			System.out.println("a == b");	break;
		case 1:
			System.out.println("a > b");	break;
		default:
			;
		}
		
	}
	
	public static int compareTo(int a, int b) {
		if (a == b)
			return 0;
		
		return a > b ? 1 : -1;
	}

}



Measured memory_bytes: 26212
n,a,b=map(int,input().split())
num=[]
sumlist=[]
for i in range(1,n+1):
    num0=i
    num1=list(str(num0))
    num2=list(map(int,list(num1)))
    if a<=sum(num2)<=b:
        num.append(num0)
print(sum(num))

Measured memory_bytes: 3552
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N; std::string S; std::cin >> N >> S;
  fin(std::unique(S.begin(), S.end()) - S.begin());
  return 0;
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int n, a;
    set<int> arr;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        arr.insert(a);
    }
    if(arr.size() == n){
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO\n";
    }
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
        
     string s;
  cin>>s;
    int ssize=s.size();
     int bef[ssize+1]={0};
    int co=0;
    for(int i=ssize-1;i>=0;i--)
    {
        if(s[i]=='>')co++;
        else co=0;
        bef[i]=co;
    }
    ll sum=bef[0];
    int x=bef[0];
    for(int i=0;i<ssize;i++)
    {
        if(s[i]=='<')x++;
        else x=0;
        x=max(x,bef[i+1]);
        sum+=x;
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 2820
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

class c_gcd
{
private:

   
public:
   int f_gcd(int a,int b);
};

int c_gcd::f_gcd(int x,int y)
{
    //cout << "x = " << x << endl;
    //cout << "y = " << y << endl;
    
    if (y != 0){
        c_gcd::f_gcd(y,x % y);
    }else{
        cout << x << endl;
        return 0;
    }
    
}

int main(){
    int a,b;
   
    c_gcd gcd01;
    
    cin >> a >> b;
    
    gcd01.f_gcd(a,b);
    
    return 0;
}

Measured memory_bytes: 3092
#include<cstdio>
#include<algorithm>
const int MaxN=100010;
int N,L[MaxN],R[MaxN],Ls[MaxN],Rs[MaxN];
bool cmpl(int i,int j){return L[i]<L[j];}
bool cmpr(int i,int j){return R[i]<R[j];}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d%d",L+i,R+i),Ls[i]=Rs[i]=i;
	std::sort(Ls,Ls+N,cmpl);
	std::sort(Rs,Rs+N,cmpr);
	long long ans=0,ansl=L[Ls[N-1]],ansr=-R[Rs[0]],tmp;
	for(int i=1;i<=N;i++){
		tmp=L[Ls[N-i]]-R[Rs[i-1]];
		if(tmp<=0)break;
		ans+=tmp;
	}
	for(int i=1;i<N;i++){
		tmp=L[Ls[N-i-1]]-R[Rs[i-1]];
		if(tmp<=0)break;
		ansl+=tmp;
	}
	for(int i=1;i<N;i++){
		tmp=L[Ls[N-i]]-R[Rs[i]];
		if(tmp<=0)break;
		ansr+=tmp;
	}
	if(ansl>ans)ans=ansl;
	if(ansr>ans)ans=ansr;
	printf("%lld\n",ans*2);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a[111111],ans=INT_MAX;
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  for(int i=0;i<=n-m;i++) ans=min(ans,a[i+m-1]-a[i]);
  cout<<ans<<endl;
  return(0);
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class SegmentTree {
    using Func = std::function<T(T, T)>;
    private:
        const Func F;
        const T DEF;
        int N;
        std::vector<T> dat;
    public:
        SegmentTree(int n, const Func f, const T def) : F(f), DEF(def) {
            N = 1;
            while (N < n) N *= 2;
            dat.assign(2*N, DEF);
        }
        // a is 0-indexed
        void set(int a, const T v) {
            dat.at(a+N) = v;
        }
        void build() {
            for (int i=N-1; i>0; --i) dat.at(i) = F(dat.at(2*i), dat.at(2*i+1));
        }
        // a is 0-indexed
        void update(int a, const T v) {
            int cur = a + N;
            dat.at(cur) = v;
            while ((cur /= 2) > 0) dat.at(cur) = F(dat.at(2*cur), dat.at(2*cur+1));
        }
        // return value of [a, b)
        // a and b are 0-indexed
        T get(int a, int b) {
            return get(a, b, 1, 0, N);
        }
        T get(int a, int b, int k, int l, int r) {
            if (b <= l || r <= a) return DEF;
            if (a <= l && r <= b) return dat.at(k);
            T vleft = get(a, b, 2*k, l, (l+r)/2);
            T vright = get(a, b, 2*k+1, (l+r)/2, r);
            return F(vleft, vright);
        }
        // a is 0-indexed
        T at(int a) { return dat.at(a+N); }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> p(m);
    for (int i=0; i<m; ++i) {
        cin >> p.at(i).first >> p.at(i).second;
    }

    sort(p.begin(), p.end(), greater<pair<int, int>>());
    int res = 0, rm = n;
    for (int i=0; i<m; ++i) {
        if (rm >= p.at(i).second) {
            ++res;
            rm = p.at(i).first;
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

int main(){
	int l,r,i,j,a,ans = 2019;
	cin >> l;
	cin >> r;

	if((r-l) >= 2019){
		cout << 0;
	}
	else if(l%2019 > r%2019){
		cout << 0;
	}
	else if(l%2019 < r%2019){
		for(i = l; i < r; i++){
			for(j = l+1; j <= r; j++){
				a = ((i%2019)*(j%2019))%2019;
				if(a < ans){
					ans = a;
				}
			}
		}
		cout << ans;
	}

	return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  cout << s.substr(0, 3) << endl;

}
























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

using namespace std;

int N, C;
string Base;

bool isPrimeNumber(const string &str) {
	unsigned long long num, limit;
	stringstream ss;

	ss << str;
	ss >> num;
	limit = sqrt(num) + 1;
	for (unsigned long long i = 2; i < limit; ++i) {
		if (num%i == 0) {
			return false;
		}
	}
	return true;
}

int toInt(const string &str) {
	int num;
	stringstream ss;

	ss << str;
	ss >> num;
	return num;
}

string toString(int &num) {
	stringstream ss;

	ss << num;
	return ss.str();
}

void solve() {
	int curNum;
	char c;
	string tmp, ans;
	stringstream ss;

	c = C + '0';
	ans = Base + c + Base;
	while (true) {
		tmp = Base;
		reverse(tmp.begin(), tmp.end());
		tmp = Base + c + tmp;
		//cout << tmp << endl;
		if (isPrimeNumber(tmp)) {
			ans = tmp;
			break;
		}
		curNum = toInt(Base);
		/*if (curNum == 1) {
			break;
		}*/
		Base = toString(--curNum);
	}
	cout << ans << endl;
}

int main() {

	cin >> N >> C;
	for (int i = 0; i < N; ++i) {
		Base += "9";
	}
	if (C < 0) {
		if (N == 1) {
			cout << "11" << endl;
		}
		else {
			cout << Base << Base << endl;
		}
		return 0;
	}
	solve();
	
	return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

const int MAX_GRID = 81;
int H, W;
int A[MAX_GRID][MAX_GRID], B[MAX_GRID][MAX_GRID];

bool dp[MAX_GRID][MAX_GRID][2 * MAX_GRID * MAX_GRID];

int main() {
    cin >> H >> W;
    rep(i, H)
        rep(j, W)
            cin >> A[i][j];
    rep(i, H)
        rep(j, W)
            cin >> B[i][j];
    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    rep(i, H) {
        rep(j, W) {
            int d = abs(A[i][j] - B[i][j]);
            rep(k, 2 * 80 * 80 + 1) {
                if(i >= 1){
                    dp[i][j][k] |= dp[i - 1][j][k + d];
                    dp[i][j][k] |= dp[i - 1][j][abs(k - d)];
                }
                if(j >= 1){
                    dp[i][j][k] |= dp[i][j - 1][k + d];
                    dp[i][j][k] |= dp[i][j - 1][abs(k - d)];
                }
            }
        }
    }
    rep(k, 12800) {
        if(dp[H - 1][W - 1][k]) {
            cout << k << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 84224
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  int n; cin>>n;
  switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
    cout<<"hon"<<endl;
    break;
    case 0:
    case 1:
    case 6:
    case 8:
    cout<<"pon"<<endl;
    break;
    case 3:
    cout<<"bon"<<endl;
    break;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> p(n + 2);
    for (int i = 1; i <= n; ++i)
        cin >> p[i];
    p.back() = n + 1;
    vector<LL> dp(n + 2, 1E18);
    dp[0] = 0;
    for (int i = 1; i <= n + 1; ++i) {
        for (int j = i - 1, c = 0; j >= 0; --j) {
            if (p[j] > p[i])
                ++c;
            else
                dp[i] = min(dp[i], dp[j] + 1LL * c * a + 1LL * (i - j - 1 - c) * b);
        }
    }
    cout << dp.back() << endl;
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

template <typename T> int sgn(T val) {
  return (T(0) < val) - (val < T(0));
}

void solve() {
  long long t[2], a[2], b[2];
  scanf("%lld%lld%lld%lld%lld%lld", t, t+1, a, a+1, b, b+1);
  long long p[6][2], d[6];
  for (int i = 0; i < 6; ++i) {
    p[i][0] = t[i%2]*a[i%2];
    p[i][1] = t[i%2]*b[i%2];
    if (!i) continue;
    p[i][0] += p[i-1][0];
    p[i][1] += p[i-1][1];
  }
  for (int i = 0; i < 6; ++i) {
    d[i] = p[i][0]-p[i][1];
  }
  if (d[1] == 0 || d[1] == d[3]) {
    puts("infinity");
    return;
  }
  if (sgn(d[0]) == sgn(d[1])) {
    puts("0");
    return;
  }
  if (d[0]%d[1]==0) {
    printf("%lld", abs(d[0]/d[1]*2));
  } else {
    printf("%lld", abs(d[0]/d[1]*2)+1);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

ll n,dsize;
vector<ll> x,y,d;
string dir ="LUDR";

string solve (int now);
int main(void){
	cin >> n;
	x.resize(n);
	y.resize(n);
	for(int i=0;i<n;i++)cin >> x[i] >> y[i];
	for(int i=1;i<n;i++){
		if(abs(x[i-1] + y[i-1])%2 != abs(x[i]+y[i])%2){
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i=0;i<31;i++)d.push_back( ( 1LL << (30-i) ) );
	if(!(abs(x[0]+y[0])%2))d.push_back(1);
	dsize = d.size();
	cout << dsize << endl;
	for(int i = 0;i < dsize;i++){
		if(i != 0 )cout << " ";
		cout << d[i];
	}
	cout << endl;
	for(int i=0;i<n;i++)cout << solve(i) << endl;
	return 0;
}

string solve(int now){
	string ans;
	ll uv[2] = {x[now]+y[now]+(1LL<<31)-1,x[now]-y[now]+(1LL<<31) -1 };
	if(abs(x[now]+y[now])%2==0)++uv[0],++uv[1];
	for(int i=0;i<dsize;i++){
		int flag = 0;
		for(int j=0;j<2;j++){
			if(uv[j] >=2*d[i]){
				flag += 1 << j;
				uv[j] -= 2*d[i];
			}
		}
		ans += dir[flag];
	}
	assert(uv[0] == 0 && uv[1] == 0 );
	return ans;
}

Measured memory_bytes: 384