akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
    int a[3],tmp;

    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    
    if(a[0]>a[1]){
        tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }
    if(a[0]>a[2]){
        tmp = a[0];
        a[0] = a[2];
        a[2] = tmp;
    }
    if(a[1]>a[2]){
        tmp = a[1];
        a[1] = a[2];
        a[2] = tmp;
    }

    printf("%d %d %d\n",a[0],a[1],a[2]);

    return 0;
}

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

int max( int a, int b ) {
	return (a > b) ? a : b;
}

long long f( char s[], int x, int n ) {
	long long sum = 0;
	
	if( x >= n ) {
		return 0;
	}
		
	long long num = 0;
	for( int i = x; i < n; i++ ) {
		num = num * 10 + (s[i]  - '0');
		sum += num * (1LL << max(0,n-i-2))+ f(s, i+1, n);
	}
	
	return sum;
}

int main( void ) {
	char s[20];
	scanf("%s", s);
	
	printf("%lld\n", f(s, 0, strlen(s)));
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0;i < n;i++){
       cin >> a[i];
    }
    for(int i = 1;i < n;i++){
        a[i] = gcd(a[i],a[i-1]);
    }
    cout << a[n-1] << endl;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


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

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

    int a[N] = {0};
    for(int i = 0; i < N; i++) cin >> a[i];

    int colors[9];
    for(int i = 0; i < 9; i++) colors[i] = 0;

    for(int i = 0; i < N; i++)
    {
        if(0 < a[i] and a[i] < 400) //灰色
        {
            colors[0]++;
        }
        else if(400 <= a[i] and a[i] < 800) //茶色
        {
            colors[1]++;
        }
        else if(800 <= a[i] and a[i] < 1200) //緑色
        {
            colors[2]++;
        }
        else if(1200 <= a[i] and a[i] < 1600) //水色
        {
            colors[3]++;
        }
        else if(1600 <= a[i] and a[i] < 2000) //青色
        {
            colors[4]++;
        }
        else if(2000 <= a[i] and a[i] < 2400) //黄色
        {
            colors[5]++;
        }
        else if(2400 <= a[i] and a[i] < 2800) //橙色
        {
            colors[6]++;
        }
        else if(2800 <= a[i] and a[i] < 3200) //赤色
        {
            colors[7]++;
        }
        else if(3200 <= a[i]) //好きな色
        {
            colors[8]++;
        }
    }


    int cnt = 0;
    for(int i = 0; i < (9-1); i++)
    {
        if(colors[i] > 0) cnt++;
    }

    cout << max(1, cnt) << " " << cnt+colors[8] << endl;

    return 0;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  string s;
  cin>>s;

  string prev,back;
  prev+=s[0];
  prev+=s[1];
  back+=s[2];
  back+=s[3];

  int pr,ba;
  pr=stoi(prev);
  ba=stoi(back);
  
  if(12>=pr && pr>=1){
     if(12>=ba && ba>=1) cout<<"AMBIGUOUS"<<endl;
     else cout<<"MMYY"<<endl;
  }else{
     if(12>=ba && ba>=1)cout<<"YYMM"<<endl;
     else cout<<"NA"<<endl;
  }

 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

