akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#define f cin
#define NMAX 3010
using namespace std;

//ifstream f("date.in");

string s, t;
int n, m;
int dp[NMAX][NMAX];
int next_elem_x[NMAX][NMAX];
int next_elem_y[NMAX][NMAX];

// vector<int> ans;

int main() {

    f >> s >> t;
    n = s.size();
    m = t.size();

    /*for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            next_elem_x[i][j] = -1;
            next_elem_y[i][j] = -1;
        }
    }*/

    for (int i = 0; i < n; ++i) {
        if (s[i] == t[0]) {
            dp[i][0] = 1;
            next_elem_x[i][0] = i;
            next_elem_y[i][0] = 0;
        } else {
            if (i != 0) {
                dp[i][0] = dp[i - 1][0];
                next_elem_x[i][0] = next_elem_x[i - 1][0];
                next_elem_y[i][0] = next_elem_y[i - 1][0];
            }
        }
    }

    for (int i = 0; i < m; ++i) {
        if (t[i] == s[0]) {
            dp[0][i] = 1;
            next_elem_x[0][i] = 0;
            next_elem_y[0][i] = i;
        } else {
            if (i != 0) {
                dp[0][i] = dp[0][i - 1];
                next_elem_x[0][i] = next_elem_x[0][i - 1];
                next_elem_y[0][i] = next_elem_y[0][i - 1];
            }
        }
    }

    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < m; ++j) {
            if (dp[i - 1][j] > dp[i][j - 1]) {
                dp[i][j] = dp[i - 1][j];
                next_elem_x[i][j] = next_elem_x[i - 1][j];
                next_elem_y[i][j] = next_elem_y[i - 1][j];
            } else {
                dp[i][j] = dp[i][j - 1];
                next_elem_x[i][j] = next_elem_x[i][j - 1];
                next_elem_y[i][j] = next_elem_y[i][j - 1];
            }
            if (s[i] == t[j]) {
                if (dp[i - 1][j - 1] + 1 > dp[i][j]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    next_elem_x[i][j] = i;
                    next_elem_y[i][j] = j;
                }
            }
        }
    }

    int pos_x = next_elem_x[n - 1][m - 1];
    int pos_y = next_elem_y[n - 1][m - 1];
    char ans[3030];
    int cnt = 0;
    while (pos_x >= 0 && pos_y >= 0) {
        if (s[pos_x] == t[pos_y]) {
            ans[cnt] = s[pos_x];
            cnt ++;
        }
        pos_x --;
        pos_y --;
        if (pos_x >= 0 && pos_y >= 0) {
            pos_x = next_elem_x[pos_x][pos_y];
            pos_y = next_elem_y[pos_x][pos_y];
        }
    }

    for (int i = cnt - 1; i >= 0; --i) {
        cout << ans[i];
    }

    return 0;
}


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

void solve() {
	string s; long long k;
	cin >> s >> k;

	long long res = 1;
	rep(i, min((long long)s.size(), k)) {
		if (s[i] != '1') {
			res = s[i] - '0';
			break;
		}
	}

	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 

ll f(ll x) {
    ll res = 0;
    
    FOR(i,1,50) {
        const ll P = 1LL << i;
        ll cnt = ((x+1) / P)*(P / 2) + max(0LL, ((x+1)%P) - (P/2));
        
        if (cnt%2 == 1) {
            res += 1LL << (i - 1);
        }
    }

    return res;
}

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

    ll A, B; cin >> A >> B;

    ll ans = f(B) ^ f(A - 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")


def solve(k, s):
    if len(s) <= k:
        return s
    return s[:k] + "..."


if __name__ == "__main__":
    k = int_in()
    s = str_in()
    out(solve(k, s))

Measured memory_bytes: 61792
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
//    cout << setprecision(30);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    pair<pair<string, int>, int> a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i].first.first >> a[i].first.second;
        a[i].first.second = -a[i].first.second;
        a[i].second = i + 1;
    }


    sort(a,a + n);
    for (auto e : a) {
        cout << e.second << '\n';
    }




}


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

using namespace std;

const int N=21,M=2100000;

typedef long long LL;

int n,K,s[N][M],f[N][M],fi[N][M][2],Out[N],two[N],h[N];

char S[N][M];

void Write(int x,int l)
{
	for (int i=l;i;i--,x>>=1) Out[i]=x&1;
	for (int i=1;i<=l;i++) printf("%d",Out[i]);
	exit(0);
}

