akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=300002;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      string s;
      cin>>s;
      int n=s.length();
      int cnt=0;
      int ans=0;
      for(int i=0;i<n;i++)
      {
            if(i+1<n)
            {
                  if(s[i]=='B'&&s[i+1]=='C')
                  {
                        if(cnt!=0)
                        {
                              ans+=cnt;
                        }
                        else{
                              cnt=0;
                        }
                        i+=1;
                  }
                  else if(s[i]=='A') cnt++;
                  else cnt=0;
            }
      }
      cout<<ans;
}     

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

int main(){
    int n, m;
    cin >> n>>m;
    int a[n];
    double sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);

    reverse(a, a + n);

    sum /= (4 * m);

    for (int i = 0; i < m; i++){
        if(a[i]<sum){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) return 0 * puts("0");
	cout << min(min(a * b, b * c), a * c) << endl;
}



Measured memory_bytes: 256
N,K = map(int, input().split())
bi = []
i = 1
j = 0
while i < K:
    bi.append(i)
    i *= 2
    j += 1
bi.append(i)
ans = max(0,N-K+1)
ite = min(N+1,K)

for i in range(1,ite):
    # print(i,j, bi[j-1] * i)
    if j > 0 and bi[j-1] * i >= K:
        j -= 1
    #print(i, j, i*bi[j])
    ans += 0.5**j
print('{:.10f}'.format(ans / N))

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

using namespace std;

signed main(){
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a%2)cout<<"No";
	else{
		string s1=s.substr(0,a/2);
		string s2=s.substr(a/2,a/2);
		if(s1==s2)cout<<"Yes";
		else cout<<"No";
	}
	
		
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main (){
    int n;
    long long int l,t[3]= {2,1};
    scanf("%d",&n);
    for(int i= 2; i<=n; i++){
        t[i%3] = t[(i-1) %3] + t[(i-2) %3];
    }
    printf("%lld\n",t[n%3]);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
a = int(input())
b = int(input())
c = int(input())
x = int(input())

f = 0
for ax in range(a + 1):
   for bx in range(b + 1):
      for cx in range(c + 1):
        if (ax*500+bx*100+cx*50 == x):
          f = f +1
print(f)


Measured memory_bytes: 3060
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s;
	cin >> s;
	if(s[1]=='B')s[1]='R';
	else s[1]='B';
	cout << s << endl;
}	


Measured memory_bytes: 3652
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>

using namespace std;

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

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

int dy[] = {1,0,-1,0}; //次に行くところ
int dx[] = {0,1,0,-1}; //上に同じ

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,cnt1 = 0,cnt2 = 0,cnt3 = 0;
  cin >> n >> m;
  vector<int> k(m),p(m),a;
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++){
    cin >> k[i];
    s[i].resize(k[i]);
    for (int j = 0; j < k[i]; j++){
      cin >> s[i][j];
    } 
  }

  for (int i = 0; i < m; i++){
    cin >> p[i];
  }
  
  for (int bit = 0; bit < 1 << n; bit++){
    cnt2 = 0;
    for (int i = 0; i < m; i++){
      cnt1 = 0;
      for (int j = 0; j < k[i]; j++){
        if (bit & 1 << s[i][j] - 1){
          cnt1++;
        }
      }
      if (cnt1 % 2 == p[i]){
        cnt2++;
      } 
    }
    if (cnt2 == m){
      cnt3++;
    }
  }
  
  
  cout << cnt3 << '\n';
  return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
const int N=305;
const int M=305;

int main(void)
{   
	int x , y ;
	
	while(scanf("%d %d", &x ,&y))
	{ 
		if(x == 0 && y == 0)
		{
		break;
		}	
		for(int i = 0 ; i < y ; i++)
		{
			printf("#");
		}
		printf("\n");
		for(int i = 0 ; i < x - 2 ; i++)
		{
			printf("#");
			for(int j = 0 ; j < y - 2 ; j++)
			{
			  printf(".");
			}
			printf("#");
			printf("\n");
		}
		for(int i = 0 ; i < y ; i++)
		{
			printf("#");
		}
		printf("\n");
		printf("\n");
	}
return 0;
}


Measured memory_bytes: 2588
import sys

n = int(sys.stdin.readline())
p = [None] * n
for i in range(n):
    p[i] = int(sys.stdin.readline())
a = [None] * n
for i in range(n):
    a[p[i]-1] = i
prv = -1
mx = 1
nw = 0
for i in range(n):
    if prv < a[i]:
        nw += 1
        mx = max(mx, nw)
    else:
        nw = 1
    prv = a[i]
print(n-mx)


Measured memory_bytes: 18836
#include <bits/stdc++.h>
using namespace std;
 
//#define READ_NUMBER(i) scanf("%d",i)
 
