akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

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

const ll MOD = ll(1e9 + 7);

ll solve(const ll m, const ll n) {
    if (m == 0) return 0;
    if (n == 0) return 1;

    ll ans = 1;
    if (n % 2 != 0) {
        ans = m;
    }

    ll x = solve(m, n / 2);
    return (ans * ((x * x) % MOD)) % MOD;
}

int main(void) {
    int m, n;
    cin >> m >> n;

    cout << solve(m, n) << endl;

    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>


using namespace std;
typedef long long ll;

int main() {
    while(true) {
        ll n, m; cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<pair<ll, ll>> roads;
        for(ll i = 0; i < n; i++) {
            int d, p; cin >> d >> p;
            roads.push_back({d, p});
        }
        sort(roads.begin(), roads.end(), [](pair<ll, ll> a, pair<ll, ll> b){ return a.second > b.second;});
        ll b = 0;
        for (ll i = 0; i < n; i++) {
            if (roads[i].first < m) {
                m -= roads[i].first;
                roads[i].first = 0;
            } else {
                roads[i].first -= m;
                m = 0;
                b = i;
                break;
            }
        }
        ll ans = 0;
        for (ll i = b; i < n; i++) {
            ans += roads[i].first*roads[i].second;
        }
    cout << ans << endl;
    }
}


Measured memory_bytes: 3336
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func ReverseAndDisplay(n []int){
	for i := 0; i < len(n) - 1; i++ {
		fmt.Printf("%d ",n[len(n) - 1 - i])
	}

	fmt.Println(n[0])
}

func main(){
	var a_n []int
	sc.Split(bufio.ScanWords)

	n := nextInt()

		for i := 0; i < n; i++ {
			input := nextInt() 
			a_n = append(a_n, input)
		}

	ReverseAndDisplay(a_n)
}


Measured memory_bytes: 1100
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	ll n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	cout<<arr[n-1]-arr[0];
	return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;



int main(void) {
    int n, m;
    cin >> n >> m;
    int s[m];
    char c[m];
    rep (i, m) cin >> s[i] >> c[i];

    bool ok = true;
    for (int i = 0; i < 1000; i++) {
        ok = true;
        string tmp = to_string(i);
        if (tmp.size() != n) continue;
        rep (i, m) {
            if (tmp[s[i] - 1] != c[i]) ok = false;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

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

    if (K <= A) {
        cout << A - K << " " << B << "\n";
    } else if (K <= A + B) {
        cout << 0 << " " << B - (K - A) << "\n";
    } else {
        cout << 0 << " " << 0 << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

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

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;

typedef struct GE{
	int to;
	ll w;
	GE(){};
}GE;

int n, m;
int A[MAXN];
int main() {
	scanf("%d", &n);
	
	for(int i=0;i<n;i++) {
		scanf("%d", &A[i]);
	}
	int ans=0;
	for(int i=1;i<n-1;i++){
		vector<int> tmp;
		tmp.push_back(A[i-1]);
		tmp.push_back(A[i]);
		tmp.push_back(A[i+1]);
		sort(tmp.begin(), tmp.end());
		if(tmp[1]==A[i]) {
			ans++;
		}
	}
	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> grid(3,vector<int>(3,0));
  for(int h=0;h<3;h++){
    for(int w=0;w<3;w++){cin>>grid.at(h).at(w);}
  }
  int difh1=grid.at(0).at(0)-grid.at(1).at(0);
  int difh2=grid.at(1).at(0)-grid.at(2).at(0);
  for(int w=1;w<3;w++){
    int _difh1=grid.at(0).at(w)-grid.at(1).at(w);
    int _difh2=grid.at(1).at(w)-grid.at(2).at(w);
    if(difh1!=_difh1||difh2!=_difh2){cout<<"No"<<endl;return 0;}
  }
  int difw1=grid.at(0).at(0)-grid.at(0).at(1);
  int difw2=grid.at(0).at(1)-grid.at(0).at(2);
  for(int h=1;h<3;h++){
    int _difw1=grid.at(h).at(0)-grid.at(h).at(1);
    int _difw2=grid.at(h).at(1)-grid.at(h).at(2);
    if(difw1!=_difw1||difw2!=_difw2){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");

//const ll N=1e5+5;
ll p=1e9+7;
//ll fac[N];

inline ll ceil(ll a,ll b)
{
  return (a+b-1)/b;
}

ll max(ll x,ll y,ll z)
{
  return max(x,max(y,z));
}


ll modpro(ll x,ll y,ll z=1)
{
  x%=p;
  y%=p;
  z%=p;
  ll res=(x*y)%p;
  res=(res*z)%p;
  return res;
}

ll modadd(ll x,ll y,ll z=0)
{
  ll res=(x+y)%p;
  res=(res+z)%p;
  return res;
}


ll pow_mod_p(ll a,ll b)
{
  a=a%p;
  ll res=1;
  while(b>0)
  {
    if(b&1) res=(res*a)%p;
    b=b>>1;
    a=(a*a)%p;
  }
  return res;
}

inline ll mod_inv(ll x)
{
  return pow_mod_p(x,p-2);
}
/*
ll nCr(ll x,ll y)
{
  if(x<y) return 0;
  ll res=fac[x];
  ll den=(fac[y]*fac[x-y])%p;
  ll deni=mod_inv(den);
  res=(res*deni)%p;
  return res;
}
*/

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

void func()
{
  ll n,k;
  cin>>n>>k;
  if(k==0)
  {
    cout<<n<<endl;
    return;
  }
  if(n==0)
  {
    cout<<n<<endl;
    return;
  }
  ll x=min(n%k,k-(n%k));
  pr(x) nl 
} 


int main() 
{
    fast
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/

    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int>W(10);
  vector<int>H(10);
  for(int i=0;i<10;i++)
    cin>>W[i];
  for(int i=0;i<10;i++)
    cin>>H[i];
  sort(W.begin(),W.end(),greater<int>());
  sort(H.begin(),H.end(),greater<int>());
  cout<<W[0]+W[1]+W[2]<<" "<<H[0]+H[1]+H[2]<<endl;
  return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll ans=0;
    ans=(n*(n-1))/2;
    cout<<ans;
    
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    for (int i=0; i<n-2; i++) {
        if (s.substr(i, 3) == "ABC") ++count;
    }
    cout << count <<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int main()
{
	int n,m,a,b,i,x,y;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&m);
		for(a=b=i=0;i<m;++i)
		{
			scanf("%d",&x);
			if(i)
			{
				if(x>y)a=std::max(a,x-y);
				else b=std::max(b,y-x);
			}
			y=x;
		}
		printf("%d %d\n",a,b);
	}
	return 0;
}

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

using namespace std;

typedef long long int 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; }

typedef pair<int,int> pair;

int main(){
    int n;
    string s;
    cin >> n >> s;
    string a="ABC";
    int count=0;

    for(int i=2;i<n;i++){
        string b;
        b+=s[i-2];
        b+=s[i-1];
        b+=s[i];
        if(a==b){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a.sort()

lis = [0] * n
m = 1

for i in range(0, n-1):
    while a[i] > m:
        m += 1
    lis[m-1] += 1
    
for i in range(n):
    print(lis[i])

Measured memory_bytes: 32372
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M=3010;
db p[M],dp[M];
int n,m;
int main()
{
    scanf("%d",&n);
    m=n/2;
    for(int i=1;i<=n;i++)
        scanf("%lf",&p[i]);
    dp[0]=1;
    for(int i=1;i<=n;i++)
        for(int j=m;j>=0;j--)
        {
            dp[j]=dp[j]*p[i];
            if(j) dp[j]+=dp[j-1]*(1-p[i]);
        }
    db ans=0;
    for(int i=0;i<=m;i++)
        ans+=dp[i];
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 384
n, a, b, c, d = map(int, input().split())
S = input()
if c < d:
  for i in range(a-1, d-1):
    if S[i] == "#" and S[i+1] == "#":
      print("No")
      exit()
  print("Yes")
else:
  for i in range(a-1, d-1):
    if S[i] == "#" and S[i+1] == "#":
      print("No")
      exit()
  for i in range(b-1, min(d, n-1)):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
      print("Yes")
      exit()
  print("No")

Measured memory_bytes: 9400
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);


void solve() {
	string s; cin >> s;
	int n = s.length();
	ll ans = 0;
	int tmp = 0;
	per(i, n) {
		if (s[i] == 'B')ans += tmp;
		else tmp++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}





Measured memory_bytes: 720
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100010
#define pi M_PI

typedef struct ppp{
    char name[20];
    int time;
} P;

P Q[N];
int head=0,tail=0;

void enqueue(P x){
    Q[tail]=x;
    tail =(tail+1)%N;
}
P dequeue(){
    P x=Q[head];
    head =(head+1)%N;
    return x;
}
int main(){
    int n,q;
    scanf("%d%d\n",&n,&q);
    int result=0;
    for(int i=0;i<n;i++){
        P qu;
        scanf("%s%d",qu.name,&qu.time);
        enqueue(qu);
    }
    while(head != tail){
        P kari = dequeue();
        if(kari.time<=q){
            result += kari.time;
            printf("%s %d\n",kari.name,result);
        }else{
            result += q;
            kari.time -= q;
            enqueue(kari);
        }
    }
    return 0;
}



Measured memory_bytes: 4080
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int n , cnt , k , freq[N];
int main() {
    abdelrahman010
    cin >> n >> k;
    for(int i = 0;i < n;i++) {
        int x;
        cin >> x;
        freq[x - 1]++;
    }
    sort(freq , freq + n , greater<>());
    for(int i = k;i < n;i++)
        cnt += freq[i];
    cout << cnt;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
  int i;
  int a[1000],b[1000];
  char op[1000];

  while(1){
    scanf("%d %c %d\n",&a[i],&op[i],&b[i]);
        if(op[i]=='?'){
          break;
        }
    i++;
  }

  for(int j;j<i;j++){
    if(op[j]=='+'){
      printf("%d\n",a[j]+b[j]);
    }else if(op[j]=='-'){
      printf("%d\n",a[j]-b[j]);
    }else if(op[j]=='*'){
      printf("%d\n",a[j]*b[j]);
    }else if(op[j]=='/'){
      printf("%d\n",a[j]/b[j]);
    }
  }
  return 0;
}


Measured memory_bytes: 2140
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, m;
    int a[100][100], b[100], c[100];
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }

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

    for (int i = 0; i < n; i++) {
        c[i] = 0;
        for (int j = 0; j < m; j++) {
            c[i] += a[i][j] * b[j];
        }
    }

    for (int i = 0; i < n; i++) {
        printf("%d\n", c[i]);
    }
}


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

#define ll long long 

using namespace std;

int n,k,aux,r;
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    vector <int> v(10);
    for (int i=0; i<k; i++){
        cin>>aux;
        v[aux]=1;
    }
        
    for (int i=n; i<=n*10; i++){
        int j=i;
        while(j!=0){
            r=j%10;
            if (v[r]==1) break;
            j/=10;
        }
        if (j==0) return cout<<i,0;
    }
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long H){
  long long t = 0;
  long long a = 1;
  while (H > 0) {
    H /= 2;
    t += a;
    a *= 2;
  }
  std::cout << t << std::endl;
}

int main(){
  long long H;
  scanf("%lld",&H);
  solve(H);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int w, d;
int a[30];
signed main() {
    while(cin >> w >> d, w || d) {
        int ans = 0, inp;
        memset(a, 0, sizeof(a));
        rep(i,0,w) {
            cin >> inp;
            a[inp]++;
        }
        rep(i,0,d) {
            cin >> inp;
            if(a[inp]) a[inp]--;
            ans += inp;
        }
        rep(i,0,30) ans += i * a[i];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
# coding: utf-8
# Your code here!
n=int(input())
p=list(map(int,input().split()))
mi=10**9
ma=0
ans=0
for i in range(n):
    #print(ans)
    if mi>p[i]:
        mi=p[i]
        ans+=1
    if ma<p[i] and i!=0:
        ma=p[i]
        continue
print(ans)

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

int pnjg, freq [30];
string input, abjad="abcdefghijklmnopqrstuvwxyz";
bool gaada;

int main (){
	gaada=true;
	cin>>input;
	pnjg=input.length();
	for (int i=0; i<pnjg; i++){
		freq [input [i]-'a']++;
	}
	for (int i=0; i<26;i++){
		if (freq [i]==0){
			cout<<abjad[i]<<endl;
			i=27;
			gaada=false;
		}
	}
	if (gaada==true){
		cout<<"None"<<endl;
	}
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,d=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(i*500+j*100+k*50==x)
          d++;
      }
    }
  }
  cout<<d;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    total = 0
    cntr = {}
    cntr[0] = 0
    for a in A:
        total = (total + a) % M
        if total not in cntr:
            cntr[total] = 0
        else:
            cntr[total] += 1
    ans = 0
    for c in cntr.values():
        ans += c*(c+1) // 2
    print(ans)


if __name__ == "__main__":
    main()


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

ll dp[300000][5];
int a[300000];

int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	rep(i,n){
		dp[i+1][0]=dp[i][0]+a[i];
		dp[i+1][1]=min(dp[i][0],dp[i][1])+(a[i]?a[i]%2:2);
		dp[i+1][2]=min({dp[i][0],dp[i][1],dp[i][2]})+(a[i]?!(a[i]%2):1);
		dp[i+1][3]=min({dp[i][0],dp[i][1],dp[i][2],dp[i][3]})+(a[i]?a[i]%2:2);
		dp[i+1][4]=min({dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4]})+a[i];
	}
	ll Min=INF;
	rep(i,5)Min=min(Min,dp[n][i]);
	cout<<Min<<endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(1,vector<int>(26,-1));
  vector<vector<int>> C(1,vector<int>(26,0));

  auto add = [&](const string& s){
               int v = 0;
               vector<int> cnt(26);
               for(auto cc : s){
                 ++cnt[cc-'a'];
               }
               for(auto cc : s){
                 for(int i = 0; i < 26; ++i){
                   if(cnt[i] > 0) ++C[v][i];
                 }

                 int c = cc-'a';
                 --cnt[c];
                 if(G[v][c] < 0){
                   int v_ = G.size();
                   G[v][c] = v_;
                   G.push_back(vector<int>(26,-1));
                   C.push_back(vector<int>(26,0));
                 }
                 v = G[v][c];
               }
             };

  auto solve = [&](const string& s){
                 int v = 0;
                 for(size_t i = 0; i+1 < s.length(); ++i){
                   int c = s[i] - 'a';
                   v = G[v][c];
                 }
                 return C[v][s.back()-'a'];
               };

  vector<string> S(N);
  for(int i = 0; i < N; ++i){
    cin >> S[i];
    reverse(S[i].begin(), S[i].end());
    add(S[i]);
  }
  long long ans = 0;
  for(auto s : S){
    // cerr << s << endl;
    // cerr << solve(s) << endl;
    ans += solve(s);
  }
  ans -= N;
  cout << ans << endl;
}


Measured memory_bytes: 269856
//Problem: ABC 172 B
//Progress: Working
#include <iostream>
#include <cstring>
typedef long long int ll;
using namespace std;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	cin >> s >> t;
	ll ans = 0;
	for(int i=0; i<(ll)s.length(); i++){
		if(s[i] != t[i])
			ans++;
	}
	cout << ans;
	return 0;
}

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

int main()
{
	int x,n,i;
	cin>>x>>n;
	int a[n];
	for(int i=0;i<n;++i)
	{
		cin>>a[i];
		a[i]=a[i]-x;
	}
	for(i=0;;++i)
	{
		int ans1=0,ans2=0;
		for(int j=0;j<n;++j)
		{
			if(a[j]==i) ans1=1;
			 if(a[j]==-i) ans2=2;
			if(ans1!=0 && ans2!=0) break;
		}
		
		if(ans2==0) 
		{
		cout<<x-i;
		return 0;
	}
		 if(ans1==0) {
		cout<<x+i;
		return 0;
	}
	}
	 return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
main()
{
    int a,b,c,area;
    scanf("%d %d %d",&a,&b,&c);
    area=0.5*a*b;
    if(c==0)
        printf("0\n");
    else if(a==1 && b==1)
        printf("1\n");
    else
    printf("%d\n",area);

}


Measured memory_bytes: 1716
#include<iostream>
using namespace std;
int N,K;
main()
{
	cin>>N>>K;
	if(N==1)
	{
		if(K==0)cout<<"1 1 0 0"<<endl;
		else cout<<-1<<endl;
	}
	else if(K>=1<<N)cout<<-1<<endl;
	else
	{
		for(int i=0;i<1<<N;i++)if(i!=K)cout<<i<<" ";
		cout<<K<<" ";
		for(int i=1<<N;i--;)if(i!=K)cout<<i<<" ";
		cout<<K<<endl;
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

struct edge { int to; ll cost; };
using graph = vector<vector<edge>>;

int n;
vector<ll> previ;

void dijkstra(const graph &G, vector<ll> &dist, int s) {
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> que;
    fill(dist.begin(), dist.end(), INT_MAX);
    fill(all(previ),-1);
    dist[s] = 0;
    que.push(pair<ll,int>(0, s));
    while(!que.empty()){
        pair<ll, int> p=que.top(); que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        rep(i,0,G[v].size()){
            edge e = G[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                previ[e.to]=v;
                que.push(pair<ll,int>(dist[e.to], e.to));
            }
        }
    }
}

int main(){
    int m;
    cin >> n >> m;

    graph G(n);
    vector<ll> dist(n, LINF);
    previ.resize(n);
    rep(i,0,m){
        int from, to;
        ll cost;
        cin >> from >> to;
        from--; to--;
        G[from].push_back({to, 1});
        G[to].push_back({from, 1});

    }
    cout<<"Yes"<<endl;
    dijkstra(G,dist,0);
    rep(i,1,n){
        cout<<previ[i]+1<<endl;
    }

}

Measured memory_bytes: 19596
<?php
$input = STDIN;

list($n, $q) = explode(" ", trim(fgets($input)));
$n = (int)$n;
$q = (int)$q;

for ($i = 0; $i < $n; $i++) {
    list($name_i, $time_i) = explode(" ", trim(fgets($input)));
    $time_i = (int)$time_i;
    $queue[] = [$name_i, $time_i];
}

$head = 0;
$tail = $n;
$elapsed = 0;
$ans = "";

while ($head != $tail) {
    // dequeue
    list($p_name, $remaining) = $queue[$head];
    if ($head == $n) $head = 0;
    else $head++;

    if ($remaining <= $q) {
        $elapsed += $remaining;
        $ans .= "{$p_name} {$elapsed}\n";
    } else {
        $elapsed += $q;
        $remaining -= $q;

        //enqueue
        $queue[$tail] = [$p_name, $remaining];
        if ($tail == $n) $tail = 0;
        else $tail++;
    }
}

print $ans;


Measured memory_bytes: 40500
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let (a, b, c): (i32, i32, i32) = read();
    let ans = max(solve(a, b, c), max(solve(a, c, b), solve(b, c, a)));
    println!("{}", ans);
}

fn solve(a: i32, b: i32, c: i32) -> i32 {
  max(a*10+b+c, b*10+a+c)
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include<algorithm>	
using namespace std;
#define ll long long 
vector<vector<int>> l(100001);
//int used[100001][100001];
int col[100001];
const int MAX = 510000;
const int MOD = 1000000007;

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




Measured memory_bytes: 6268
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
char a[200020];
int main(void)
{
    int T,n,f,x,y,s,mn,xx,yy;
    string a,b,c;
    cin>>a;
    for(int i=0;i<a.size();i++)
        printf("x");
    printf("\n");
    return 0;
}



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

int main()
{
  int n,k,i,j=0;
  cin>>n>>k;
  int arr[n];
  for(i=0;i<n;i++)
    cin>>arr[i];
  int *p;
  for(i=0;i<k;i++)
  { p=min_element(arr,arr+n);
   j+=*p;
  *p=numeric_limits<int>::max();}
  cout<<j;
  
  
  
}

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

#define rep(i, n) for (ll i = 1; i < (ll)(n); i++)
#define ll long long
using namespace std;


int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int count = 0;
  rep (i, n + 1) {
    int isom = 0;
    int now = i;
    while (now > 0) {
      isom += now % 10;
      now /= 10;
    }
    if (isom >= a && isom <= b) {
      count += i;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define register register
#define cs const
using std::cerr;
using std::cout;
using pii=std::pair<int,int>;
#define fi first
#define se second

std::string inv(std::string s){
	std::string res="";
	std::reverse(s.begin(),s.end());
	for(char c:s)
		if(isupper(c))res+=c-'A'+'a';
		else res+=c-'a'+'A';
	return res;
}

int n;
std::string A;

void Main(){
	std::cin>>n>>A;
	if(A[0]=='0')
	{
		puts("Impossible");
		return ;
	}
	int register i=0;
	while(i<(1<<n))
	{ 
		if(A[i]=='1')
		{
			int register j=i;
			while(j)
			{
				if(A[j]=='0')
				{
					puts("Impossible");
					return ;
				}
				j=i&(j-1);
			}
		}
		++i;
	}
	std::vector<pii> p({{0,0}});
	int register s=0;
	while(s<(1<<n))
	{
		if(A[s]=='0')
		{
			bool flag=true;
			int register t=s&(s-1);
			while((t)&&(flag))
			{
				if(A[t]=='0')flag=false;
				t=s&(t-1);
			}
			if(!flag)
			{
				++s;
				continue;
			}
			std::string q;
			int register i=0;
			while(i<n)
			{
				if(s&(1<<i))
				{
					if(q.empty()) q+='a'+i;
					else q=(char)('a'+i)+q+(char)('A'+i)+inv(q);
				}
				++i;
			}
			int nw=0;
			int k=0;
			while(k<q.size())
			{
				char c=q[k];
				int i,dir;
				if(isupper(c))
				{
					i=c-'A';
					dir=0;
				}
				else
				{ 
					i=c-'a';
					dir=1;
				}
				int j=nw+1;
				while(j<=i)
				{
					p.push_back({j,0});
					++j;
				}
				j=nw-1;
				while(j>=i)
				{
					p.push_back({j,0});
					--j;
				}
				nw=i;
				if(dir)
				{
					p.push_back({i,1});
					p.push_back({i+1,1});
					p.push_back({i+1,0});
					p.push_back({i,0});
				}
				else
				{
					p.push_back({i+1,0});
					p.push_back({i+1,1});
					p.push_back({i,1});
					p.push_back({i,0});
				}
				++k;
			}
			int j=nw-1;
			while(~j)
			{
				p.push_back({j,0});
				--j;
			}
		}
		++s;
	}
	cout<<"Possible\n"<<(p.size()-1)<<"\n";
	i=0;
	while(i<p.size())
	{
		cout<<p[i].fi<<" "<<p[i].se<<"\n";
		++i;
	}
}
signed main()
{
	Main();
	return 0;
}

Measured memory_bytes: 3732
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c

n, k, s = [int(i) for i in input().split()]

ans = [s] * k
if s == 10**9:
    ans += [1] * (n - k)
else:
    ans += [s + 1] * (n - k)
print(" ".join([str(i) for i in ans]))


Measured memory_bytes: 78140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
const long double eps=1e-10;

struct point{
    long double x;
    long double y;
    bool up;
};

int ccw(point a,point b,point c){
    point d={b.x-a.x,b.y-a.y};
    point e={c.x-a.x,c.y-a.y};
    
    long double cross=d.x*e.y-d.y*e.x;
    long double dot=d.x*e.x+d.y*e.y;
    
    if(cross>eps) return 1;
    if(cross<-eps) return -1;
    if(dot<-eps) return 2;
    if((d.x*d.x+d.y*d.y)<(e.x*e.x+e.y*e.y)) return -2;
    return 0;
}//反時計回り、時計回り、直線上で後ろ、前、線分上

bool intersect(point a,point b,point s,point t){
    if(ccw(a,b,s)*ccw(a,b,t)<=0&&ccw(s,t,a)*ccw(s,t,b)<=0) return 1;
    else return 0;
}//1なら交差

point GetCrossPoint(point a,point b,point c,point d,bool up){
    point base={d.x-c.x,d.y-c.y};
    point vec1={a.x-c.x,a.y-c.y};
    point vec2={b.x-c.x,b.y-c.y};
    long double d1=abs(base.x*vec1.y-base.y*vec1.x),d2=abs(base.x*vec2.y-base.y*vec2.x);
    long double t=d1/(d1+d2);
    
    return {a.x+(b.x-a.x)*t,a.y+(b.y-a.y)*t,up};
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        point s,g;cin>>s.x>>s.y>>g.x>>g.y;
        vector<point> use;
        
        int N;cin>>N;
        for(int i=0;i<N;i++){
            point a,b;cin>>a.x>>a.y>>b.x>>b.y;
            int o,l;cin>>o>>l;
            
            if(intersect(s,g,a,b)){
                point p=GetCrossPoint(s,g,a,b,bool((o+l)%2));
                use.push_back(p);
            }
        }
        
        sort(all(use),[](point a,point b){
            if(a.x==b.x) return a.y<b.y;
            return a.x<b.x;
        });
        int ans=0;
        
        for(int i=0;i+1<use.size();i++){
            if(use[i].up!=use[i+1].up) ans++;
        }
        
        cout<<ans<<endl;
    }

}




Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n,m;
    while(cin>>n>>m,n+m){
        vector<pii>res;
        int ans=0;
        rep(i,n){
            int a,b; cin>>a>>b;
            ans+=a*b;
            res.push_back(mp(b,a));
        }
        sort(all(res),greater<pii>());
        rep(i,res.size()){
            if(m-res[i].second>0){
                ans-=res[i].first*res[i].second;
                m-=res[i].second;
            }else{
                ans-=m*res[i].first;
                break;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> flg(101,0);
    for(int i=0;i<n;i++){
        int d;
        cin >>d;
        flg[d]=1;
    }
    int ans;
    ans =0;
    for(int i=0; i<101;i++){
        ans += flg[i];
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,i,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

string next(string s){
	bool list[26] = {};

	if(s.size() < 26){
		for(auto t : s){
			list[t-'a'] = true;
		}
		rep(i,26){
			if(!list[i]){
				return s + char(i+'a');
			}
		}
	}else{
		for(int i = 25; i >= 0; i--){
			list[s[i] - 'a'] = true;
			for(int j = s[i] - 'a' + 1; j <= 25; j++){
				if(list[j]){
					return s.substr(0,i) + char(j + 'a');
				}
			}
		}
	}

	cout << "ERROR:ERROR" << endl;
	return "-2";
}


void solve(){
	string S;
	cin >> S;
	bool list[26] = {};

	if(S == "zyxwvutsrqponmlkjihgfedcba"){
		cout << -1 << endl;
		return;
	}

	cout << next(S) << endl;
	return;
}

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

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if( a==5&&b==5&&c==7 ||a==7&&b==5&&c==5 ||a==5&&b==7&&c==5)
    printf("YES");
    else 
    printf("NO");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;
int main()
{
    unsigned long long int a,b,k,ansa,ansb;
    cin >> a>> b >> k;
    if(k>=a)
    {
        ansa=0;
        k-=a;
        if(k<=b)
        {
            ansb=b-k;
        }
        else
            ansb=0;
    }
    else
    {
        ansa=a-k;
        ansb=b;
    }
    cout << ansa << " " << ansb;
}



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

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> a(m);
  for (int i = 0; i < m; ++i)
  	cin >> a[i].first >> a[i].second;

  sort(a.begin(), a.end());
  int ans = 0;
  int mx = -1;
  for(auto const& p : a) {
  	int l, r; tie(l, r) = p;
  	// remove first
  	if(mx <= l) {
  		ans++;
  		mx = r;
  	} 
  	// add next
  	else {
  		mx = min(mx, r);
  	}
  }
  cout << ans << flush;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))

two = 0
four = 0
odd = 0

for a in A:
  if a % 4 == 0:
    four += 1
  elif a % 2 == 0:
    two += 1

N -= max(0, two - 1)

print("Yes" if four >= N // 2 else "No")

Measured memory_bytes: 20128
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;

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

    ll ans=0;

    if(K==0){
        ans = N * N;
        cout << ans << endl;
        return 0;
    }
    for(ll i=1;i<=N;i++){
        ll m, r;
        m = N / i;
        r = N % i;
        ans = ans + m * max(0LL, i-K) + max(0LL, r-K+1);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

inline ll f(ll a,ll x){
    if(a<0)return 0;
    return a/x+1;
}

int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    cout<<f(b,x)-f(a-1,x)<<endl;
    return 0;
}


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

int main (void){
long long int n = 0,k = 0,m = 0,min = 10000000000;

  cin >> n;
  cin >> k;

  vector<long long int> hei(n,0);
  for(int i = 0; i < n;i++){
    cin >> hei[i];
  }

  sort(hei.begin(),hei.end());

  for(int i = 0;i < n - k + 1;i++){
    m = hei[n - i - 1] - hei[n - k - i];
    if(m < min){
      min = m;
    }
  }

  cout << min << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

string s, t;
Int c;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s >> t;
	for(size_t i=0; i<s.size(); ++i)
		if(s[i] == t[i])
			++c;
	cout << c << "\n";
}

Measured memory_bytes: 256
N, M = map(int, input().split())

all_cities = []
pref = {}
for _ in range(M):
    Pi, Yi = map(int, input().split())

    # [ 誕生年,  認識番号 ]
    city = [Yi, None]

    all_cities.append(city)

    if Pi not in pref:
        pref[Pi] = []
    pref[Pi].append(city)

for pref_id, pref_cities in pref.items():
    for city_id, city in enumerate(sorted(pref_cities, key=lambda c: c[0])):
        city[1] = "{:06}{:06}".format(pref_id, city_id + 1)

for city in all_cities:
    print(city[1])


Measured memory_bytes: 44460
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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()
{
cin.tie(0);
ios::sync_with_stdio(false);

int n;
cin >> n;

if(n%2 == 0) cout << 0.5 << endl;
else{
    double a = n / 2 + 1;
    cout << fixed << setprecision(10) << a / double(n) << endl;
}

return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main()
{
	int n,maxv,minv;
	cin >> n;
	int R[n];
	REP(i,n) cin >> R[i];
	maxv = R[1] - R[0];
	minv = R[0];

	FOR(i,1,n) {
		maxv = max(maxv, (R[i]-minv));
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	return 0;
}



Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	bool ans = true;
	std::vector<int> b(n);
	for(int k = n; k > 0; k--) {
		int count = 0;
		for(int i = k - 1; i < n; i += k) count += !!b[i];
		if(count % 2 != a[k - 1]) b[k - 1] = 1;
	}
	
	if(!ans) {
		printf("-1\n");
	} else {
		std::vector<int> ans;
		for(int i = 0; i < n; i++) if(b[i]) ans.push_back(i + 1);
		printf("%d\n", ans.size());
		for(auto v: ans) printf("%d ", v);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int h = Integer.parseInt(br.readLine());
		int w = Integer.parseInt(br.readLine());
		int n = Integer.parseInt(br.readLine());
		int max = Integer.max(h, w);
		int result =0;
		if(n%max == 0) {
			result = n/max;
		}else {
			result  = n/max +1;
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 21076
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N / i != i)
                res.push_back(N / i);
        }
    }
    // 小さい順に並び替える
    sort(all(res), greater<ll>());
    return res;
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> en = enum_divisors(M);
    rep(i, en.size()) {
        if (M / en[i] >= N) {
            cout << en[i] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
#define MAX 20

int con;
int eq[MAX][MAX], hoge[4][MAX];

bool check(int y, int x){
	return hoge[0][y]||hoge[1][x]||hoge[2][y-x+8]||hoge[3][y+x]||eq[y][x];
}

void mark(int y, int x, bool tf){
	bool z = tf;
	eq[y][x] = z;
	hoge[0][y] = hoge[1][x] = hoge[2][y-x+8] = hoge[3][y+x] = z;
}

bool fuga(int z){
	while(hoge[0][z] == 1) z++;
	if(z>=8)return true;
	for(int i = 0; i < 8; i++){
		if(!check(z,i)){
			mark(z,i,true);
			if(fuga(z+1) == false) mark(z,i,false);
			else return true;
		}
	}
	return false;
}

int main(){
	int k, x, y;
	
	cin>>k;
	
	for(int i = 0; i < k; i++){
		cin>>y>>x;
		mark(y,x,true);
	}
	
	fuga(0);
	
	for(int i = 0; i < 8; i++){
		for(int j = 0; j < 8; j++){
			cout<<(eq[i][j]?"Q":".");
		}cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#!/usr/bin/env python3
import sys


def solve(X: int):
    i=1
    sum_a=0
    while sum_a < X:
        sum_a+=i
        i+=1

    print(i-1)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940