int main()
{
	scanf("%d%d",&n,&K);
	for (int i=0;i<=n;i++) two[i]=1<<i;
	for (int i=1;i<=n;i++) h[i]=two[i]-1; h[0]=0;
	for (int i=0;i<=n;i++)
	{
		scanf("%s",S[i]);
		for (int j=0;j<two[i];j++) f[i][j]=S[i][j]-'0';
	}
	memset(fi,255,sizeof(fi));
	for (int l=1;l<=n;l++) for (int i=0;i<two[l];i++)
	{
		for (int j=0;j<l;j++) if (two[j]&i) fi[l][i][1]=j;else fi[l][i][0]=j;
	}
	for (int j=n;j;j--) for (int i=0;i<two[j];i++)
	{
		for (int l=0;l<=n-j;l++) for (int k=0;k<two[l];k++)
		{
			int st=i^(k+h[l]<<j),t1,t2;
			if (!f[j][st]) continue;
			if (fi[j][i][0]>=0)
			{
				t1=fi[j][i][0];
				t2=(i&two[fi[j][i][0]]-1)^((k<<1)+h[l+1]<<fi[j][i][0]);
				f[t1][t2]+=f[j][st];
			}
			if (fi[j][i][1]>=0)
			{
				t1=fi[j][i][1];
				t2=(i&two[fi[j][i][1]]-1)^((k<<1|1)+h[l+1]<<fi[j][i][1]);
				f[t1][t2]+=f[j][st];
			}
		}
	}
	for (int j=n;j>=0;j--)
	{
		for (int i=0;i<two[j];i++)
		{
			for (int l=0;l<=n-j;l++) for (int k=0;k<two[l];k++)
			{
				int st=i^(k+h[l]<<j);
				s[l][k]+=f[j][st];
			}
		}
	}
	for (int l=n;l;l--) for (int i=0;i<two[l];i++) if (s[l][i]>=K) Write(i,l);
	return 0;
}

Measured memory_bytes: 604544
#include<stdio.h>

typedef struct{
  char m;
  int n;
} Card;

int main(){
  Card A[100],B[100],tmp;
  int i,j,n,mini,c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf(" %c%d",&A[i].m,&A[i].n);
  for(i=0;i<n;i++)B[i]=A[i];

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j].n<A[j-1].n){
        tmp=A[j];
        A[j]=A[j-1];
        A[j-1]=tmp;
      }
    }
  }
  for(i=0;i<n-1;i++) printf("%c%d ",A[i].m,A[i].n);
  printf("%c%d\n",A[n-1].m,A[n-1].n);
  printf("Stable\n");

   for(i=0;i<n-1;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(B[j].n<B[mini].n) mini=j;
    }
    tmp=B[i];
    B[i]=B[mini];
    B[mini]=tmp;
  }

   for(i=0;i<n-1;i++) printf("%c%d ",B[i].m,B[i].n);
   printf("%c%d\n",B[n-1].m,B[n-1].n);

   for(i=0;i<n;i++){
     if(A[i].m!=B[i].m){
       printf("Not stable\n");
       return 0;
     }
   }
   printf("Stable\n");

   return 0;
}



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

using namespace std;

const int N = 1000100;

long long v[N], qtd[N];
long long acc[N];
vector <long long> s;

int get(int l, int r, long long val) {
	while (l < r) {
		int m = (l+r+1)/2;
		if (s[m] <= val) l = m;
		else r = m-1;
	}
	return r;
}

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int nn = n;

	for (int i = 0; i < m; ++i) {
		scanf("%lld", &v[i]);
	}

	stack <long long> q;
	q.push(n);
	for (int i = 0; i < m; ++i) {
		while(!q.empty() && v[i] <= q.top())q.pop();
		q.push(v[i]);
	}


	while(!q.empty()){
		s.push_back(q.top());
		q.pop();
	}
	reverse(s.begin(), s.end());

	n = (int)s.size();
	qtd[n-1] = 1;
	for (int i = n - 1; i >= 0; --i) {
		long long at = s[i];
		while(at > s[0]) {
				int nxt = get(0, i-1, at);
				qtd[nxt] += qtd[i] * (at/s[nxt]);
				at%=s[nxt];
		}
		//printf("wtf %lld\n", at);
		acc[at]+=qtd[i];
	}


	for (int i = s[0]; i > 0; i--){
		acc[i-1] += acc[i];
	}
	for (int i = 1; i <= nn; i++) {
		printf("%lld\n", acc[i]);
	}



}

Measured memory_bytes: 12336
import os, sys, re, math

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

L = 1
R = N

for _ in range(M):
	l,r = list(map(int,input().split(' ')))
	L = max(L,l)
	R = min(R,r)

