akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  string S="Yes";
  if(A!=B||B!=C||C!=A) S="No";
  cout<<S;
return 0;}

Measured memory_bytes: 3616
import math
n, d = map(int, input().split())
positions = []
for i in range(n):
    positions.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i+1, n):
        sum = 0
        for k in range(d):
            sum += (positions[i][k] - positions[j][k]) ** 2
        if math.sqrt(sum).is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(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 ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PI 3.14159265358979323846
using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  vector<int> HED(n);
  REP(i, n) { HED[i] = -2; }
  REP(i, n) { cin >> H[i]; }
  vector<int> A(m);
  vector<int> B(m);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    A[i] = a - 1;
    B[i] = b - 1;
  }

  vector<bool> isHIGH(n, true);

  REP(i, m) {
    if (H[A[i]] < H[B[i]]) {
      isHIGH[A[i]] = false;
    } else if (H[A[i]] == H[B[i]]) {
      isHIGH[A[i]] = false;
      isHIGH[B[i]] = false;
    } else {
      isHIGH[B[i]] = false;
    }
  }

  // cout << "GOAL" << endl;
  int ans = 0;
  REP(i, n) {
    if (isHIGH[i]) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6404
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    if(a<b && b<c){
        
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    
    return 0;
}

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

int main() {
    char a;
    cin >> a;
    
    switch(a){
        case 'q':
        case 'w':
        case 'e':
        case 'r':
        case 't':
        case 'y':
        case 'u':
        case 'i':
        case 'o':
        case 'p':
        case 'a':
        case 's':
        case 'd':
        case 'f':
        case 'g':
        case 'h':
        case 'j':
        case 'k':
        case 'l':
        case 'z':
        case 'x':
        case 'c':
        case 'v':
        case 'b':
        case 'n':
        case 'm':
            cout << 'a' << endl;
            break;
        default:
            cout << 'A' << endl;
            break;
    }
}

Measured memory_bytes: 3640
import itertools
while 1:
    n = int(raw_input())
    if n == 0: break
    ss = map(int, raw_input().split())
    for i in itertools.count(0):
        ps = [ss.count(s) for s in ss]
        if ps == ss:
            break
        ss = ps
    print i
    print ' '.join(map(str, ps))

Measured memory_bytes: 4356
#include <iostream>

using namespace std;

int tax(int p, double x);

int main(void)
{
	int x, y, s;
	while(cin>>x>>y>>s && x > 0){
		int maxi=0;
		for(int i=1;i<s-1;i++){
			for(int j=i;j<s-1;j++){
				if (tax(i, x)+tax(j, x)==s){
					maxi = max(maxi, tax(i, y)+tax(j, y));
				}
			}
		}
		cout << maxi << endl;
	}	
	return 0;
}

int tax(int p, double x)
{
	return (int)(p*(100.0+x)/(100.0));
}


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

long euclidean_gcd(long a, long b) {
  if(a < b) return euclidean_gcd(b, a);
  long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
    long K;
    long sum_gcd = 0, tmp;
    cin >> K;
    for (long a = 1; a <= K; a++) {
        for (long b = 1; b <= K; b++) {
            for (long c = 1; c <= K; c++) {
                // sum_gcd += gcd(a, b, c);
                tmp = euclidean_gcd(a, b);
                sum_gcd += euclidean_gcd(tmp, c);
            }
        }
    }
    cout << sum_gcd << endl;
}

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

using namespace std;

int main(void)
{
	int h, n;
	cin >> h >> n;
	long long a[n], b[n];
	long long max_a = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] > max_a)
			max_a = a[i];
	}
	long long d[h+max_a];

	long long INF = 10e12;
	d[0] = 0;
	for (int i = 1; i < h+max_a; i++)
		d[i] = INF;
	for (int i = 1; i < h+max_a; i++) {
		long long min = INF;
		for (int j = 0; j < n; j++) {
			if (i-a[j] >= 0) {
				if (min > (d[i-a[j]] + b[j]))
					min = d[i-a[j]] + b[j];
			}
		}
		d[i] = min;
	}
	long long ans = INF;
	for (int i = h; i < h+max_a; i++) {
		if (d[i] < ans)
			ans = d[i];
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
    long int n,w;
    cin>>n>>w;
    vector<pair<long int,long int>> vt;
    long int a,b;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        vt.push_back(make_pair(a,b));
    }
    sort(vt.begin(),vt.end());
    vector<vector<long int>> dp(vt.size() , vector<long int> (w+1,0));
    
    
    for(int i=0;i<vt.size();i++)
    {
        for(int j=1;j<=w;j++)
        {
            
            if(i==0)
            {
                if( j >= vt[i].first)
                dp[i][j]=vt[i].second;
            }
            else
            dp[i][j]=j-vt[i].first>=0?max(dp[i-1][j],vt[i].second+dp[i-1][j-vt[i].first]):dp[i-1][j];
            
        }
    }
    
    
  
    