signed main() {
	
	fastio();
//	#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n,k;
	cin>>n;
	string s;
	cin>>s;
	cin>>k;
	for(int i=0;i<n;i++)
	{
		if(s[i]==s[k-1])
		{
			cout<<s[i];
		}else{
			cout<<"*";
		}
	}
	return  0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, int>;


template<typename T> struct BIT {
    int mxn;
    vector<T> data;
    const bool zi;
    const T un;
    BIT<T>(int max_n, bool zero_indexed = false, T unit = T(0)) : mxn(max_n), zi(zero_indexed), un(unit) {
        if ( zi ) mxn++;
        data.assign(mxn + 1, unit);
    }
    void add(int i, T x) {
        if ( zi ) i++;
        assert( i > 0 );
        while ( i <= mxn ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        if ( zi ) i++;
        assert( i > 0 );
        T s = un;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
    vector<T> get_sum_list(int l, int r) {
        vector<T> a;
        for ( int i = l; i <= r; i++ ) {
            a.push_back(sum(i));
        }
        return a;
    }
};

ll solve() {
    ll N, D, A;
    cin >> N >> D >> A;
    vector<ll> X(N), H(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i] >> H[i];
    }

    vector<ll> xs;
    for ( int i = 0; i < N; i++ ) {
        xs.push_back(X[i]);
        xs.push_back(X[i] + 2*D);
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    vector<ll> xl(X.size()), xr(X.size());
    for ( int i = 0; i < X.size(); i++ ) {
        xl[i] = lower_bound(xs.begin(), xs.end(), X[i]) - xs.begin();
        xr[i] = lower_bound(xs.begin(), xs.end(), X[i] + 2*D) - xs.begin();
    }

    vector<pii> ps;
    for ( int i = 0; i < N; i++ ) {
        ps.push_back(pii(xl[i],i));
    }
    sort(ps.begin(), ps.end());
    BIT<ll> d(xs.size()+1, true);

    ll ans = 0;
    for ( int j = 0; j < N; j++ ) {
        int i = ps[j].second;
        ll h = H[i] - d.sum(xl[i]);
        if ( h > 0 ) {
            ll cn = (h+A-1)/A;
            ans += cn;
            d.add(xl[i], cn*A);
            d.add(xr[i]+1, -cn*A);
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 18412
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;
	
	int C[VMAX+ 1];
	int n, i, j;
	scanf("%d", &n);
	
	A = malloc(sizeof(short) * n + 1);
	B = malloc(sizeof(short) * n + 1);
	
	for( i=0; i<=VMAX; i++ ) C[i] =0;
	
	for(i=0; i<n; i++){
		scanf("%hu", &A[i + 1]);
		C[A[i + 1]]++;
	}
	

	for ( i=1; i<=VMAX; i++ ) C[i] = C[i] + C[i-1];
	
	for( j=1; j<=n; j++){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for( i=1; i<=n; i++){
		if( i>1 ) printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");
	
	
	return 0;
}


Measured memory_bytes: 9656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m, a, b;
  cin >> n >> m;
  vector<int> s(n);
  for(int i=0; i<m; ++i){
    cin >> a >> b;
    ++s[a-1];
    ++s[b-1];
  }
  for(int i=0; i<n; ++i) cout << s[i] << endl;
}



Measured memory_bytes: 3600
#!/usr/bin/ruby
#
# 1031.rb: Simple GUI Application
#

### subroutines

# tagst := stag tagvalue {tagst}* etag
# stag  := <tagname>
# etag  := </tagname>
# tagname := string
# tagvalue := num,num,num,num

def parse_tagst(gui)
  tagname = parse_stag(gui)
  vals = parse_tagvalue(gui)

  tagsts = []
  while gui[$pos + 1] != '/'
    tagsts << parse_tagst(gui)
  end

  parse_etag(gui)

  [tagname, vals, tagsts]
end

def parse_stag(gui)
  return nil if gui[$pos] != '<'
  $pos += 1

  pos0 = $pos
  while gui[pos0] != '>'
    pos0 += 1
  end

  tagname = gui[$pos...pos0]
  $pos = pos0 + 1
  tagname
end

def parse_etag(gui)
  return nil if gui[$pos] != '<'
  $pos += 1
  return nil if gui[$pos] != '/'
  $pos += 1

  pos0 = $pos
  while gui[pos0] != '>'
    pos0 += 1
  end

  tagname = gui[$pos...pos0]
  $pos = pos0 + 1
  tagname
end

def parse_tagvalue(gui)
  pos0 = $pos
  while gui[pos0] != '<'
    pos0 += 1
  end

  vals = gui[$pos...pos0].split(',').map(&:to_i)
  $pos = pos0
  vals
end

### main

loop do
  n = gets.to_i
  break if n == 0

  gui = gets.strip

  $pos = 0
  main = parse_tagst(gui)

  n.times do
    x, y = gets.split.map(&:to_i)

    name = 'OUT OF MAIN PANEL'
    cnum = 1
    panels = [main]

    while ! panels.empty?
      panel = panels.shift

      pname, pvals, pchld = panel
      x0, y0, x1, y1 = pvals

      if x >= x0 && x <= x1 && y >= y0 && y <= y1
        name = pname
        cnum = pchld.length
        panels = pchld.clone
      end
    end

    puts [name, cnum].join(' ')
  end
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

typedef pair<ll,ll> P;

int main() {
    int N; cin >> N;
    vector<P> coord(N);
    REP(i,N){
        ll x,y; cin >> x >> y;
        coord[i] = {x,y};
    }
    int p = (abs(coord[0].first) + abs(coord[0].second))%2;
    REP(i,N){
        if(p != (abs(coord[i].first) + abs(coord[i].second))%2){
            cout << -1 << endl;
            return 0;
        }
    }

    vector<ll> D(39);
    REP(i,39){
        D[i] = (1LL<<(38-i));
    }
    if(p%2 == 0) D.push_back(1);

    cout << D.size() << endl;
    REP(i,D.size()){
        cout << D[i];
        if(i!=D.size()-1) cout << " ";
    }
    cout << endl;

    REP(i,N){
        ll X = coord[i].first, Y = coord[i].second;
        ll x=0, y=0;
        REP(i,D.size()){
            ll d = D[i];
            ll dx = X-x, dy = Y-y;

            if(abs(dx) > abs(dy)){
                if(dx>0){
                    cout << "R";
                    x += d;
                }else{
                    cout << "L";
                    x -= d;
                }
            }else{
                if(dy>0){
                    cout << "U";
                    y += d;
                }else{
                    cout << "D";
                    y -= d;
                }
            }
        }
        cout << endl;
        //cout << "(" << x << ", " << y << ")" << endl;
    } 

    return 0;
}

Measured memory_bytes: 3612
found = False
a, b = map(int, input().split())
for i in range(int(b/10000)+1):
    for j in range(int(int(b-i*10000)/5000)+1):
        if(i*10000+j*5000+1000*(a-i-j)==b):
            print(str(i)+" "+str(j)+" "+str(a-i-j))
            found = True
            break
    if(found):
        break
if not found:
    print("-1 -1 -1")

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

int main(){
	int n;
	ll k;

	cin >> n >> k;

	vector<int> a(n+1);
	for(int i=1; i<n+1; i++){
		cin >> a[i];
	}

	vector<ll> b(n+1, 0);
	ll now = 1;
	ll cnt = 1;
	while(b[now] == 0){
		b[now] = cnt;
		if(k < cnt){
			cout << now << endl;
			return 0;
		}
		cnt++;
		now = (ll)a[now];
	}

	ll n_town = cnt - b[now];
	k -= b[now] - 1;
	ll amari = k % n_town;
	for(ll i=0; i<amari; i++){
		now = (ll)a[now];
	}

	cout << now << endl;
}


Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
using namespace std;
long int Wallet;

int main(void)
{
	cin >> Wallet;

	long int A = Wallet / 500;
	Wallet -= (A * 500);
	long int B = Wallet / 5;

	long int Result = A * 1000 + B * 5;
	cout << Result << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  for (int i = 0; i < s.length(); ++i) {
    ans += (ll)s[i] - '0';
	ans %= 9;
  }
  if (ans % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3720
// 世界は変わらない
#include <bits/stdc++.h>
#define int long long int
#define eb emplace_back
#define vi vector <int>
#define pii pair <int, int>
#define ff first
#define ss second

using namespace std;

int h, w, k;

bool cnt(char bo[6][6], int r_mask, int c_mask)
{
    int idx = 0;
    while(r_mask)
    {
        int col = r_mask & 1;
        if(col){
            for(int i = 0; i < w; i++){
                bo[idx][i] = '*';
            }
        }
        r_mask >>= 1;
        idx++;
    }
    idx = 0;
    while(c_mask)
    {
        int col = c_mask & 1;
        if(col){
            for(int i = 0; i < h; i++){
                bo[i][idx] = '*';
            }
        }
        c_mask >>= 1;
        idx++;
    }
    int res = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            res += (bo[i][j] == '#');
        }
    }
    if(res == k)
        return true;
    return false;
}

void solve()
{
    cin >> h >> w >> k;
    char b[6][6], temp[6][6];
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> b[i][j];
        }
    }
    int res = 0;
    for(int i = 0; i <= pow(2, h) - 1; i++)
    {
        for(int j = 0; j <= pow(2, w) - 1; j++)
        {
//            cout << i << ' ' << j << ' ';
            for(int m = 0; m < h; m++){
                for(int l = 0; l < w; l++)
                    temp[m][l] = b[m][l];
            }
            res += cnt(temp, i, j);
//            cout << res << '\n';
        }
    }
    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3944
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; i++) cin >> d[i];
  int m;
  cin >> m;
  int t[m];
  for(int i = 0; i < m; i++) cin >> t[i];

  if(n < m){
    cout << "NO" << endl;
    return 0;
  }

  multiset< int > ms;
  for(int i = 0; i < n; i++) ms.insert(d[i]);

  bool ans = true;
  for(int i = 0; i < m; i++){
    multiset< int >::iterator it = ms.find(t[i]);
    if(it == ms.end()){
      ans = false;
      break;
    }
    ms.erase(it);
  }

  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 11136
def array_sub(left, right)
  res = []
  left.each_with_index do |num, i|
    res << num - right[i]
  end
  res
end

def contains_one(array)
  array.all?{|num| num == array[0] }
end

c1 = STDIN.gets.split(' ').map(&:to_i)
c2 = STDIN.gets.split(' ').map(&:to_i)
c3 = STDIN.gets.split(' ').map(&:to_i)

c_1 = [c1[0], c2[0], c3[0]]
c_2 = [c1[1], c2[1], c3[1]]
c_3 = [c1[2], c2[2], c3[2]]

subs = []
subs << array_sub(c1, c2)
subs << array_sub(c2, c3)
subs << array_sub(c_1, c_2)
subs << array_sub(c_2, c_3)

if subs.all?{|array| contains_one(array)}
  puts 'Yes'
else
  puts 'No'
end


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

signed main(){
	string s; cin >> s;
	int ans = 0;
	for(int i=0; i < (1+s.length())/2; ++i){
		if(s[i] != s[s.length()-1-i])++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    [n,k] <- r'
    let x = logBase (fromIntegral k) (fromIntegral n) :: Double
    print $ ceiling $ if abs ((fromIntegral $ ceiling x) - x) < 0.0000000000001 then x+1 else x 


Measured memory_bytes: 380
arr = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
arr1 = list(map(int,arr.split(", ") ))

k = int(input())

print(arr1[k-1])

Measured memory_bytes: 2940
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(M):
  b = list(map(int, input().split()))
  B.append(b)
  
B.sort(reverse = True, key = lambda x : x[1])
A.sort()
count = 0

for x in B:
  i = x[0] - 1
  c = x[1]
  if count + i >= N:
    if A[-1] > c:
      for j in range(count,N):
        if A[j] < c:
          A[j] = c
      break
    else:
      A[count:] = [c] * (N - count)
      break
    
  elif A[count + i] > c:
    for j in range(i):
      if A[count + j] < c:
        A[count + j] = c
    break
  else:
    A[count:count + i + 1] = [c] * (i + 1)
    count += i + 1

print(sum(A))

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

int main(int argc, char* argv[]) {
	ll s, w;
	cin >> s >> w;
	if (s<=w)
	{
		cout << "unsafe" << endl;
	}
	else
	{
		cout << "safe" << endl;
	}
	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cstdio>
#include <iostream>
#include <cstdint>
#include <cstdio>
using namespace std;

int main(int argc, char const* argv[])
{
  int64_t A, B, C;
  scanf("%ld %ld %ld", &A, &B, &C);
  printf("%ld\n", min(B / A, C));
  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}

ll Q;




ll dp[2004][2];

int main() {
	ll N, Z, W;

	cin >> N >> Z >> W;
	vector<ll> a(N+1);
	rep(i, N) {

		cin >> a[i+1];
	}

	
	rep(i, 2004) {
		dp[i][1] = inf;
	}

	if (N == 1) {
		cout << abs(a[1] - W) << endl;
		return 0;
	}

	a[0] = Z;
	dp[N][0] = abs(a[N] - a[N - 1]);
	dp[N][1] = abs(a[N] - a[N - 1]);
	


	for(int i = N-1; i >= 1; i--) {
		
		for (int k = 1; k <= N - i + 1; k++) {
			
			if (k == N - i + 1 && i != 1) {
				dp[i][0] = max(dp[i][0], abs(a[N] - a[i - 1]));
			}
			else if (k == N - i + 1 && i == 1) {
				dp[i][0] = max(dp[i][0], abs(a[N] - W));
			}
			else
				dp[i][0] = max(dp[i + k][1], dp[i][0]);
		}

		for (int k = 1; k <= N-i+1; k++) {			
			
			if (k == N - i + 1)
				dp[i][1] = min(dp[i][1], abs(a[N] - a[i - 1]));
			else
				dp[i][1] = min(dp[i + k][0], dp[i][1]);
		}

	}

	cout << dp[1][0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

const int SIZE=5005;
int dp[SIZE],a[SIZE];
long long n,k,ret,sum;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>k;
	REP(i,n)cin>>a[i],sum+=a[i];
	sort(a,a+n);
	dp[0]=1;
	for(int i=n-1;i>=0;i--)
	{
		int up=false;
		for(int j=0;j<k;j++)
			if(dp[j] && j+sum>=k)up=true;
		if(!up)ret++;
		sum-=a[i];
		for(int j=k-1;j>=a[i];j--)dp[j]|=dp[j-a[i]];
	}
	cout<<ret<<endl;
	return 0;
}


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

int main() {
    int N, M2 = 0, M4 = 0;
    cin >> N;
    int Vetor[N];


    for(int i=0; i<N; i++) {
        cin >> Vetor[i];
    }


    for(int i=0; i<N; i++) {

        if(Vetor[i]%4 == 0)
            M4++;
        else if(Vetor[i]%2 == 0)
            M2++;
    }




    if(N%2 == 0 && (M2 >= N - (M4*2) || M4 >= N/2 - M2/2)) {
        cout << "Yes" << endl;
    }else if(N%2 == 1 && (M2 >= N - (M4*2) + 1 || M4 >= N/2 - M2/2)) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
x,k,d = map(int,input().split())
x = abs(x)
r = x % d
q = x // d
if (k*d) < x:
    print(x - (k*d))
else:
    if (k - q) % 2 == 0:
        print(r)
    else:
        print(abs(d-r))

Measured memory_bytes: 61628
#include<stdio.h>

int main(){

  int i,j,l;
  int n;
  int u,k;

  //input
  scanf("%d",&n);
  int A[n][n];
  int B[n][n];
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(l=0;l<k;l++){
      scanf("%d",&B[i][l]);
    }
    for(j=0;j<n;j++){
      A[i][j]=0;
      for(l=0;l<k;l++){
	if(B[i][l]==j+1){
	  A[i][j]=1;
	}
      }
    }
  }  
  //output
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==n-1) printf("%d\n",A[i][j]);
      else printf("%d ",A[i][j]);
    }
  }  
   
     

  return 0;
}



Measured memory_bytes: 2112
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
	int n, Q;
	cin >> n >> Q;
	int a[n]; Query queries[Q];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < Q; i++)
	{
		int l, r;
		cin >> l >> r;
		l--;r--;
		queries[i] = {l, r, i};
	} 
	sort(queries, queries+Q, cmp); 
	answeringQueries(a, n, queries, Q); 
	return 0; 
} 


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    double A,B,H,M; cin >> A >> B >> H >> M;
    double b = (M/60)*360;
    double a = (H/12)*360 + 30*(M/60);
    double c = min(360-abs(a-b),abs(a-b));
    double C = A*A+B*B-2*A*B*cos(PI*c/180);
    printf("%.10f",sqrt(C));
    return 0;
}


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

static const int MAX = 100;

void selectionSort(int A[], int N)
{
	int tmp, count = 0;

	for (int i=0; i < N; i++) {
		int minj = i;
		for (int j=i; j < N; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
		if (i != minj) count++;
	}
	for (int i=0; i < N; i++) {
		if (i != N-1) cout << A[i] << " ";
		else cout << A[i] << endl;
	}
	cout << count << endl;
}

int main()
{
	int N, A[MAX];

	cin >> N;
	for (int i=0; i < N; i++) cin >> A[i];
	selectionSort(A, N);
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
)

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func max(nums []int) int {
	max := nums[0]
	for _, v := range nums {
		if max < v {
			max = v
		}
	}
	return max
}

func min(nums []int) int {
	min := nums[0]
	for _, v := range nums {
		if v < min {
			min = v
		}
	}
	return min
}

func main() {
	var n int
	fmt.Scan(&n)

	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}

	fmt.Println(abs(max(nums) - min(nums)))
}


Measured memory_bytes: 512
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)

	ans := 0
	for i := 0; i < n; i++ {
		x := getNextInt(scanner)
		if isPrime(x) {
			ans++
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func isPrime(num int) bool {
	for i := 2; i*i <= num; i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}



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

int A, B, C, X;
int main() {
	cin >> A >> B >> C >> X;
	int ans = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				if (500 * i + 100 * j + 50 * k == X) ans++;
			}
		}
	}

	cout << ans << endl;
}

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