ret = max(0, R-L+1)
print(ret)

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (k) {
            k--;
            continue;
        }
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define rep1(i,n) for(int i=1;i<=((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef long long ll;

const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;

		b>>=1;
	}
	return res;
}
void exgcd(int a,int b,int &x,int &y,int &d)
{
    if (b==0) x=0,y=1,d=a;
    else exgcd(b,a%b,y,x,d),y-=(a/b)*x;
}
int n;
int main()
{
    //IOS;
    int a,b,t;
    while(cin>>a>>b>>t)
    {
        cout<<(t/a)*b<<"\n";
    }
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define mul(n) n<<1 //multiply by 2;
#define di(n) n>>1 //division by 2;
#define powof2(n) 1<<n //finding power of 2
#define ans(n) (n&(n-1)==0) //check if number is power of 2;
#define statusofxbit(n,x) (n&(1<<x-1)==0) //get the status of xth bit from the right;
#define setthexthbit(n,x) n|(1<<x-1)
#define togglexthbit(n,x) n^(1<<x-1)
#define equalno(a,b) if(a^b==0) cout<<1<<endl; else cout<<0<<endl;
#define xortwotogetthird c=a^b
#define resettherightmostsetbit(n) n&(n-1)
#define Bitlength(n) len=0; while(n){len+=1;n>>=1;};
#define noofsetbits(n) __builtin_popcount(n);
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int flag=0;
        while (1) {
            c-=b;
            if(c<=0){
                flag=1;
                break;
            }
            a-=d;
            if(a<=0){
                break;
            }
        }
        if(!flag){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n, k;
    cin >> n >> k;
    vi a,b;
    rep(i,n){
        int t;
        cin >> t;
        if(t < 0)a.push_back(-t);
        else b.push_back(t);
    }
    reverse(all(a));
    int ans = INF;
    rep(i,k+1){
        j = k-i;
        if(i <= a.size() && j <= b.size()){
            int t1 = 0, t2 = 0;
            if(i) t1 += a[i-1];
            if(j) t2 += b[j-1];
            ans = min(ans, t1+t2+min(t1,t2));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1020
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=scan.nextInt();
		int e[]=new int[a];
		int f[]=new int[b];
		for(int i=0;i!=a;i++) {
			e[i]=scan.nextInt();
		}
		for(int i=0;i!=b;i++) {
			f[i]=scan.nextInt();
		}
		int count1=0,count2=0,ans=0;
		for(int i=c+1;i!=d+1;i++) {
			count1=0;count2=0;
			for(int j=0;j!=a+1;j++) {
				if(j==a) {
					count1++;
					break;
				}
				if(i<=e[j]) {
					break;
				}
			}for(int j=0;j!=b+1;j++) {
				if(j==b) {
					count2++;
					break;
				}

				if(i>f[j] ) {
					break;
				}
			}
			if(count1==1&&count2==1) {
				ans++;
				break;
			}
		}
		if(ans==1) {
			System.out.println("No War");
		}
		else {
			System.out.println("War");
		}
	}
}

Measured memory_bytes: 23764
N = int(input())
a_list = [int(e) for e in input().split()]
a_list.sort(reverse=True)
a_list = [0] + a_list 
ans_list= list()

for i in range(1,len(a_list)):
    if i%2 == 0:
        ans_list.append(a_list[i])
        if len(ans_list) == N:
            print(sum(ans_list))
            break

Measured memory_bytes: 42672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;



int main() {
	long long int A, B;
	long long int C, D, X;
	cin >> A >> B >> C >> D;
	
	long long int A1 = 0, A2 = 0, B1 = 0, B2 = 0, C1 = 0, C2 = 0;
	long long int i, a, b;
	if (C > D) {
		a = C;
		b = D;
	}
	else {
		a = D;
		b = C;
	}
	A1 = (A - 1) / C;
	A2 = B / C;
	B1 = (A - 1) / D;
	B2 = B / D;
	while ((i = a % b) != 0) {
		a = b;
		b = i;
	}
	X = C * D / b;
	C1 = (A - 1) / X;
	C1 = A1 + B1 - C1;
	C1 = (A - 1) - C1;
	C2 = B / X;
	C2 = A2 + B2 - C2;
	C2 = B - C2;
	cout << C2 - C1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
string S;
ll res, t;

int main() {
	cin >> N >> S;
	res = 1;
	for (int i = 0; i < N + N; ++i) {
		if (S[i] == 'B') {
			if (t % 2) {
				res *= t;
				--t;
			}
			else {
				++t;
			}
		}
		else {
			if (t % 2) {
				++t;
			}
			else {
				res *= t;
				--t;
			}
		}
		res %= mod;
		if (t < 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	if (t) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1; i <= N; ++i) {
		res *= i;
		res %= mod;
	}
	cout << res << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static int n;
	public static int[] S;
	public static int q;
	public static int[] T;

	public static void main(String[] args) {

		int t = 0;
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		S = new int[n];
		for (int i = 0; i < n; i++) {
			S[i] = sc.nextInt();
		}
		q = sc.nextInt();
		T = new int[q];
		for (int i = 0; i < q; i++) {
			T[i] = sc.nextInt();
		}

		for (int i = 0; i < q; i++) {
			if (binarySearch(T[i])) {
				t++;
			}
		}
		System.out.println(t);
	}

	public static boolean binarySearch(int x) {
		int l = 0;
		int r = n - 1;
		while (true) {
			if (l < r) {
				int m = (l + r) / 2;
				if (S[m] < x) {
					l = m + 1;
				} else {
					r = m;
				}
			} else {
				break;
			}
		}
		if (S[l] == x) {
			return true;
		} else {
			return false;
		}
	}

}


Measured memory_bytes: 68896
#include<stdio.h>
#define NIL -1

typedef struct{
  int parent,left,right;
}tree;

void data_print(tree *,int );
int depth(tree *,int );

int sibling(tree *,int);
int degree(tree *,int);
int height(tree *,int);

int main(){
  tree inf[100001];
  int n,id,pick,num,a,r;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    inf[i].parent=NIL;
    inf[i].left=NIL;
    inf[i].right=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d",&id);

      scanf("%d",&pick);
      if(pick!=NIL){
        inf[id].left=pick;
        inf[pick].parent=id;
    }
      scanf("%d",&pick);
      if(pick!=NIL){
        inf[id].right=pick;
        inf[pick].parent=id;
      }
}

  for(i=0;i<n;i++)data_print(inf,i);

  return 0;
}

void data_print(tree *inf,int i){

  int temp;

  printf("node %d: ",i);

  printf("parent = %d, ",inf[i].parent);

  printf("sibling = %d, ",sibling(inf,i));

  printf("degree = %d, ",degree(inf,i));

  printf("depth = %d, ",depth(inf,i));

  printf("height = %d, ",height(inf,i));

  if(inf[i].parent==NIL)printf("root");

  else if(inf[i].left==NIL && inf[i].right==NIL)printf("leaf");

  else if(inf[i].left!=NIL || inf[i].right!=NIL)printf("internal node");

  printf("\n");
}

int depth(tree *inf,int num){
  int cnt=0,temp;

  while(inf[num].parent!=NIL){
    cnt++;
    temp=inf[num].parent;
    num=temp;
  }
  return cnt;
}

int sibling(tree *inf ,int num){
  int temp;

  if(inf[num].parent==NIL)return -1;
  else temp=inf[num].parent;

  if(inf[temp].left!=NIL && inf[temp].left!=num)return inf[temp].left;
  else if(inf[temp].right!=NIL && inf[temp].right!=num)return inf[temp].right;
else return -1;
}

int degree(tree *inf,int num){
  int c=0;
  if(inf[num].left!=NIL)c++;
  if(inf[num].right!=NIL)c++;
  return c;
}

int height(tree *inf,int num){
  int lef=0,rig=0;

  if(inf[num].left==NIL && inf[num].right==NIL)return 0;

  if(inf[num].left!=NIL)lef=height(inf,inf[num].left)+1;
  if(inf[num].right!=NIL)rig=height(inf,inf[num].right)+1;

  if(lef>rig)return lef;
  else return rig;
}



Measured memory_bytes: 2148
// dp[i]=min cost occured to reach ith position


#include<bits/stdc++.h>

using namespace std;

int main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    int n;
    cin>>n;
    vector<vector<int>> dp(n, vector<int>(3));
    vector<int> points(3);
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>points[j];
        }
        for(int k=0;k<3;k++){
            // will make dp[i][k]
            dp[i][k]=0;
            for(int j=0;j<3;j++){
                if(j==k){
                    continue;
                }
                if((i-1)>=0){
                    dp[i][k]=max(dp[i-1][j], dp[i][k]);
                }
            }
            dp[i][k]+=points[k];
        }
    }

    int ans=0;
    for(int i=0;i<3;i++){
        ans=max(dp[n-1][i], ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8780
def solve():
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    ab = [tuple(map(int, f_i.readline().split())) for i in range(M)]
    ab.sort()
    
    ans = 1
    t = N
    for a, b in ab:
        if a >= t:
            ans += 1
            t = N
        t = min(t, b)
    
    print(ans)

solve()

Measured memory_bytes: 17024
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card
{
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right)
{
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++)
    {
      if(L[i].value<=R[j].value)
	{
	  A[k]=L[i++];
	}
      else
	{
	  A[k]=R[j++];
	}
    }
}

void mergeSort(struct Card A[],int n,int left,int right)
{
  int mid;
  if(left + 1<right)
    {
      mid = (left + right)/2;
      mergeSort(A,n,left,mid);
      mergeSort(A,n,mid,right);
      merge(A,n,left,mid,right);
    }
}

int partition(struct Card A[],int n,int p,int r)
{
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j].value<=x.value)
	{
	  i++;
	  t=A[i];
	  A[i]=A[j];
	  A[j]=t;
	}
    }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r)
{
  int q;
  if(p<r)
    {
      q=partition(A,n,p,r);
      quickSort(A,n,p,q-1);
      quickSort(A,n,q+1,r);
    }
}