cout<<dp[n-1][w];
    return 0;
}


Measured memory_bytes: 79488
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n,a,b = map(int,input().split())
    ans=0
    if (b-a) % 2 == 0:
        print((b-a) // 2)
    else:
        print((b-a)//2 + min(a-1,n-b) + 1)

if __name__=="__main__":
    main()

Measured memory_bytes: 9080
#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <sstream>
#include <queue>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define mk make_pair
#define fi first
#define se second
#define ALL(A) A.begin(), A.end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repr(i, n) for(int (i)=(int)(n);(i)>=0;(i)--)
#define repab(i,a,b) for(int (i)=(int)(a);(i)<=(int)(b);(i)++)
#define reprab(i,a,b) for(int (i)=(int)(a);(i)>=(int)(b);(i)--)
#define sc(x) scanf("%d", &x)
#define pr(x) printf("x:%d\n", x)
#define fastio ios::sync_with_stdio(0), cin.tie(0)
#define frein freopen("in.txt", "r", stdin)
#define freout freopen("out.txt", "w", stdout)
#define freout1 freopen("out1.txt", "w", stdout)
#define PI M_PI
#define debug cout<<"???"<<endl
#define mid ((l+r)>>1)
const ll mod = 1000000007;
//const int INF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}

const int maxn =  5e6+10;

ll x,y;
int main(){
    //frein;
    cin >> x >> y;
    int cnt = 0;
    for(cnt = 0; x <= y; cnt++){
        x *= 2;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	
	int n,a,b;
	cin>>n>>a>>b;
	int x = 0;
	if(n%a){
		x = n / a + 1;
	}else{
		x = n/a;
	}

	cout<<x*b<<endl;

	

	return 0;
}

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

int main() {
    
    while (1) {
        int x, y;
        cin >> x >> y;
        
        if (x == 0 && y == 0) {
            break;
        }
        
        if (x <= y) {
            cout << x << " " << y << endl;
        }
        else {
            cout << y << " " << x << endl;
        }
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

const int maxN=110000;
bool Prime[maxN+1]={};
void PrimeArray(int n){
    for(int i=0;i<=maxN;i++){
        Prime[i]=true;
    }
    Prime[0]=false;
    Prime[1]=false;
    int root_n = (int)sqrt(n);
    for(int i=2;i<=root_n;i++){
        if(Prime[i]==false)continue;
        for(int j=2*i;j<=n;j+=i){
            Prime[j]=false;
        }
    }
}

signed main(void){
    int X;
    cin >> X;
    PrimeArray(110000);
    REP(i,110000){
        if(i>=X && Prime[i]==true){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for(int i = 1; i <= n; ++ i)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define dow(i, a, b) for(int i = a; i >= b; i --)

using namespace std;
const int N = 300005;
char s[N];
int f[N], a[N], a1[N], sum[N], sum1[N];

int main()
{
	int n;
	scanf("%d", &n);
	scanf("%s", s + 1);
	REP(i, n) if(s[i] == 'E') a[i] = 0; else a[i] = 1;
	dow(i, n, 1) if(s[i] == 'E') a1[i] = 1; else a1[i] = 0;
	rep(i, 1, n) sum[i] = sum[i - 1] + a[i];
	dow(i, n, 1) sum1[i] = sum1[i + 1] + a1[i];
	
//	REP(i, n) cout<<sum[i] << " " << sum1[i]<<endl;
	
//	int ans = min(sum1[1], sum[n]);
	int ans = 1e9;
	rep(i, 1, n) ans = min(sum[i - 1] + sum1[i + 1], ans);
	printf("%d\n", ans);
	return 0;
}

/*

5
WEEWW

12
WEWEWEEEWWWE

8
WWWWWEEE

*/

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for (ll i(2);i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if (n!=1) res[n]=1;
  return res;
}

int main(){
  ll N;
  cin>>N;
  map<ll,ll> m = prime_factor(N);
  ll ans(0);
  for(auto mi:m){
    int cnt(0);
    for(int i(1);i<100;i++){
      cnt += i; 
      if(mi.second < cnt){
        ans += i - 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

typedef pair<int,int> P;

signed main(){
	int w,h,p[100000],q[100000],ans = 0;
	int tat = 0,yok = 0;
	vector<P> vec;
	cin >> w >> h;
	for(int i = 0;i < w;i++) {
		cin >> p[i];
		vec.push_back(P(p[i],i));
	}
	for(int i = 0;i < h;i++) {
		cin >> q[i];
		vec.push_back(P(q[i],i + w));
	}
	sort(vec.begin(),vec.end());
	for(int i = 0;i < h + w;i++){
		int cost = vec[i].first,v = vec[i].second;
		bool dir = v >= w;
		if(dir) {
			v -= w;
			ans += cost * (w + 1 - tat);
			yok++;
		}else{
			ans += cost * (h + 1 - yok);
			tat++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7536
#include "bits/stdc++.h"
using namespace std;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a+1<2*c)for(int i=a;i<=b;i++)cout<<i<<"\n";
    else{
        for(int i=0;i<c;i++)cout<<a+i<<"\n";
        for(int i=1-c;i<=0;i++)cout<<b+i<<"\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll M, K;
  cin>>M>>K;
  if(K==0) {
    for(int i=0;i<(1<<M);++i) {
      cout<<i<<" "<<i<<" ";
    }
    cout<<endl;
    return 0;
  }
  ll tmp = 0;
  for(int i=0;i<(1<<M);++i) {
    if(i==K) continue;
    tmp ^= i;
  }
  if(tmp!=K) {
    cout<<-1<<endl;
    return 0;
  }
  cout<<0<<" "<<K<<" "<<0<<" ";
  for(int i=1;i<(1<<M);++i) {
    if(i==K) continue;
    cout<<i<<" ";
  }
  cout<<K<<" ";
  for(int i=(1<<M)-1;i>0;--i) {
    if(i==K) continue;
    cout<<i<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int N =sc.nextInt();
		int [] A = new int[N];
		for(int i=0 ; i < N; i++  ){
			A[i] = sc.nextInt();
		}
		show(A);
		for(int i =1; i < N ; i++){
			int v = A[i];
			int j = i-1;
			while(j >= 0 && A[j] > v){
				A[j+1] = A[j];
				j --;
			}
			A[j+1] = v;
			show(A)	;
			}	
	}
	public static void show(int[] A){
		StringBuilder sb = new StringBuilder();
		for (int i = 0 ; i < A.length; i++){
			sb.append(A[i]);
			if(i != A.length -1){
				sb.append(" ");
			}
		}
		System.out.println(sb); 
	}
	
}

Measured memory_bytes: 28468
#include <stdio.h>

int main(void) {
    char S[100] = {'U'};
    scanf("%s", S);

    for (int i = 0; i < 100; i++) {
        if ((i + 1) % 2 == 0) {
            if (S[i] == 'R') {
                printf("No\n");
                return 0;
            }
        } else {
            if (S[i] == 'L') {
                printf("No\n");
                return 0;
            }
        }
    }

    printf("Yes\n");
    return 0;
}

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

#define ll long long int

const int MAX = 100006;

int a[MAX],b[MAX];


int main()
{

    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> ar(n);
    for(int i=0;i<n;++i)
    cin >> ar[i].first >> ar[i].second;
    sort(ar.begin(),ar.end());
    ll ans = 0;
    bool yo = true;
    for(int i=0;i<n;++i)
    {
        
        while(ar[i].second-->0)
        {
            m--;
            ans+=ar[i].first;
            if(m==0)
            {
                yo = false;
                break;
            }
            
        }
        if(!yo)break;
    }
    
    cout << ans;
}

Measured memory_bytes: 1024
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define N 100001
main() {
	int n,a[2*N];
	rep(i,2*N)a[i]=-1;
	scanf("%d",&n);
	rep(i,n) {
		if(i%2)scanf("%d",&a[N-(i+1)/2]);
		else scanf("%d",&a[N+i/2]);
	}
	if(n%2)Rep(i,-(n-1)/2,(n+1)/2)printf("%d ",a[N-i]);
	else Rep(i,N-n/2,N+n/2)printf("%d ",a[i]);
}

Measured memory_bytes: 2816
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n;
    cin >> n;

    ll ans = 0;

    for (int i = 1; i <= n; i++)
    {
        ll x = n / i;
        ans += x * (x + 1) / 2 * i;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3644
from collections import deque

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 1
    while queue:
      #queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。
        y, x = queue.popleft()#queueに入っていたものを消す。
        if [y, x] == [gy, gx]:#もしゴールについていたならば、そのときの手数を出す。
            return visited[y][x]
        r = ([1, 0, 0], [-1, 0, 1], [0, 1, 2], [0, -1, 3])
        for j, k, l in r:#上下左右についてcheck
          new_y, new_x = y+j, x+k #改行して条件文を続けるときにバックスラッシュ
          if (0 <= new_y < d) and (0 <= new_x < w):
            if visited[new_y][new_x] >= 10 ** 10:#まだ来たことない点だったという条件
              if (l == 0) and (maze[2 * y + 1][x] == 0):
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])#新しい点を足す。
              elif (l == 1) and (maze[2 * y - 1][x] == 0):
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])#新しい点を足す。           
              elif (l == 2) and (maze[2 * y][x] == 0):
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])#新しい点を足す。                   
              elif (l == 3) and (maze[2 * y][x - 1] == 0):
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])#新しい点を足す。 
                
                
T = True
while T:
  w, d = map(int, input().split())
  if (w, d) == (0, 0):
    T = False
    quit()
  visited = [[float("inf")] * w for i in range(d)]
  visited2 = [[0] * w for i in range(d)]
  visited[0][0] = 1
  visited2[0][0] = 1
  maze = [0] * (2 * d - 1)
  for i in range(2 * d - 1):
    maze[i] = list(map(int, input().split()))
  #print(maze)
  bfs(maze, visited, 0, 0, d - 1, w - 1)
  #print(visited)
  if visited[d - 1][w - 1] >= 10 ** 10:
    print(0)
  else:
    print(visited[d - 1][w - 1])
  
  
  
  
  


Measured memory_bytes: 6068
import sys

N, K = map(int, input().split())
XY = sorted(list(map(int, sys.stdin.readline().split())) for i in range(N))
X, Y = [], []
for xi, yi in XY:
    X.append(xi)
    Y.append(yi)

ans = float('inf')
for i in range(N):  # 左
    for j in range(i+1, N):  # 右
        for k in range(N):  # 下
            for l in range(N):  # 上
                if Y[k] >= Y[l]:
                    continue
                cnt = 0
                for x, y in zip(X, Y):  # 含まれてるかカウント
                    if X[i] <= x <= X[j] and Y[k] <= y <= Y[l]:
                        cnt += 1
                        if cnt == K:
                            ans = min(ans, (X[j] - X[i]) * (Y[l] - Y[k]))
                            break

print(ans)


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

using namespace std;

typedef long long ll;

const int maxn=2e5+10;

int k;
int a[maxn];
int dp[81];


int main()
{
  	int n;
  	cin>>n;
    for ( int i = 1; i <= n; i++ ) cin>>a[i];
    
    ll res = 1000, cnt = 0;
    for ( int i = 1; i <= n; i++ ) 
	{
        if( a[i] < a[i + 1] ) 
		{
            cnt += res / a[i];
            res%=a[i];
        }
        else if( a[i] > a[i + 1] )
		 {
            res += cnt * a[i];
            cnt = 0;
        }
    }
    res+=cnt*a[n];
    printf("%lld\n", res);
	
} 

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int a, b;
string s;

signed main()
{
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }


    return 0;
}


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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sol = min(a, k);
    k -= sol;
    if (k)
        k -= min(k, b);
    if (k)
        sol -= min(k, c);
        
    cout << sol;
    
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
LL A[214514];
bool used[214514];
map<LL, set<int>> cnt;

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%lld", &A[i]);
    cnt[A[i]].insert(i);
  }

  int ans = 0;
  rrep(k, 40) {
    LL target = 1LL << k;
    rep(i, N) {
      if (used[i]) continue;
      if (!cnt.count(target-A[i])) continue;
      if (cnt[target-A[i]].empty()) continue;
      
      int idx = *cnt[target-A[i]].begin();
      if (idx == i) idx = *cnt[target-A[i]].rbegin();
      if (idx == i) continue;
      used[i] = true;
      used[idx] = true;
      ans++;
      cnt[A[i]].erase(i);
      cnt[target-A[i]].erase(idx);
    }
  }
  printf("%d\n", ans);
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<int,int> >num;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    num.pb(mp(a,i));
  }
  sort(num.begin(),num.end());
  int ans=1;
  int cnt=1;
  for(int i=1;i<n;i++){
    // cout<<num[i].S<<" "<<num[i-1].S<<endl;
    if(num[i].S>num[i-1].S){
      cnt++;
    }else{
      ans=max(ans,cnt);
      cnt=1;
    }
    if(cnt==n)ans=n;
  }
  cout<<n-ans<<endl;
  return 0;
}


Measured memory_bytes: 2548
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

int main(){
    int N;cin>>N;
    vector<int> A(N);
    int cn=0;
    bool flag=true;
    int absm=1e9+1;
    ll sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]<0&&flag) cn++;
        if(A[i]==0){
            cn=0;
            flag=false;
        }
        if(absm>abs(A[i])){
            absm=abs(A[i]);
        }
        sum+=abs(A[i]);
    }
    if(cn&1) sum-=2*absm;
    cout<<sum<<endl;
    return 0;
}

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