int main(){
	int N;
	int count = 0;
	cin >> N;
	int Value[N];
	int Cost[N];
	for(int i = 0;i < N; i++){
		cin >> Value[i];
	}
	for(int i = 0; i < N; i++){
		cin >> Cost[i];
	}
	for(int i = 0; i < N; i++){
		if(Value[i] - Cost[i] >= 0){
			count += Value[i] - Cost[i];
		}
	}
	cout << count << endl;

}

Measured memory_bytes: 256
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

def dist(x, y, u, v):
    return ((x - u)**2 + (y - v)**2)**0.5

a = dist(x1, y1, x2, y2)
b = dist(x2, y2, x3, y3)
c = dist(x3, y3, x1, y1)
s = (a + b + c) / 2

S = (s * (s - a) * (s - b) * (s - c))**0.5
leng = a + b + c
L = max(a, b, c)

r = S * 2 / leng
ans = r * L / (r + r + L)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
char s1[100005];
int cnt=0;
int main()
{
	cin>>s1;
	int n=strlen(s1);
	int l=0,r=n-1;
	while (l<=r)
	{
		if (s1[l]=='x' && s1[r]!='x')
		{
			l++;
			cnt++;
		}
		else if (s1[r]=='x' && s1[l]!='x')
		{
			r--;
			cnt++;
		}
		else {
			if (s1[r]!=s1[l])
			{
				printf("-1\n");
				return 0;
			}
			else{
			l++;r--;}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 384
from heapq import heapify, heappop, heappush

n, m = map(int, input().split())
arr = [-x for x in map(int, input().split())]
heapify(arr)

for _ in range(m):
    tmp = heappop(arr)
    heappush(arr, int(tmp / 2))

print(-sum(arr))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     // freopen("error.txt","w",stderr);
        ll n;
        cin>>n;
        ll a[n];
        ll ans[n];
        ll xr=0;
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
            xr^=a[i];
        }
        for(ll i=0;i<n;i++)
        {
            ans[i]=xr^a[i];
            cout<<ans[i]<<" ";
        }cout<<endl;
    return 0;
}

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

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> houses(n);
    for (int i = 0; i < n; i++){
        cin >> houses.at(i);
    }
    sort(houses.begin(), houses.end());

    //最初の家と最後の家の距離
    int last_dis = k - houses.at(n - 1) + houses.at(0);
    int max_dis = last_dis;
    
    for (int i = 1; i < n; i++){
        //max_dis = houses.at(i) - houses.at(i - 1) > max_dis ? houses.at(i) - houses.at(i - 1) : max_dis;
        if (houses.at(i) - houses.at(i - 1) > max_dis) {
            max_dis = houses.at(i) - houses.at(i - 1);
        }
    }
    cout << k - max_dis << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

//ostream& operator << (ostream &a, const vector<int> &b) {
//    for (auto k : b) cout << k << " ";
//    return a;
//}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")s
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(all(a));
    int cnt = 1;
    vector<string> ans;
    int  mx = 1;
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) cnt++;
        else {
            if (cnt == mx) {
                ans.pb(a[i - 1]);
            } else if (cnt > mx) {
                mx = cnt;
                ans.clear();
                ans.pb(a[i - 1]);
            }
            cnt = 1;
        }
    }
    if (cnt == mx) {
        ans.pb(a[n - 1]);
    } else if (cnt > mx) {
        mx = cnt;
        ans.clear();
        ans.pb(a[n - 1]);
    }
    cnt = 1;
    sort(all(ans));
    for (auto k : ans) cout << k << "\n";
}
/*
*/


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  vector<char> c(n);
  REP(i, n)
    c.at(i) = s[i];
  sort(s.begin(), s.end());
  
  char ans = 'a';
  REP(i, n) {
    if (s[i] > ans)
      break;
    else if (s[i] == ans)
      ++ans;
  }
  
  if (ans == 'z' + 1)
    cout << "None" << endl;
  else
    cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		if(a < b){
			System.out.println("a < b");
		}else if(a > b){
			System.out.println("a > b");
		}else {
			System.out.println("a == b");
		}
	}
}


Measured memory_bytes: 26176
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A;
    cin >> N >> A;
    cout << N*N - A;
    return 0;
}

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

void fnInput(vector<int>& rvnHeight)
{
  int nHeightSiz;
  cin >> nHeightSiz;
  rvnHeight.resize(nHeightSiz);

  for (int& rnHeight : rvnHeight)
    cin >> rnHeight;
}