using namespace std;
const int N=1e5+5;

int a[N][3];
int mem[N][3];

int n;

int vac(int day,int act)
{
    if (day==n)
        return 0;
    if(mem[day][act]!= -1)
        return mem[day][act];
    int ans=0;

    ans=max (ans,a[day][act]+ vac(day+1,(act+1)%3));
    ans=max (ans,a[day][act]+ vac(day+1,(act+2)%3));

    mem[day][act]=ans;
    return mem[day][act];
}

main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++)
        scanf("%d %d %d",&a[i][0], &a[i][1], &a[i][2]);
    memset(mem, -1, sizeof mem);

    int th1=vac(0,0);
    int th2=vac(0,1);
    int th3=vac(0,2);

    printf("%d\n",max(th1,max(th2,th3)));

    return EXIT_SUCCESS;
}


Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {

	static boolean[] prime;

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

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

		int ans = -2000000000;
		int min = R[0];
		for (int i=1; i<n; i++) {
			ans = Math.max(ans, R[i]-min);
			min = Math.min(min, R[i]);
		}

		System.out.println(ans);

		sc.close();
	}

}

Measured memory_bytes: 101308
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j][k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i-1][j-1])
  ans = dp[-1].max()
  return ans

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item))


Measured memory_bytes: 177380
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
	long long w,s,v;
	bool operator < (const struct node & n)const
	{
		return w+s>n.w+n.s;
	}
}NODE,*PNODE;
NODE a[1001];
long long f[20001];
int main()
{
	int n,i,j;
	long long maxx=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%lld%lld%lld",&a[i].w,&a[i].s,&a[i].v);
	sort(a+1,a+1+n);
	for(i=n;i>=1;i--)
	{
		maxx=max(maxx,a[i].v+f[a[i].s]);
		for(j=20001;j>=a[i].w;j--)
				f[j]=max(f[j],f[min(a[i].s,j-a[i].w)]+a[i].v);
	}
	printf("%lld",maxx);
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <cmath>

int main() {

  int N;
  int X;
  int T;

  std::cin >> N;
  std::cin >> X;
  std::cin >> T;

  std::cout << (int) (std::ceil((double) N / X) * T) << std::endl;

  return 0;

}


Measured memory_bytes: 3588
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	sum := 0
	if a != b {
		sum += 2
		if a != c && b != c {
			sum++
		}
	} else {
		sum++
		if a != c {
			sum++
		}
	}
	fmt.Println(sum)
}


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (string x : a) {
    cout << x;
  }
  return 0;
}