int main(){
    while(1){
        long long int n,k;
        cin >> n >> k;
        if(n==0) break;
        long long int p10=1, num=0, step=1;
        while(1){
            if(n <= num+ 9*p10*step) break;
            num += 9*p10*step;
            p10 *= 10;
            step++;
        }
        n -= num+1;
        int start = n/step+p10;
        string ret = "";
        for(int i=0; i<100; i++){
            ret += to_string(start+i);
        }
        cout << ret.substr(n%step, k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3272
n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n,m;
char a[100005],b[100005];
int main() {
	int i,k;
	scanf("%s",a+1); n=strlen(a+1);
	for (i=1,m=0;i<=n;++i) {
		b[++m]=a[i];
		while (b[m]==b[m-2]) m-=2;
	}
	//b[m+1]=0; printf("%s\n",b+1);
	if (m<3) k=0;
	else if (b[1]==b[m]) k=(m-3)&1;
	else k=(m-2)&1;
	if (k) printf("First\n"); else printf("Second\n");
	return 0;
}

/*
*/


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int main()
{
    ll n, m;
    while(scanf("%lld%lld", &n, &m) != EOF)
    {
        if(m / 2 <= n)
            printf("%lld\n", m / 2);
        else
        {
            ll sum = 0;
            sum += n;
            m = m - n * 2;
            sum += m / 4;
            printf("%lld\n", sum);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iostream>

#define PI 3.14159265358979323846264338327950288L

using namespace std;

int main()
{
	int n;

	vector<long double> x(1001), y(1001);

	x[1] = 1.0; y[1] = 0.0;

	for (int i = 2; i <= 1000; i++)
	{
		long double theta = PI / 2.0L + atan2l(y[i - 1], x[i - 1]);

		x[i] = x[i - 1] + cos(theta);
		y[i] = y[i - 1] + sin(theta);
	}

	while (true)
	{
		cin >> n;

		if (n == -1) { break; }

		cout << x[n] << endl << y[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< (int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb(e) push_back(e)
#define foreach(c, i) for(iter(c) i = (c).begin(); i != c.end(); ++i)
#define mp(a, b) make_pair(a, b)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int sz = 220;
int dp[sz][sz];

int main(){
  int T, N;
  cin >> T;
  while(T--){
    cin >> N;
    vector<int> cards;
    rep(i, N){
      int c;
      cin >> c;
      cards.pb(c);
    }
    
    rep(i, N)  cards.pb(cards[i]);
    memset(dp, 0, sizeof(dp));


    rep(i, 2 * N) dp[i][i] = 0;
    for(int w = 2; w <= N; w++){
      rep(i, 2 * N - w + 1){
	// calc dp[i][i+w-1]
	for(int k = i + 1; k <= i + w - 1; k++){
	  dp[i][i+w-1] = max(dp[i][i+w-1],
			     dp[i][k-1] + dp[k][i+w-1] + abs(cards[i] - cards[k]));
	}
      }
    }
    
    int res = 0;
    rep(i, N){
      res = max(res, dp[i][i + N - 1]);
    }
    cout << res << endl;
  }
  return 0;
}

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



/*引き算するときは0または負の数になることを考えて関数の引数に渡す
to_str(s.size()-1 == 0) は例外を投げる

いつもintをdefineしてllにしてるとstollにせずにstoiにしてしまうから気を付ける。
*/
signed main()
{
	int a;
	cin >> a;
	a++;
	string s = to_string(a);
	int ans = (s.length() - 1) * 9 + s[0] - '1';
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  int ans=0,k=0;
  for(int i=1;i<n;i++)
  {
      if(a[i]>a[i-1])
      {
          ans=max(ans,k);
          k=0;
      }
      else k++;
      ans=max(ans,k);

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



Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>

int main(void)
{
	char ch, str[1200];
	int i = 0;
	
	while (1) {
		scanf("%c", &ch);
		if (ch == '\n' || ch =='\0') {
			break;
		}
		if (isupper(ch)) {
			str[i] = tolower(ch);
		} else if (islower(ch)) {
			str[i] = toupper(ch);
		} else {
			str[i] = ch;
		}
		
		i++;
	}
	
	str[i] = '\0';
	
	printf("%s\n", str);
	
	return 0;
}

Measured memory_bytes: 528
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX / 2)

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    ll d;
    ll max_v=-INF;
    ll max_i=0;
    cin>>d;
    vector<ll>c(d);
    vector<vector<ll>>s(d,vector<ll>(26));
    vector<ll> ans;
    rep(i,d){
        cin>>c[i];
    }
    rep(i,d){
        max_v=-INF;
        rep(j,26){
            cin>>s[i][j];
            if(max_v<s[i][j]){
                max_v=s[i][j];
                max_i=j+1;
            }
        }
        ans.push_back(max_i);
    }
    for(auto i:ans){
        cout<<i<<endl;
    }
}
/*

*/


Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] ar = new int[n];
        int first = 0, second = 0;
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
            if (first >= ar[i]) {
                second = Math.max(second, ar[i]);
            }
            first = Math.max(first, ar[i]);
        }

        for (int i = 0; i < n; i++) {
            if (ar[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
}


Measured memory_bytes: 94908
#include <stdio.h>
#include <string.h>

#define L 50

int main() {
	static int aa[26];
	int n, c;

	scanf("%d", &n);
	memset(aa, L + 1, sizeof aa);
	while (n--) {
		static char s[L + 1];
		static int kk[26];
		int l, i;

		scanf("%s", s);
		l = strlen(s);
		memset(kk, 0, sizeof kk);
		for (i = 0; i < l; i++)
			kk[s[i] - 'a']++;
		for (c = 0; c < 26; c++)
			if (aa[c] > kk[c])
				aa[c] = kk[c];
	}
	for (c = 0; c < 26; c++)
		while (aa[c]--)
			printf("%c", c + 'a');
	printf("\n");
	return 0;
}


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

using namespace std;

class ModInt{
private:
  long long number;

public:
  static constexpr long long mod = 1000000007;

  constexpr ModInt(const ModInt& x) : number(x.number){};

  constexpr ModInt(const long long number = 0) : number((mod + number) % mod){}

  constexpr long long get() const{
    return number;
  }

  constexpr ModInt& operator=(const ModInt& rhs) &{
    number = rhs.number;
    return *this;
  }

  constexpr ModInt operator+() const{
    return ModInt(*this);
  }

  constexpr ModInt operator-() const{
    return ModInt(mod - number);
  }

  constexpr ModInt& operator+=(const ModInt& rhs){
    number += rhs.number;
    if(number >= mod) number -= mod;
    return *this;
  }

  constexpr ModInt& operator-=(const ModInt& rhs){
    number -= rhs.number;
    if(number < 0) number += mod;
    return *this;
  }

  constexpr ModInt& operator*=(const ModInt& rhs){
    (number *= rhs.number) %= mod;
    return *this;
  }

  constexpr ModInt& operator/=(const ModInt& rhs){
    (*this) *= rhs.inverse();
    return *this;
  }

  constexpr ModInt inverse() const{
    long long a = number, m = mod, u = 1, v = 0;

    while(m){
      long long t = a / m;
      a -= t * m;
      u -= t * v;

      //swap a, m
      a ^= m;
      m ^= a;
      a ^=m;

      //swap u, v
      u ^= v;
      v ^= u;
      u ^= v;
    }

    return ModInt(u);
  }

  constexpr ModInt& operator++(){
    return *this += 1;
  }

  constexpr ModInt& operator--(){
    return *this -= 1;
  }

  constexpr ModInt operator++(int x){
    ModInt ret = *this;
    ++(*this);
    return ret;
  }

  constexpr ModInt operator--(int x){
    ModInt ret = *this;
    --(*this);
    return ret;
  }
};

constexpr ModInt operator+(const ModInt& lhs, const ModInt& rhs){
  return ModInt(lhs) += rhs;
}

constexpr ModInt operator-(const ModInt& lhs, const ModInt& rhs){
  return ModInt(lhs) -= rhs;
}

constexpr ModInt operator*(const ModInt& lhs, const ModInt& rhs){
  return ModInt(lhs) *= rhs;
}

constexpr ModInt operator/(const ModInt& lhs, const ModInt&rhs){
  return ModInt(lhs) /= rhs;
}

constexpr ModInt operator^(const ModInt& lhs, const int& rhs){
  long long b = lhs.get(), e = rhs, y = 1, mod = lhs.mod;
  bool inv = e < 0;
  if(inv) e = -e;

  while(e){
    if(e & 1) (y *= b) %= mod;

    (b *= b) %= mod;
    e >>= 1;
  }

  return (inv ? ModInt(y).inverse() : ModInt(y));
}

std::istream& operator>>(std::istream& is, ModInt& x){
  long long in;
  is >> in;
  x = in;
  return is;
}

std::ostream& operator<<(std::ostream& os, const ModInt& x){
  os << x.get();
  return os;
}

int main(){
  int N, K;
  cin >> N >> K;
  
  ModInt ans = 0;
  for(int k = K; k <= N + 1; k++){
    ans += (long long)k * (N - k + 1) + 1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
/*using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
int dp[3009][3009];
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
        string s,t;
        cin>>s>>t;

        int ns= sz(s),nt = sz(t);
        rep(i,1,ns+1)
        {
            rep(j,1,nt+1)
            {
                if(s[i-1]==t[j-1])
                    dp[i][j] = 1+ dp[i-1][j-1];
                else
                    dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
        int n = dp[ns][nt];
        char arr[n+1];
        arr[n]=  '\0';
        int i = ns,j = nt;
        while(i>0&&j>0)
        {
            if(s[i-1]==t[j-1]){
                arr[n-1] = s[i-1];
                i--;
                j--;
                n--;
            }
            else if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
                j--;
        }
        cout<<arr<<el;



    }
    return 0;
}


Measured memory_bytes: 70784
#include<stdio.h>
int main (void)
{
    int n,i,a,b,ansa=0,ansb=-1;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(b>ansb){
            ansa=a,ansb=b;
        }
        if(b==ansb&&a<ansa){
            ansa=a;
        }
    }
    printf("%d %d\n",ansa,ansb);
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll n, m;
	cin >> n >> m;
	vector<pair<int , int>> a(m);
	rep(i, m) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a.begin(), a.end());
	ll count = 0;
	int now = -1;
	rep(i,a.size()){
		if (now < a[i].second) {
			now = a[i].first - 1;
			count++;
		}
	}
	cout << count;
	return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;
int main(){
  int N,M;
  cin>>N>>M;
  vector<ll> x(N),y(N),z(N);
  for(int i(0);i<N;i++){
    cin>>x[i]>>y[i]>>z[i];
  }
  ll ans(0);
  for(int i(-1);i<2;i++){
    for(int j(-1);j<2;j++){
      for(int k(-1);k<2;k++){
        if(i == 0 || j == 0 || k == 0) continue;
        vector<ll> cnt(0);
        for(int l(0);l<N;l++){
          cnt.push_back(x[l]*i+y[l]*j+z[l]*k);
        }
        sort(cnt.rbegin(),cnt.rend());
        ll tmp(0);
        for(int l(0);l<M;l++){
          tmp += cnt[l]; 
        }
        ans = max(ans,tmp);
      }
    } 
  }
  cout << ans << endl;
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

int N, K, R, S, P;
string T;
LL dp[pow10(5)][3];
bool flg[pow10(5)][3];

// way: K番前に何を出したか: -1:Null, 0:R, 1:S, 2:P
LL rec(int turn, int way)
{
    if (turn >= N)
        return 0;

    if (flg[turn][way])
        return dp[turn][way];
    flg[turn][way] = true;

    LL ans = 0;

    if (way != 0)
        ans = max(ans, rec(turn + K, 0) + R * (T[turn] == 's'));
    if (way != 1)
        ans = max(ans, rec(turn + K, 1) + S * (T[turn] == 'p'));
    if (way != 2)
        ans = max(ans, rec(turn + K, 2) + P * (T[turn] == 'r'));

    return dp[turn][way] = ans;
}

void solve()
{
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    LL ans = 0;

    REP0 (i, K)
    {
        ans += rec(i, -1);
    }

    cout << ans;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


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

int main()
{
    std::string S, T;
    int count = 0;

    std::cin >> S;
    std::cin >> T;

    for(int i=0; i < S.size(); i++) {
        if(S[i] != T[i]) {
            count++;
        }
    }

    std::cout << count << std::endl;
}

Measured memory_bytes: 3868
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<math.h>

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

using namespace std;

int n,m;

//時刻,学生
int data[1300][10003];

void solve() {
	rep(i,1300) rep(j,10003) data[i][j]=0;
	int r;
	cin>>r;
	rep(i,r) {
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(d==1) {
			data[a][c]++;
		}
		else {
			data[a][c]--;
		}
	}

	rep(i,m+1) {
		for(int j=1;j<1300;j++) {
			data[j][i]+=data[j-1][i];
		}
	}

	int q;
	cin>>q;
	rep(i,q) {
		int a,b,c;
		cin>>a>>b>>c;
		int ans=0;
		for(int j=a;j<b;j++) {
			if(data[j][c]!=0) {
				ans++;
				//printf("[debug] %d,%d = %d\n",j,c,data[j][c]);
			}
		}
		//cout<<"ans="<<ans<<endl;
		cout<<ans<<endl;
	}

}

int main() {

	while (cin>>n>>m)
	{
		if(n+m==0) {
			return 0;
		}
		solve();
	}

	return 0;
}

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

main(){
  int n;cin >> n;
  vector<int> a(n);for(int i=0;i<n;i++) cin >> a[i];
  int cnt_odd = 0;
  string ans="YES";
  for(int i=0;i<n;i++){
    if(a[i]%2 == 1) cnt_odd++; 
  }
  if(cnt_odd%2 == 1){
    ans="NO";
    cout << ans << endl;
    return 0;
  }
  cout << ans <<endl;
  return 0;
} 

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
int res=0;
int main()
{
	cin >>n>>m;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			if (j%10<2) continue;
			if (j/10<2) continue;
			if ((j%10)*(j/10)!=i) continue;
			res++;
		}
	}
	cout <<res;
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

int l = 0, r = 0, now = 0;
int n;
vector<int> a(10), b(10);
vector<int> current(10);
map<int, bool> used;

void
find(int index) {
  if (index == n) {
    now++;

    bool same = true;
    for (int i=0; i<n; i++)
      if (a[i] != current[i]) {
        same = false;
        break;
      }
    if (same) l = now;

    same = true;
    for (int i=0; i<n; i++)
      if (b[i] != current[i]) {
        same = false;
        break;
      }
    if (same) r = now;
  }
  else {
    for (int i=1; i<=n; i++) {
      if (used[i]) continue;

      used[i] = true;
      current[index] = i;
      find(index + 1);
      used[i] = false;
    }
  }
}

void
solve() {
  cin>>n;

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

  find(0);

  cout<<abs(l - r)<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
//using System.Linq;
class Program
{
  //static List<string> list;
  //static List<int> primes = new List<int>{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,
  //                              59,61,67,71,73,79,83,89,97};
	static void Main(string[] args)
	{
		// 入力フェーズ
        int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int T = int.Parse(input[0]);
        int A = int.Parse(input[1]);
        // N個の地点の標高を取得する
        string[] height = Console.ReadLine().Split(' ');
        int[] H = new int[N];
        for(int i=0; i<N; i++)
        {
          H[i] = int.Parse(height[i]);
        }

        // 各地点の気温とAとの差のminをとる
        decimal min = 0;
        int strct = 0; //建設地点
        for(int i=0; i<N; i++)
        {
          decimal atom = (decimal)(T - H[i]*0.006);
          if(i == 0 || Math.Abs(A - atom) < min)
          {
            min = Math.Abs(A - atom);
            strct = i;
          }
        }


    // 出力
        Console.WriteLine(strct + 1);
    }
		class layer{ //自作クラス
			public long total {set; get;} // 全部の層数
			public long paty {set; get;}  // パティの数
      public long banz {set; get;}  // バンズの数
		}
}


Measured memory_bytes: 11164
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var A = Number(lines[0].split(" ")[0]);
    var B = Number(lines[0].split(" ")[1]);
    var C = Number(lines[0].split(" ")[2]);

    if (A === B && A === C && B === C) { console.log("Yes") }
    else { console.log("No") }
});

Measured memory_bytes: 7500