int fnMinWorkCnt(vector<int>& rvnHeight)
{
  int nWorkCnt = 0;
  int nPrevWorkCnt = -1;

  while (nPrevWorkCnt != nWorkCnt)
  {
    nPrevWorkCnt = nWorkCnt;
    int nBgn = 0;
  
    while (nBgn < rvnHeight.size() )
    {
      int nFoward = nBgn;

      while (nFoward < rvnHeight.size() &&
             rvnHeight[nFoward]            )
      {
        rvnHeight[nFoward]--;
        nFoward++;
      }

      if (nBgn != nFoward)
      {
        nWorkCnt++;
        nBgn = nFoward;
      }
      else
        nBgn = nFoward + 1;
    }
  }
  return nWorkCnt;
}
 
int main()
{
  vector<int> vnHeight;

  fnInput(vnHeight);
  cout << fnMinWorkCnt(vnHeight) << endl;

  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> da(100, 0);
	for (int i = 2;i < n + 1;i++) {
		int x = i;
		for (int j = 2;j < 11;j++) {
			while (x % j == 0) {
				da[j]++;
				x /= j;
			}
		}
		da[x]++;
	}
	int tw = 0, fo = 0,ft=0,tf=0,sf=0;
	for (int i = 2;i < 100;i++) {
		if (3 < da[i])
			fo++;
		if (1 < da[i])
			tw++;
		if (13 < da[i])
			ft++;
		if (23 < da[i])
			tf++;
		if (73 < da[i])
			sf++;
	}
	int ans = 0;
	if (tw > 0 && fo > 1) {
		ans = fo * (fo - 1)*(tw - 2) / 2;
	}
	if (tw > 0 && tf > 0)
		ans += tf * (tw - 1);
	if (fo > 0 && ft > 0)
		ans += ft * (fo - 1);
	if (sf > 0)
		ans += sf;
	cout << ans << endl;
	//cout << fo << " " << tw << endl;
//	for (int i = 0;i < 100;i++)
	//	cout << i << " " << da[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int W, H, x, y;
  cin >> W >> H >> x >> y;

  int num;
  if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y)
    num = 1;
  else
    num = 0;

  cout << std::fixed << std::setprecision(10) << (double)W * H / 2 << " " << num << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> s(n + 2);
  for (int i = 1; i <= n + 1; ++i) {
    s[i] = s[i - 1] + i;
  }
  ll ans = 0;
  for (int i = k; i <= n + 1; ++i) {
    ll mn = s[i];
    ll mx = s[n + 1] - s[n - i + 1];
    ll res = mx - mn + 1;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){

    int a,b;
    cin>>a>>b;

    if(a>=b) for(int i=0;i<a;i++) cout<<b;
    else for(int i=0;i<b;i++) cout<<a;

    cout<<endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N=Integer.parseInt(sc.next());
		int[] x = new int[N];
		for(int i=0; i<N; i++) {
			x[i]=Integer.parseInt(sc.next());
		}
		int minimum =Integer.MAX_VALUE;
		for(int i=1; i<=100; i++) {
			int total = 0;
			for(int aa:x) {
				total +=(aa-i) * (aa-i);
			}
			minimum = Math.min(total, minimum);
		}
		System.out.println(minimum);
	}
}


Measured memory_bytes: 23124
#coding: utf-8

n = int(input())

x = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]


for i in range(n):
    b, f, r, v = (int(j) for j in input().split())
    x[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" " + str(x[i][j][k]), end = '' if k != 9 else '\n')

    print("#"*20 if i != 3 else '', end='\n'if i != 3 else '')


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)


int main()
{
    int n,k;
    cin >> n>> k;
    vector<ll> v(n);
    rep(i,n)
    {
        cin >> v[i];
    }
    
    int r;
    r = min(n,k);
    int a,b,cd;

    priority_queue<int, std::vector<int>, std::greater<int> > que;
    int temp = 0;
    int ans = 0;

    rep(i,r+1)
    {
        cd = k-i;//cdの操作を行う回数
        rep(j,i+1)
        {
            a = j;
            b = i-j;
            temp = 0;
            priority_queue<int, std::vector<int>, std::greater<int> > que;
            rep(k,a)
            {
                //aの操作で得たダイヤをキューに挿入
                que.push(v[0+k]);
            }

            rep(l,b)
            {
                //bの操作で得たダイヤをキューに挿入
                que.push(v[n-1-l]);
            }

            int counter = 0;

            while(!que.empty() && que.top()<0 && counter < cd)
            {
                que.pop();
                counter++;
            }

            while(!que.empty())
            {
                temp += que.top();
                //cout << que.top() << ",";
                que.pop();
            }
            if(temp>ans)
            {
                ans = temp;
            }
            //cout << a <<" " <<  b << " "  << " " << cd << " "<<  temp  << endl;
            
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
	int n,k;
	int list[50]={0};

	cin >> n >> k;
	int tmp;
	for(int i=0; i<n; i++){
		cin >> list[i];
	}
	for(int i=n-1; i>0; i--){
		for(int k=0; k<i; k++){
			if(list[k]<list[k+1]){
				tmp = list[k];
				list[k] = list[k+1];
				list[k+1] = tmp;
			}
		}
	}

	int sum=0;
	for(int i=0; i<k; i++){
		sum+=list[i];
	}
	cout << sum << endl;

}




Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        return -self.root[self.find(x)]


N, M = map(int, input().split())
uf = UF_tree(N)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

ans = 0
for i in range(N):
    ans = max(ans, uf.size(i))

print(ans)

Measured memory_bytes: 16344
#include <stdio.h>
#include <string.h>
#define NMMAX 100000
int main(void)
{
  int i, n, m, a, b, vmin = 0, bcount = 0, ledge[NMMAX] = {0};
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    if (ledge[a-1] < n - b + 1) ledge[a-1] = n - b + 1;
  }
  for (i = 0; i < n - 1; i++) {
    if (vmin < ledge[i]) vmin = ledge[i];
    if (i + 1 == n - vmin) {
      vmin = 0;
      bcount++;
    }
  }
  printf("%d\n", bcount);
}

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

typedef long long llint;
typedef long double ld;
typedef pair<int,int> P;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())


priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

void solve(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)v[i]=i+1;
    vector<int>p(n+1),q(n+1);
    for(int i=0;i<n;i++)cin >> p[i];
    for(int i=0;i<n;i++)cin >> q[i];
    int c1,c2;
    int now=1;
    do{
        int pc=0,qc=0;
        for(int i=0;i<n;i++){
            if(p[i]==v[i])pc++;
            if(q[i]==v[i])qc++;
        }
        if(pc==n)c1=now;
        if(qc==n)c2=now;
        now++;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(c1-c2) << endl;
}

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





Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   long long H,W;
   cin >> H >> W;
   if(H==1 || W == 1) cout << 1 << endl;
   else{
      cout << (H * W +1)/2 << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 10000

int main(void){
	
	int i, n, x;
	int FLG_CHECK_NUM = 1;
	int FLG_INCLUDE3 = 1;
	int FLG_SOMETHING_DO = 0;
	
	i = 1;
	
	scanf("%d", &n);
	
	while(i<=n){
		
		if(FLG_CHECK_NUM){
			x = i;
		}
		
		//CHECK_NUM
		if(x%3 == 0 && !FLG_SOMETHING_DO && FLG_CHECK_NUM){
			FLG_INCLUDE3 = 0;
			FLG_SOMETHING_DO = 1;
			printf(" %d", i);
		}
		
		//INCLUDE3
		if(x%10==3 && !FLG_SOMETHING_DO && FLG_INCLUDE3){
			FLG_CHECK_NUM = 0;
			FLG_SOMETHING_DO = 1;
			printf(" %d", i);
		}
		
		FLG_CHECK_NUM = 1;
		FLG_INCLUDE3 = 1;
		
		if(!FLG_SOMETHING_DO){
			x /= 10;
			if(x){
				i--;
				FLG_CHECK_NUM = 0;
			}
		}
		
		//END_CHECK_NUM
		FLG_SOMETHING_DO = 0;
		
		i++;
		
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MOD 1000000007
#define MAX 100100
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
    int x=0;bool t=false;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
int n,m,a[MAX];
struct Matrix
{
    int s[3][3];
    void clear(){memset(s,0,sizeof(s));}
    void init(){clear();for(int i=0;i<3;++i)s[i][i]=1;}
    int*operator[](int x){return s[x];}
}P[31],A,B,G;
Matrix operator*(Matrix a,Matrix b)
{
    Matrix c;c.clear();
    for(int i=0;i<3;++i)
        for(int j=0;j<3;++j)
            for(int k=0;k<3;++k)
                add(c[i][j],1ll*a[i][k]*b[k][j]%MOD);
    return c;
}
Matrix fpow(int b)
{
    Matrix s;s.init();
    for(int i=0;b;b>>=1,++i)
        if(b&1)s=s*P[i];
    return s;
}
int f[MAX][3];
int main()
{
    n=read();m=read();
    for(int i=1;i<=m;++i)a[i]=read()+1;
    /*
    f[0][0]=1;
    for(int i=1,pos=1;i<=n;++i)
    {
        if(i!=a[pos])
            for(int j=0;j<3;++j)
                add(f[i][j],((j==1)?2:1)*f[i-1][2]%MOD);
        for(int j=0;j<3;++j)
        {
            add(f[i][j],f[i-1][j]);
            if(j<2)add(f[i][j+1],(2-j)*f[i-1][j]%MOD);
            if(j<1)add(f[i][j+2],f[i-1][j]);
        }
        if(i==a[pos])++pos;
    }
    printf("%d\n",f[n][2]);
    */
    A[0][0]=1;A[0][1]=2;A[0][2]=1;
    A[1][0]=0;A[1][1]=1;A[1][2]=1;
    A[2][0]=1;A[2][1]=2;A[2][2]=2;
    B=A;
    B[2][0]=0;B[2][1]=0;B[2][2]=1;
    P[0]=A;for(int i=1;i<=30;++i)P[i]=P[i-1]*P[i-1];
    G[0][0]=1;
    for(int i=1;i<=m;++i)G=G*fpow(a[i]-a[i-1]-1)*B;
    G=G*fpow(n-a[m]);
    printf("%d\n",G[0][2]);
    return 0;
}

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

import collections

N = int(input())
S = [input() for i in range(N)]
S_count = collections.Counter(S)
S_most = S_count.most_common()
a, b = S_most[0]
ans = []

for i, j in S_most:
    if j == b:
        ans.append(i)
for i in sorted(ans):
    print(i)


Measured memory_bytes: 49204
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int size = s.size()/2;
  int hug = 0;
  for(int i=0; i<size; i++) {
    if(s.at(i) != s.at(s.size()-i-1)) {
      hug++;
    }
  }
  cout << hug << endl;
}

Measured memory_bytes: 3632
import numpy as np
import math

ABCD=np.array(input().split(" "),dtype=np.int32)

A=ABCD[0]
B=ABCD[1]
C=ABCD[2]
D=ABCD[3]

Aturn=math.ceil(A/D)
Cturn=math.ceil(C/B)

if(Aturn>=Cturn):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27128
/*
 * 	Just close your eyes
 * 		The sun is going down
 * 			You'll be alright...
 * 				No one can hurt you now
 * 					Come, morning light...
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll inf=1e18;
const int mod=1e9+7;
typedef vector<int> vi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> gra[100005];
int par[100005];
int in[100005];
void solve()
{
	int n,m,u,v;
	cin>>n>>m;
	for(int i=1; i<=n+m-1; i++) {
		cin>>u>>v;
		gra[u].pb(v);
		in[v]++;
	}
	queue<pii> cur,next;
	for(int i=1; i<=n; i++)
		if(in[i]==0)
			cur.push({0,i});
	while(!cur.empty()) {
		while(!cur.empty()) {
			pii ho=cur.front();
			cur.pop();
			par[ho.se]=ho.fi;
			for(int i:gra[ho.se])
				if(in[i]==1)
					next.push({ho.se,i});
				else in[i]--;
		}
		cur.swap(next);
	}
	for(int i=1; i<=n; i++)
		cout<<par[i]<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        scan.close();

        long sum = 0;
        for (int i = 0; i <= n; i++) {
            if (i % 3 != 0 && i % 5 != 0) {
                sum += i;
            }
        }

        System.out.println(sum);
    }

}


Measured memory_bytes: 35700
import sys
import bisect
#t=int(input())
t=1
for _ in range(t):
    #r,g,b=map(int,input().split())
    #l=list(map(int,input().split()))
    #l2=list(map(int,input().split()))
    n=int(input())
    l=list(map(int,input().split()))
    d={}
    for i in l:
        d[i]=d.get(i,0)+1
    l=list(set(l))
    l.sort()
    ans=0
    #print(d,l)
    for i in range(len(l)):
        for j in range(i+1,len(l)):
            for k in range(j+1,len(l)):
                if l[k]<l[i]+l[j]:
                    ans+=d[l[i]]*d[l[j]]*d[l[k]]
    print(ans)                

Measured memory_bytes: 67940
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(ll i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const ll N=1e5+7;
const ll INF=1e9+7;
ll n,cnt=0;
ll sz[N],w[N],X[N],Y[N],ds[N];
struct pir{ll x,d;}p[N];
bool cmp(pir a,pir b){return a.d<b.d;}

int main(){
	scanf("%lld",&n);
	rep(i,n)scanf("%lld",&p[i].d),p[i].x=i;
	sort(p+1,p+n+1,cmp);
	rep(i,n){
		w[i]=p[i].d;
		sz[i]=1;
		ds[i]=0;
	}
	for(ll i=n;i>1;i--){
		ll t=lower_bound(w+1,w+n+1,w[i]-(n-2*sz[i]))-w;
		if(w[t]!=w[i]-(n-2*sz[i])){
			puts("-1");
			return 0;
		}
		sz[t]+=sz[i];
		ds[t]=ds[t]+ds[i]+sz[i];
		X[++cnt]=p[i].x;
		Y[cnt]=p[t].x;
	}
	if(sz[1]!=n||ds[1]!=w[1]){
		puts("-1");
		return 0;
	}
	rep(i,cnt)printf("%lld %lld\n",X[i],Y[i]);
	return 0;
}


Measured memory_bytes: 6912
import sys
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LF(): return [float(x) for x in sys.stdin.readline().split()]


def LS(): return sys.stdin.readline().split()


def II(): return int(sys.stdin.readline())


def SI(): return input()


N = int(input())
X = {}
for i in range(1, N+1):
    s, p = input().split()
    if s in X:
        X[s] += [(int(p), i)]
    else:
        X[s] = [(int(p), i)]

X = sorted(X.items())
for v in X:
    a = sorted(v[1], reverse=True)
    for i in a:
        print(i[1])


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

		int n = in.nextInt();
		int a[] = new int[n + 1];
		for ( int i = 1; i <= n; i++ ) {
			a[i] = in.nextInt();
		}

		int box[] = new int[n + 1];
		int cnt = 0;

		// 自分の倍数がない場合を埋める
		int n_per2 = n / 2;
		for ( int b = n; n_per2 < b; b-- ) {
			box[b] = a[b];
			if ( a[b] == 1 ) cnt++;
		}

		// 倍数がある場合
		for ( int b = n_per2; 0 < b; b-- ) {

			// 振り返りチェックしつつ埋める
			int sum = 0;
			for ( int i = b; i <= n; i += b ) {
				sum += box[i];
			}
			if ( sum % 2 != a[b] ) {
				box[b] = 1;
				cnt++;
			}
		}

		System.out.println(cnt);
		for ( int i = 1; i <= n; i++ ) {
			if ( box[i] == 1 ) System.out.print(i + " ");
		}

		in.close();
	}
}

Measured memory_bytes: 84028
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back

#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 500000
int dirx[] = {1, -1,0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};



//=============================================ASIFAZAD==============================================//

vi seg(4*N), inp(N);

void upd(int cur, int strt, int en, int i,int v)
{
    if(strt == en)
        seg[cur] = v;
    else
    {
        int mid = (strt + en)/2;
        if(i <= mid)
            upd(2*cur, strt, mid, i, v);
        else
            upd(2*cur+1, mid+1, en, i, v);
        seg[cur] = max(seg[2*cur], seg[2*cur+1]);
    }
}

int qry(int cur, int strt, int en, int l, int r)
{
    if(en < l || strt > r)
        return INT_MIN;
    if(strt >= l && en <= r)
        return seg[cur];
    int mid = (strt + en)/2;
    return max(qry(2*cur, strt, mid, l, r), qry(2*cur + 1, mid + 1, en, l, r));
}


int32_t main()
{
    io;
    int n, k;
    cin>>n>>k;
    for(int i = 1; i<= n; i++)
        cin>>inp[i];
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int rt = qry(1, 1, 300001, inp[i] + 1, min(inp[i] + 1+ k, 300001));
        int lf = qry(1,1, 300001, max(0, inp[i] - k) + 1, inp[i] + 1);
        int ac = max(rt , lf) + 1;
        ans = max(ans, ac);
//        dbg(i);
//        dbg(ans);
        upd(1,1, 300001, inp[i] + 1, ac);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 12884
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def cal_divisors(N):
    divisors = []
    i = 1
    while i*i <= N:
        if N % i == 0:
            divisors.append(i)
            if i != N // i:
                divisors.append(N//i)
        i += 1
    divisors.sort()
    return divisors

def prime_factorize(N):
    prime_list = []
    while N % 2 == 0:
        prime_list.append(2)
        N //= 2
    f = 3
    while f**2 <= N:
        if N % f == 0:
            prime_list.append(f)
            N //= f
        else:
            f += 2
    if N != 1:
        prime_list.append(N)
    return prime_list

def main():
    N = int(input())
    divisors = []
    for i in range(1,N+1):
        divisors.extend(prime_factorize(i))
    l = Counter(divisors)
    # print(l)
    # 約数を75個持つ X = a^p * b^q とした時、(p,q) = (0,74), (2,24), (4,14) しかない
    ans = 0
    nums = l.values()
    # 74より大きい素因数の数だけ(1)のパターン
    ans += len([*filter(lambda x: x >= 74, nums)])

    # 14,4のパターン
    ans += len([*filter(lambda x: x >= 14, nums)]) * (len([*filter(lambda x: x >= 4, nums)])-1)

    # 24,2のパターン
    ans += len([*filter(lambda x: x >= 24, nums)]) * (len([*filter(lambda x: x >= 2, nums)])-1)

    # 4,4,2のパターン
    ans += len([*filter(lambda x: x >= 4, nums)]) * (len([*filter(lambda x: x >= 4, nums)])-1) * (len([*filter(lambda x: x >= 2, nums)])-2) // 2

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9464
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<tuple<int, int, int>> w(n);
    for(auto& x : w)
        cin >> get<0>(x) >> get<1>(x) >> get<2>(x);
    vector<int> d(q);
    vector<vector<int>> b(q + 10);
    vector<vector<int>> out(q + 10);
    for(auto& x : d)
        cin >> x;
    
    for(auto& x : w) {
        int j = lower_bound(begin(d), end(d), get<0>(x) - get<2>(x)) - begin(d);
        b[j].push_back(get<2>(x));
        j = lower_bound(begin(d), end(d), get<1>(x) - get<2>(x)) - begin(d);
        out[j].push_back(get<2>(x));
    }

    multiset<int> bound;
    for(int i = 0; i < q; ++i) {
        for(int j : b[i])
            bound.insert(j);
        for(int j : out[i])
            bound.erase(bound.find(j));
        
        if(bound.empty())
            cout << -1 << '\n';
        else
            cout << *bound.begin() << '\n';
    }

}

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

using namespace std;

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(args...) { string _s = #args; replace(ALL(_s), ',', ' '); stringstream ss(_s); cerr << endl;_debug(ss, args); }
#define _rg auto it = next(v.begin()); it != v.end(); it++
#define _input ostream& operator <<(ostream& out

template<typename T, typename U>
_input, const pair<T, U>& p) {
	out << "(" << p.first << ", " << p.second << ")";
	return out;
}

#define cont(c) template<typename T> _input, const c<T>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}
				
#define cont2(c) template<typename T, typename U> _input, const c<T, U>& v) { \
					if (v.empty()) return out; \
					out << "[" << *v.begin(); \
					for (_rg) out << ", " << *it; \
					out << "]"; return out; \
				}

cont(vector) cont(set) cont(multiset) cont(queue) cont2(map)

template<typename T, size_t n, typename= enable_if_t<!is_same<T, char>::value>>
_input, const T(&v)[n]) {
	if (n == 0) return out;
	out << "[" << v[0];
	for (int i = 1; i < (int)n; i++) out << ", " << v[i];
	out  << "]"; return out;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T &arg) {
	string name; ss >> name;
	cerr << name << " = " << arg << endl;
}

template<typename T, typename... Ts>
void _debug(stringstream& ss, const T& arg, const Ts&... args) {
	string name; ss >> name; 
	cerr << name << " = " << arg << ", ";
	if (is_class<T>::value || is_array<T>::value) cerr << endl;
	_debug(ss, args...);
}

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int32_t main() {
	FAST_IO;

	int a;
	string b;
	cin >> a >> b;
	
	string s = "";
	int cnt = 0;
	for (int i = 0; i < (int)b.size(); i++)
		if (b[i] != '.') {
			s += b[i];
		} else {
			cnt = (int)b.size()-i-1;
		}
	
	int bb = stoi(s);
	
	int ans = a*bb;
	
	int p = 1;
	while (cnt-->0) p *= 10;
	
	cout << ans/p << endl;
	
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AtCoder_Project_CSharp
{
    class Program
    {

        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a1 = a[0], a2 = a[1], a3 = a[2];
            var ansList = new List<int>();
            ansList.Add(Math.Abs(a1 - a2) + Math.Abs(a2 - a3));
            ansList.Add( Math.Abs(a1 - a3) + Math.Abs(a2 - a3));
            ansList.Add(Math.Abs(a1 - a2) + Math.Abs(a1 - a3));
            ansList.Add(Math.Abs(a3 - a2) + Math.Abs(a1 - a3));
            ansList.Add(Math.Abs(a3 - a1) + Math.Abs(a2 - a1));
            ansList.Add(Math.Abs(a3 - a2) + Math.Abs(a2 - a1));
            
            Console.WriteLine(ansList.Min());
        }
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int p[] = new int[n];
		for(int i = 0; i < n; i++){
			p[i] = scan.nextInt();
		}
		int ans = 0;
		int min = n + 1;
		
		for(int i = 0; i < n; i++){
			if(min > p[i]){
				min = p[i];
				ans++;
			}
				
		}	
		System.out.println(ans);
	}
}

Measured memory_bytes: 66412
import java.util.*;

class Main{
    public static int gcd(int m,int n){
        int r;
        while(n>0){
            r=m%n;
            m=n;
            n=r;
        }
        return m;
    }
    
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int w,h,c;
        w=sc.nextInt();
        h=sc.nextInt();
        c=sc.nextInt();
        int r=gcd(w,h);
        System.out.println((w/r)*(h/r)*c);
    }
}


Measured memory_bytes: 26136
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
typedef pair<int,pair<int,int>> P;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m,a,b;
	//int r[1002][1002]={};
	int s[2002]={},g[2002]={},c[2002]={};
	long p[1111]={},f=0;
	cin>>n>>m;
	//FOR(i,0,n+1)FOR(j,0,n+1)r[i][j]=-mod;
	P pr[2002]={};
	FOR(i,0,m){
		int ss,gg,cc;
		cin>>ss>>gg>>cc;
		pr[i]=P(ss,make_pair(gg,cc));
		//cin>>c[i];
	}
	sort(pr,pr+m);
	FOR(i,0,m){
		s[i]=pr[i].ST;
		g[i]=pr[i].ND.ST;
		c[i]=pr[i].ND.ND;
	}
	FOR(i,2,n+1){
		p[i]=-1*(1L<<55);
	}
	p[1]=0;
	long now=1,bf[1111]={};
	int idx=0;
	while(1){
		FORQ(i,n,n)bf[i]=p[i];
		idx++;
		//bf[now]=1;
		//cout<<now<<"now:"<<p[now]<<endl;
		FOR(i,0,m){
			//if(s[i]!=now)continue;
			long val=p[s[i]]+c[i];
			if(p[g[i]]<val){
				p[g[i]]=val;
				//cout<<j<<"p:"<<p[j]<<endl;
			}
		}
		/*
		long max=-mod*2000L;
		FOR(i,1,n+1){
			if(bf[i]==1)continue;
			//cout<<" "<<i<<":"<<p[i]<<" ";
			if(p[i]>max){
				now=i;
				max=p[i];
			}
		}//*/
		//FOR(i,1,n+1)cout<<bf[i]<<" "<<endl;
		int fll=0;
		if(idx<n)fll=1;
		if(bf[n]!=p[n]){
			fll=1;
		}
		if(idx==n+5||fll==0)break;
	}
	if(idx==n+5)cout<<"inf"<<endl;
	else cout<<p[n]<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]