Measured memory_bytes: 3588
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;

int		main(void)
{
	int		H, N;
	cin >> H >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A.at(i);
	sort(A.begin(), A.end(), greater<int>());
	for (auto &i : A)
	{
		H -= i;
		if (H <= 0)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,ans=0,num=0;
	cin>>n;
	for(int i=1;pow(10,i)<=n*10;i+=2)
		ans+=(pow(10,i)-pow(10,i-1));
	int x=n;
	while(x)
	{
		x/=10;
		num++;
	}
	if(num&1)
		ans-=(pow(10,num)-n-1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n;
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> str;
	print1(n>=3200?str:"red");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100000
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mm(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
const LL mod=1e9+7;
const LL INF=(LL)1e18;
using namespace std;
struct node{
	int id;
	int val;
	node(int id,int val):id(id),val(val){}
};
int r,c,n;
vector<node>v[4];
bool check(int x,int y){
	if(x==0 || x==r || y==0 || y==c) return true;
	return false;
}
void push(int id,int x,int y){
	if(x==0) v[0].pb(node(id,y));
	else if(y==c) v[1].pb(node(id,x));
	else if(x==r) v[2].pb(node(id,y));
	else if(y==0) v[3].pb(node(id,x));
}
bool cmp1(node a,node b){
	return a.val<b.val;
}
bool cmp2(node a,node b){
	return a.val>b.val;
}
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("ouput.txt","w",sdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>r>>c>>n;
	for(int i=1;i<=n;i++){
		int x1,x2,y1,y2;
		cin>>x1>>y1>>x2>>y2;
		if(check(x1,y1) && check(x2,y2)){
			push(i,x1,y1),push(i,x2,y2);
		}
	}
	sort(v[0].begin(),v[0].end(),cmp1);
	sort(v[1].begin(),v[1].end(),cmp1);
	sort(v[2].begin(),v[2].end(),cmp2);
	sort(v[3].begin(),v[3].end(),cmp2);
	stack<int>s;
	for(int j=0;j<4;j++){
		for(int i=0;i<v[j].size();i++){
			if(s.size()==0) {
				s.push(v[j][i].id);
				continue;
			}
			if(s.top()==v[j][i].id) s.pop();
			else s.push(v[j][i].id);
		}
	}
	cout<<(s.empty()?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 2520
mod = 10 ** 9 + 7
N,M = map(int,input().split())
X = [1,1]
for i in range(N):
    X.append((X[i]+X[i+1]) % mod)
if M == 0:
    print(X[N])
else:
    a = int(input())
    ans = X[a - 1]
    #print(ans)
    tmp = a
    check = 0
    for _ in range(M-1):
        a = int(input())
        if a - tmp == 1:
            check = 1
        y = a - tmp - 2
        ans *= X[y]
        ans %= mod
        tmp = a
        #print(ans)
    y = N - tmp - 1
    ans *= X[y]
    ans %= mod 
    if check == 1:
        print(0)
    else:
        print(ans)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using i64 = long long;
using pll = pair<i64, i64>;

vector<pll> ivs;
i64 ant;

static i64 msb(i64 x) {
	if (!x) return 0;
	i64 t;

	for (t = 0; (1LL << t) <= x; ++t); --t;
	return 1LL << t; }

static void f(i64 a, i64 b) {
	i64 ma, mb;
	int t = 0;

	if (!b)	return;
	while (true) {
		ma = msb(a);
		mb = msb(b);

		if (a && b && ma == mb) {
			a-= ma;
			b-= mb; }
		else
			break; }

	ivs.emplace_back(a, b);
	if (!a) {
		ivs.emplace_back(0LL, 2 * mb - 1);
		return; }

	ivs.emplace_back(2 * mb - (mb - a), 2 * mb - 1);
	t = ivs.size();
	f(0, b - mb);
	for (int i = t; i < ivs.size(); ++i) {
		ivs[i].x+= mb;
		ivs[i].y+= mb; } }

int main() {
#ifdef HOME
	freopen("agc15d.in", "r", stdin);
	freopen("agc15d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 a, b, x, y;

	cin >> a >> b;

	f(a, b);
	sort(begin(ivs), end(ivs));

	x = ivs[0].x;
	y = ivs[0].y;
	for (auto i: ivs) {
		if (i.x <= y) {
			y = max(y, i.y); }
		else {
			ant+= y - x + 1;
			tie(x, y) = tie(i.x, i.y); } }
	ant+= y - x + 1;

	cout << ant << endl;

	return 0; }


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  int a[212345];
  int array[514690];

  for(int i = 0; i < n; ++i) cin >> a[i];
  int left = 212345, right=left+1;
  for(int i = 0; i < n; ++i) {
    if(i%2 == (n-1)%2) {
      array[left--] = a[i];
    } else {
      array[right++] =a[i];
    }
  }
  for(int i = left+1; i < right; ++i) {
    cout << array[i] << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 4480
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 char s[30],begin[150],end[150];
 ll len;
 map<string,ll>map;
 rep(i,0,n){
  sc(s);
  len=strlen(s);
  begin[i]=s[0];
  end[i]=s[len-1];
  if(map[s]!=0){
   pn;return 0;
  }
  map[s]++;
  if(i>0){
   if(begin[i]!=end[i-1]){
    pn;return 0;
   }
  }
 }
  py;  
return 0;}

Measured memory_bytes: 3636
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define pf(a)           printf("%lld\n", a)
#define sf(a)           scanf("%lld", &a)
#define line(a)         getline(cin,(a))
#define ll              long long int
#define MAX             2134567891
#define MID(l,r)        (l+r)>>1
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define per(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define T_C(t)          printf("Case %lld: ",t)
#define TC(t)           printf("Case %lld:\n",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb(a)           push_back(a)
#define ff              first
#define ss              second
#define MOD             1000000007///10^9
#define p6              1000007 ///10^6->6 zero after 1 **
#define hlw             printf("hlw\n");
#define SN              4*p6
#define NN              111
#define N               p6

ll R[N],G[N],C[N],n;
string s,S;
vector<ll>v;
//map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc,in,mod,loc,diff,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
    cin>>r>>g>>a>>b>>c;
    fr(i,a)cin>>R[i];
    fr(i,b)cin>>G[i];
    fr(i,c)cin>>C[i];

    sort(R,R+a, greater<int>());
    sort(G,G+b, greater<int>());
    sort(C,C+c, greater<int>());

    fr(i,r)v.pb(R[i]),ans+=R[i];
    fr(i,g)v.pb(G[i]),ans+=G[i];

    sort(ALL(v));
    for(i=0,j=0;i<v.size() && j<c && v[i]<C[j];i++,j++)
    {
        ans-=v[i];
        ans+=C[j];
    }
    cout<<ans<<endl;
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// long long or double? sqrt or division will work fine??


Measured memory_bytes: 12404
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include <iomanip>

using namespace std;

int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << std::fixed << std::setprecision(15) << W * H / 2 << " ";
    if(x == W/2 && y == H/2){
        cout << 1 << endl;
    }
    else cout << 0 << endl;
}


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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

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

	if(X == 3 || X == 5 || X == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}



Measured memory_bytes: 256
n=int(input())
l=[0]*n
for i in range(n):
    a=int(input())
    l[a-1]=i
cnt=1;ans=0
for i in range(1,n):
    if l[i-1]>l[i]:
        if cnt>ans:ans=cnt
        cnt=1
        continue
    cnt+=1
print(n-ans if ans!=0 else 0)


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

typedef long long ll;

ll N;
string A[] = {"pon", "pon", "hon", "bon", "hon",
              "hon", "pon", "hon", "pon", "hon"};

int main() {
  cin >> N;
  cout << A[N % 10] << endl;
  return 0;
}


Measured memory_bytes: 3604