int main()
{
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%s %d",S,&v);
      A[i].suit=B[i].suit=S[0];
      A[i].value=B[i].value=v;
    }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);
  for(i=0;i<n;i++)
    {
      if(A[i].suit!=B[i].suit)stable=0; 
    }
  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++)
    {
      printf("%c %d\n",B[i].suit,B[i].value);
    }
  return 0;
}



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

int main()
{
	int N;
	double D, X, Y;
	int n=0;

	cin >> N >> D;

	for (int i = 0; i < N; i++)
	{
		cin >> X >> Y;
		if (X * X + Y * Y <= D * D)
		{
			n++;
		}
	}
	cout << n;
}

Measured memory_bytes: 3784
nums = list(map(int, input().split()))
N, K = nums[0], nums[1]
S = input()

first_one = S[0] == '1'
cnts = []
cnt = 1
for i, e in enumerate(S):
    if i == 0:
        pass
    else:
        if e != S[i-1]:
            cnts.append(cnt)
            cnt = 1
        else:
            cnt += 1
cnts.append(cnt)


zero_obj = []
for i, c in enumerate(cnts):
    if first_one:
        if i % 2 == 1:
            left = 0
            if i - 1 >= 0:
                left = cnts[i-1]
            right = 0
            if i + 1 < len(cnts):
                right = cnts[i+1]
            zero_obj.append((left, c, right))
    else:
        if i % 2 == 0:
            left = 0
            if i - 1 >= 0:
                left = cnts[i-1]
            right = 0
            if i + 1 < len(cnts):
                right = cnts[i+1]
            zero_obj.append((left, c, right))