hmax = h[0]
count = 0
for i in range(1,n):
    if hmax-1 <= h[i]:
        count += 1
        hmax = max(hmax,h[i])
    else:
        break
if n-1 == count:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14396
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int sum = 0;
    for (int i = 0; i < m; i++) {
      sum += scanner.nextInt();
    }
    if(sum > n) {
      System.out.println(-1);
    } else {
      System.out.println(n - sum);
    }
  }
}


Measured memory_bytes: 38936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int32_t main(){


	FASTIO;
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vi A(a),B(b),C(c);
	FOR(i,a){
		cin >> A[i];
	}
	FOR(i,b){
		cin >> B[i];
	}
	FOR(i,c){
		cin >> C[i];
	}
	vi res;
	sort(all(A),greater<int>() );
	sort(all(B),greater<int>() );
	FOR(i,x){
		res.pb(A[i]);
	}
	FOR(i,y){
		res.pb(B[i]);
	}
	FOR(i,c){res.pb(C[i]);};
	sort(all(res),greater<int>() );
	int del = 0;
	FOR(i,x+y){
		del += res[i];
	}
	cout << del << endl;
    return 0;

}

Measured memory_bytes: 8048
#include<stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b && b < c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
	return (0);
}

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

const int N = 200005;

ll n, k;
ll arr[N];

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> arr[i];
    for(int i = 1; i < n; i++) arr[i] += arr[i-1];
    for(int i = 0; i < n; i++) arr[i] -= (i+1)*k;
}

vector<int> tmp;
ll dc(int l, int r)
{
    if(l == r) return (arr[l] >= 0? 1 : 0);
    int mid = (l+r)/2;
    ll res = dc(l, mid) + dc(mid+1, r);
    tmp.clear();
    int i = l, j = mid+1;
    while(i <= mid && j <= r)
    {
        if(arr[i] <= arr[j]) res += r-j+1, tmp.push_back(arr[i++]);
        else tmp.push_back(arr[j++]);
    }
    while(i <= mid) tmp.push_back(arr[i++]);
    while(j <= r) tmp.push_back(arr[j++]);
    for(i = l, j = 0; i <= r; i++, j++) arr[i] = tmp[j];
    return res;
}

void process()
{
    cout << dc(0, n-1) << endl;
}



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

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

    set<string> st;
    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        st.insert(str);
    }

    cout << st.size() << endl;
}

Measured memory_bytes: 19124
#include<bits/stdc++.h>
#define ll long long
using namespace std;
double dp[305][305][305];
double cal(ll a,ll b,ll c,ll n){

    if(a<0||b<0||c<0)
        return 0;
    if(a==0&&b==0&&c==0)
        return 0;
    if(dp[a][b][c])
        return dp[a][b][c];

    dp[a][b][c]=n+a*cal(a-1,b,c,n)+b*cal(a+1,b-1,c,n)+c*cal(a,b+1,c-1,n);
    dp[a][b][c]/=(a+b+c)*1.0;

    return dp[a][b][c];
}
int main(){
    ll n;
    cin>>n;
    ll zero=0,one=0,two=0,three=0;
    int a[n];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==1)one++;
        else if(a[i]==2)two++;
        else three++;
    }
    double ans=cal(one,two,three,n);
    cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 221952