if len(zero_obj) <= K:
    print(len(S))
else:
    m = -1
    tmp = zero_obj[0][0]
    for i in range(K):
        tmp += zero_obj[i][1] + zero_obj[i][2]
    m = tmp
    for i in range(len(zero_obj) - K):
        tmp -= zero_obj[i][0] + zero_obj[i][1]
        tmp += zero_obj[i+K][1] + zero_obj[i+K][2]
        if tmp > m:
            m = tmp
    print(m)


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

int main()
{
    int h, w, m[151][151];
    for( int i = 1; i < 151; i++ )
        for( int j = 1; j < 151; j++ )
            m[i][j] = i * i + j * j;

    while( cin >> h >> w )
    {
        if( h + w == 0 )
            break;

        int a = h * h + w * w;
        int mh = 150, mw = 150, min = m[150][150] - a;
        bool judge = false;

        for( int i = 1; i < 151; i++ )
            for( int j = i + 1; j < 151; j++ )
            {
                if( i == h && j == w )
                    continue;
                
                if( a < m[i][j] )
                {
                    int diff = m[i][j] - a;
                    if( min > diff )
                    {
                        min = diff;
                        mh = i;
                        mw = j;
                    }
                    else if( min == diff && i < mh )
                    {
                        mh = i;
                        mw = j;
                    }
                    else;
                }
                else if( a == m[i][j] && h < i )
                    if( !judge || i < mh )
                    {
                        mh = i;
                        mw = j;
                        min = 0;
                        judge = 1;
                    }
                else;
            }
        cout << mh << " " << mw << endl;
    }

    return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll n;
	cin>>n;
	ll ma=-1,mi=1001,ans;
	for(int i=0;i<n;i++){
		cin>>ans;
		ma=max(ma,ans);
		mi=min(mi,ans);
	}
	cout << ma-mi<<endl;
	return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

const int n = 3;

struct Puzzle {
	int f[n*n];
	int space;
	string path;

	bool operator < (const Puzzle &p)const {
		for (int i = 0; i < n*n; i++) {
			if (f[i] == p.f[i])continue;
			return f[i] > p.f[i];
		}
		return false;
	};
};

bool istarget(Puzzle p) {
	for (int i = 0; i < n*n; i++) {
		if (p.f[i] != (i + 1))return false;
	}
	return true;
}

string bfs(Puzzle s) {
	queue<Puzzle> q;
	map<Puzzle, bool> V;
	Puzzle u, v;
	s.path = "";
	q.push(s);
	V[s] = true;

	while (!q.empty()) {
		u = q.front();
		q.pop();
		if (istarget(u))return u.path;
		int sx = u.space / n;
		int sy = u.space % n;
		for (int r = 0; r < 4; r++) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= n || ty >= n)continue;
			v = u;
			swap(v.f[u.space], v.f[tx*n + ty]);
			v.space = tx*n + ty;
			if (!V[v]) {
				V[v] = true;
				v.path += dir[r];
				q.push(v);
			}
		}
	}
	return "unsolvable";
}

int main() {
	Puzzle in;

	for (int i = 0; i < n*n; i++) {
		cin >> in.f[i];
		if (in.f[i] == 0) {
			in.f[i] = n*n;
			in.space = i;
		}
	}
	string ans = bfs(in);
	cout << ans.size() << endl;
}


Measured memory_bytes: 30584
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;


int main(){
    ll N;
    ll K;
    cin>>N;
    cin>>K;
    
    ll town[N+1];
    ll point[N+1];
    
    ll num=0;
    
    for(ll i=1;i<N+1;++i){
        cin>>town[i];
    }
    
    for(ll i=0;i<N+1;++i){
        point[i]=-1;
    }
    ll a=1;
    ll tmp=0;
    point[a]=0;
    
    while(true){
        a=town[a];
        ++num;
        //cout<<"a:"<<a<<endl;
        if(point[a]==-1){
            point[a]=num;
        }else{
            tmp=num-point[a];
            break;
        }
        
        
        
      //  cout<<num<<endl;
    }
    
    /*
    rep(i,N+1){
        cout<<point[i]<<" ";
    }
    
    cout<<endl;
    
    cout<<"tmp:"<<tmp<<endl;
    cout<<"point[a]:"<<point[a]<<endl;
    */
    ll ans=0;
    
    if(K<=point[a]){
        for(ll i=1;i<N+1;++i){
            if(point[i]==K){
                ans=i;
            }
        }
    }else{
        ll b=(K-point[a])%tmp;
        b+=point[a];
        // cout<<"b:"<<b<<endl;
        for(ll i=1;i<N+1;++i){
            if(point[i]==b){
                ans=i;
            }
        }
        
    }
    cout<<ans<<endl;
    
    
    
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

const int maxN = 1000010;
const int maxM = 30010;
const int inf = 1000000009;
const ll INF = 1e16+9;

ll a[20];
ll n;
ll minv = INF;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=5;i++)
	{
		scanf("%lld",&a[i]);
		minv = min(a[i],minv);
	}
	ll ans = 0;
	if(n<= minv)
	{
		ans = 5;
	}
	else
	{
		ll t = n/minv-(n%minv==0);
		ans = t+5;
	}
	cout<<ans<<endl;
	
    return 0;
}

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

int main() {
	int n;
	vector<int> ans;
	cin>>n;
	while(n--) {
		int a;
		cin>>a;
		auto fd = lower_bound(ans.rbegin(), ans.rend(), a);
		if (ans.size() == 0 || fd == ans.rbegin())
			ans.push_back(a);
		else
			*prev(fd) = a;
	}
	cout<<ans.size()<<endl;
	return 0;
}

Measured memory_bytes: 892
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
cnt = 0
for v in C.values():
  cnt += v*(v-1)//2
for a in A:
  q = C[a]
  ans = cnt - q*(q-1)//2 + (q-1)*(q-2)//2
  print(ans)

Measured memory_bytes: 25888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+') cout << a + b << endl;
    else cout << a - b << endl;
}

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

int main() {
  ll N, K;
  cin >> N >> K;

  ll x = N % K;
  ll mi = x;
  while(true) {
    x = abs(x-K);
    if (x >= mi) {cout << mi << endl; return 0;}
    mi = x;
  }

  return 0;
}


Measured memory_bytes: 256
<?php

$table = new SplFixedArray(100000);
$table[0] = 0;
$table[1] = 0;
for ($i = 2; $i < 100000; $i++) {
    if ($table[$i] === -1) {
        $table[$i] = $table[$i - 1];
        continue;
    }
    $table[$i] = $i;
    for ($j = $i * 2; $j < 100000; $j += $i) {
        $table[$j] = -1;
    }
}
$bigger = new SplFixedArray(100000);
$p = $table[99999] + 1;
for ($i = 99998; $i > 0; $i--) {
    if ($table[$i] < $table[$i + 1]) {
        $p = $table[$i + 1];
    }
    $bigger[$i] = $p;
}

while (true) {
    fscanf(STDIN, '%d', $n);
    if (feof(STDIN)) {
        break;
    }
    echo sprintf('%d %d', $table[$n - 1], $bigger[$n]);
    echo PHP_EOL;
}

Measured memory_bytes: 12292
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

w,h,x,y = na()
a = 1 if w/2 == x and h/2 == y else 0

print(w*h/2,a)



Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>

int main() {
    int r, g, b;
    scanf("%d%d%d", &r, &g, &b);
    if ((r * 100 + g * 10 + b) % 4 == 0) {
        puts("YES");
    }
    else {
        puts("NO");
    }
}

Measured memory_bytes: 256
n = int(input())

s=[]
for i in range(n):
    list.append(s,int(input()))

ct = 0
m_ini=0 
while max(s)>0:
    m_ini = max(s)
    for i in range(n):
        if s[i]== m_ini:
            s[i]=0
        else:
            pass
    ct = ct+1
print(ct)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main(void) {

    ll N, M; cin >> N >> M;
    ll h[N+1];
    for (int i = 1; i <= N; ++i) cin >> h[i];
    ll a[M], b[M];
    rep(i,M) cin >> a[i] >> b[i];

    bool is_good[N+1];
    rep(i,N+1) is_good[i] = true;
    rep(i,M) {
        if (h[a[i]] <= h[b[i]]) {
            is_good[a[i]] = false;
        }
        if (h[a[i]] >= h[b[i]]) {
            is_good[b[i]] = false;
        }
    }

    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (is_good[i]) {
            ++ans;
        }
    }
    out(ans);

    
    
    return 0;
}











Measured memory_bytes: 6076
z = [int(input()) for i in range(4)]
count = 0

for i in range(z[0]+1):
  for j in range(z[1]+1):
    for k in range(z[2]+1):
      if 500*i + 100*j + 50*k == z[3]:
        count += 1
        
print(count)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0057
"""
import sys


Area_memo = [0 for _ in range(10002)]         #  n??¬???????????????????????????????????° (0???????¨????)
Area_memo[0] = 1
def count_area(num):
    """
    ????????°??¨???????????°?????¢????????\????????????????????£????????????
    0 -> 1
    1 -> 2
    2 -> 4
    3 -> 7
    4 -> 11
    ?????£??????i??¬???????????????????????????????????°??????(i-1)??¬????????????????????° + ????????° ??¨?????????
    n?????°????????§??§10,000????????§????????¢???????????????????????????
    ??? ?????????????????¨???n?????§????????¨?????°????????????????????°????¢???????????????¨???????????????
    :param num:????????°
    :return: ???????????°
    """
    global Area_memo
    if Area_memo[num] == 0:
        Area_memo[num] = num + count_area(num-1)
    return Area_memo[num]


def count_area2(num):
    wa = num * (1 + num) // 2
    return wa + 1



def main(args):
    for line in sys.stdin:
        num = int(line.strip())
        result = count_area2(num)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7796
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a;i>b;i--)
#define mkp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
using namespace std;
bool compare(pair<int,int>& p1,pair<int,int>& p2)
{
    return p1.second<p2.second;
}
int main()
{
    fastio
    ll n,d;
    cin>>n>>d;
    int count=0;
    REP(i,0,n)
    {
        ll x,y;
        cin>>x>>y;
        double dis=(double)sqrt(x*x+y*y);
        if(dis>(double)d)
        {
            // cout<<x<<" "<<y<<" "<<dis<<"\n";
        }
        else
            count++;
    }
    cout<<count<<"\n";
}

Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
const ll INF = 903287038295324;

ll dp[110][100010];

int main(){
	ll n, w, v = 100010;
	cin >> n >> w;
	vector<ll> V(n),W(n);
	for (int i = 0; i < n; i++) cin >> W[i] >> V[i];
	for (int i = 0; i < 110; i++) for (int j = 0; j < v; j++) dp[i][j] = INF;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) for (int j = 0; j < v; j++) {
			if(j-V[i] >= 0) chmin(dp[i+1][j], dp[i][j-V[i]] + W[i]);
			chmin(dp[i+1][j],dp[i][j]);
	}
	int ans = 0;
	for (int i = 0; i < v; i++) {
		if(dp[n][i] <= w) ans = i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q; cin >> q;
  ll sum = 0, sum1 = 0, sum2 = 0;
  priority_queue<ll> q1;
  priority_queue<ll, vector<ll>, greater<ll>> q2;
  int n = 0;
  rep(i, q) {
    int t; cin >> t;
    if(t == 1) {
      ll a, b;
      cin >> a >> b;
      sum += b;
      if(n == 0) {
        q1.push(a);
        sum1 += a;
      } else if(n%2==0) {
        if(a > q1.top()) {
          q2.push(a);
          sum2 += a;
          q1.push(q2.top());
          sum1 += q2.top();
          sum2 -= q2.top();
          q2.pop();
        } else {
          q1.push(a);
          sum1 += a;
        }
      } else {
        if(a > q1.top()) {
          q2.push(a);
          sum2 += a;
        } else {
          q1.push(a);
          sum1 += a;
          q2.push(q1.top());
          sum2 += q1.top();
          sum1 -= q1.top();
          q1.pop();
        }
      }
      n++;
    } else {
      ll med = q1.top();
      cout << med << ' ' << (med*(int)q1.size()-sum1)+(sum2-med*(int)q2.size())+sum << endk;
    }
  }
  return 0;
}


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

int main(){
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >>A[i];
    int longest = A[0] + (K-A[N-1]);
    for(int i=1;i<N;i++) longest = max(longest, A[i]-A[i-1]);
    cout << K - longest << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int n;
  int a[100005];
  int flag,cnt;
  cin >> n;
  for (int i = 0; i < n; i++) {
	cin >> a[i];
  }
  sort(a, a + n);
  flag = abs(a[0] - a[n - 1]);
  switch (flag) {
  case 0:
	if (n - 1 == a[0]) {
	  cout << "Yes" << endl;
	}
	else if(n>=2*a[0]){
	  cout << "Yes" << endl;
	}
	else {
	  cout << "No" << endl;
	}
	break;
  case 1:
	cnt = 0;
	for (int i = 0; i < n; i++) {
	  if (a[i] == a[0])cnt++;
	}
	if (cnt < a[n-1] && n - cnt >= 2 * (a[n-1] - cnt)) {
	  cout << "Yes" << endl;
	}
	else {
	  cout << "No" << endl;
	}
	break;
  default: cout << "No" << endl;
  }


}

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

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



int main(){

    ll n,m;
    cin >> n >> m;
    ll tmp;
    rep(i,m){
        cin >> tmp;
        n -= tmp;
    }

    if(n < 0){
        cout << -1 << endl;
    }else{
        cout << n << endl;
    }

    return 0;
}  



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

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

    int coin=0;

    for (int i = 0; i < 2; ++i){
        if (A < B){
            coin += B;
            --B;
        }else{
            coin += A;
            --A;
        }
    }

    cout << coin << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}
	
int main(){
	init();
	ll A,B,C;
	cin>>A>>B>>C;
	for(int b=1;b<=2*B;b++){
		if((A*b)%B==C){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
}


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

int main() {
  string s,t;
  cin>>s>>t;
  int ans = 0;
  int len = s.length();
  
  for (int i; i < len; i++) {
    if (s[i] != t[i]) {
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3912
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;

int main(){
    string a, b;
    cin >> a >> b;
    if(a.size() > b.size()){
        cout << "GREATER" << endl;
        return 0;
    }
    else if(a.size() < b.size()){
        cout << "LESS" << endl;
        return 0;
    }
    else{
        rep(i, a.size()){
            if(a[i] > b[i]){
                cout << "GREATER" << endl;
                return 0;
            }else if(a[i] < b[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
    }
    cout << "EQUAL" << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int main() {
    int A, B, C;
    while (cin >> A >> B >> C) {
        int res = 0;
        chmax(res, 10*A + B + C);
        chmax(res, 10*B + A + C);
        chmax(res, 10*C + A + B);
        cout << res << endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    map<string, int> ana;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ana[s]++;
    }

    ll ans = 0;
    for(auto p : ana){
        ll num = p.second;
        ans += num*(num-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11408
#include <cstdio>
#include <algorithm>
int main(){
  int n;
  scanf("%d", &n);
  int a[n], b[n];
  for(int i = 0; i < n; i++){
    scanf("%d", a+i);
  }
  for(int i = 0; i < n; i++){
    scanf("%d", b+i);
    a[i] -=b[i];
  }
  std::sort(a,a+n);
  int ans = 0;
  for(int i = n-1;i>= 0&&a[i]>0;i--){
    ans+=a[i];
  }
  printf("%d\n",ans);
}
  


Measured memory_bytes: 128
#include <iostream>

int main() {
	long long int n, a, b;
	std::cin >> n >> a >> b;
	if (a > b) { 
		int tmp;
		tmp = b;
		b = a;
		a = tmp;
	}
	if ((a - b) % 2 == 0) {
		std::cout << (b-a) / 2 << std::endl;
	}
	else if (a - 1 > n - b) {
		std::cout << n - b + 1 + (b - a - 1) / 2;
	}
	else {
		std::cout << a + (b - a - 1) / 2;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
long long int a[87];
int i,n;
a[0]=2;
a[1]=1;
  scanf("%d",&n);
  if(n<=1)printf("%ld",a[n]);
  else{
   for(i=2;i<=n;i++){
   a[i]=a[i-1]+a[i-2];
   }
    printf("%ld",a[n]);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
#include <bits/stdc++.h>
int main() {
    char a;
    cin >> a;
    if(a == 'a' || a == 'e' || a == 'i' || a == 'o' ||  a== 'u'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

type city struct {
	p, y int
}

// Datas :
type cities []city

func (p cities) Len() int {
	return len(p)
}

func (p cities) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p cities) Less(i, j int) bool {
	if p[i].p == p[j].p {
		return p[i].y < p[j].y
	}
	return p[i].p < p[j].p
}

func main() {
	sc.Split(bufio.ScanWords)

	_, M := getInt(), getInt()
	c := make(cities, M)
	for i := 0; i < M; i++ {
		c[i].p, c[i].y = getInt(), getInt()
	}
	s := make(cities, M)
	copy(s, c)
	sort.Sort(s)
	//out(s)

	x := make(map[city]int)
	cnt := 1
	p := s[0].p
	for i := 0; i < M; i++ {
		//out(s[i], p, cnt)
		if s[i].p == p {
			x[s[i]] = cnt
			cnt++
		} else {
			cnt = 1
			x[s[i]] = cnt
			p = s[i].p
			cnt++
		}
	}

	//out(x)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < M; i++ {
		p := c[i].p
		n := x[c[i]]
		fmt.Fprintf(w, "%06d%06d\n", p, n)
	}
}


Measured memory_bytes: 13184
#include<stdio.h>
long long n,k,L,R,M;
long long t[100000];
  
int check(long long x){
  long long i,id=0,cnt=0;
  for(i=0;i<n;i++){
    if(cnt+t[i]>x){
      cnt=t[i];
      id++;
    }else{
      cnt+=t[i];
    }
    if(id==k)return 0;
  }
  return 1;
}
  
int main(){
  int i;
  scanf("%lld %lld",&n,&k);
  L=1;
  for(i=0;i<n;i++){
    scanf("%lld",&t[i]);
    L=(L<t[i]?t[i]:L);
  }
  
  R=1000000000LL;
  while(L<R){
    M=(L+R)/2;
    if(check(M)==1){
      R=M;
    }else{
      L=M+1;
    }
  }
  printf("%lld\n",L);
  return 0;
}

Measured memory_bytes: 1376