akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int n;
    cin>>n;
    int k=n%10;
    if(k==3){
        cout<<"bon"<<endl;
    }else if(k==0||k==1||k==6||k==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
    
return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int cnt[250];
int main(){
	int n;cin>>n;
	for(int i=1;i<n+10;i+=2){
		for(int j=i;j<n+10;j+=i){
			cnt[j]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(cnt[i]==8)ans++;
	}
	cout<<ans<<endl;
}

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

int main() {
  int N,A,B,C,D;
  cin >> N >>A >>B >>C >>D;
  string S;
  cin >> S;
  int a,b;
  a=1;
  b=0;
  for(int i=A;i<C-1;i++){
    if(S.at(i)=='#' && S.at(i+1)=='#'){
      a=0;
    }
  }
  for(int i=B;i<D-1;i++){
    if(S.at(i)=='#' && S.at(i+1)=='#'){
      a=0;
    }
  }
  if(D<C){
    for(int i=B-2;i<D-1;i++){
      if(S.at(i)=='.' && S.at(i+1)=='.' && S.at(i+2)=='.'){
      b=1;
      }
    }
    if(b==0){
      a=0;
    }
  }


  if(a==1){
    cout << "Yes" <<endl;
  }

  if(a==0){
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 640
s = input()
n = len(s)

m = 2019
cnt = [0]*(m+1)

ans = 0
p = 1
cur = 0
for i in reversed(range(n)):
    cur += p*int(s[i])
    cur %= m
    p *= 10
    p %= m

    if cur == 0:
        ans += 1
    ans += cnt[cur]
    cnt[cur] += 1

print(ans)

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

typedef long long ll;

/* メモリ食い過ぎ注意 */
#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, m;
    int a[100000], b[100000];
    cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> a[i] >> b[i];

    vector<pair<int, int>> v;
    for (int i = 0; i < m; i++)
        v.push_back({b[i], a[i]});

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

    // for (int i = 0; i < v.size(); i++)
    // cout << v[i].second << "," << v[i].first << endl;
    int idx = 0;
    int cnt = 0;

    while (idx < v.size())
    {
        int tmp = v[idx].first;
        cnt++;
        for (int i = idx + 1; i < v.size(); i++)
        {
            if (v[i].second >= tmp)
            {
                idx = i;
                goto L;
            }
        }
        idx = v.size();
    L:
    {
    }
        // cout << idx << endl;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4980
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    if(A > B*2){
      System.out.println(A-B*2);
    }else{
      System.out.println(0);
    }
  }
}


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

int ans;
const int maxn = 1e5+5;
int cas=1;
int fa[maxn];
int Find(int x) {
    return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
priority_queue<int,vector<int>,greater<int> >q[maxn], pp;
int a[maxn];
int vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0 ; i < n ; i ++) fa[i] = i;
    for (int i = 0 ; i < n ; i ++) scanf("%d", a+i);
    for (int i = 1 ; i <= m ; i ++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u = Find(u);
        v = Find(v);
        fa[u] = v;
    }
    int k = 0;
    for (int i = 0 ; i < n ; i ++) {
        int tmp = Find(i);
        if (!vis[tmp]) {
            vis[tmp] = ++k;
            q[k].push(a[i]);
        }
        else q[vis[tmp]].push(a[i]);
    }
    if (k == 1) {
        printf("0\n");
        return 0;
    }
    ll ans = 0;
    for (int i = 1 ; i <= k ; i ++) {
        if (q[i].empty()) continue;
        ans += q[i].top();
        q[i].pop();
        while(!q[i].empty()) {
            pp.push(q[i].top());
            q[i].pop();
        }
    }
    int sum = k - 2;
    int flag = 1;
    while(sum--) {
        if (pp.empty()) {
            flag = 0;
            break;
        }
        ans += pp.top();
        pp.pop();
    }
    if (!flag) printf("Impossible\n");
    else printf("%lld\n", ans);
    return 0;
}

//#if def a = TreeNode(Exp a) then Preaise;

Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

#define rep(i, n)      for (int i=0; i<int(n); i++)
#define rep3(i, s, n)  for (int i=int(s); i<int(n); i++)
#define rev_rep(i, n)  for (int i=int(n)-1; i>=0; i-=1)

#define MAX_N 100010

int H, W, N;
typedef pair<int, int> P;
map<P, int> ctr;
long long ans[10];

int main() {
  cin >> H >> W >> N;
  for (int i=0; i<N; i++) {
    int a, b;
    cin >> a >> b;
    for (int xs=-1; xs<=1; xs++) {
      for (int ys=-1; ys<=1; ys++) {
        P p = P(b-1+xs, a-1+ys);
        if (p.first < 1    || p.second < 1 ||
            p.first >= W-1 || p.second >= H-1) {
          continue;
        }
        if (ctr.find(p) == ctr.end()) ctr[p] = 1;
        else ctr[p] += 1;
      }
    }
  }
  ans[0] = ((long)W-2)*((long)H-2);
  for (auto& kv : ctr) {
    ans[kv.second] += 1;
    ans[0] -= 1;
  }

  for (int i=0; i<10; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}



Measured memory_bytes: 42496
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

vll prime_number(ll max_n) {
	vector<bool> vb(max_n + 1, true);
	vb[0] = vb[1] = false;
	vll ret;
	for(ll i = 2; i <= max_n; i++) {
		if(!vb[i]) continue;
		for(ll j = 2 * i; j <= max_n; j += i) {
			vb[j] = false;
		}
	}
	for(ll i = 2; i <= max_n; i++) {
		if(vb[i]) ret.push_back(i);
	}
	return ret;
}

int solve() {
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll now = a[0];
    rep(i, n) now = __gcd(now, a[i]);
    if(now > 1) return 3;

    const ll amax = 1000000;
    vll vp = prime_number(amax);
    vll div(amax+1);    // 割り切れる最小の数. div[4]=div[6]=2等
    for(ll i = 2; i <= amax; i++) {
        for(int j : vp) {
            if(j > 1000) break;
            if(i % j != 0) continue;
            div[i] = j;
            break;
        }
        if(div[i] == 0) div[i] = i;
    }
    map<ll, ll> mp;
    rep(i, n) {
        ll b = a[i];
        set<ll> s;
        while(b > 1) {
            s.insert(div[b]);
            b /= div[b];
        }
        for(auto i = s.begin(); i != s.end(); ++i) {
            if(mp[*i] > 0) return 2;
            ++mp[*i];
        }
    }
    return 1;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int ans = solve();
    if(ans == 1) cout << "pairwise coprime" << endl;
    else if(ans == 2) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 19488
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

mean_temp = [t - x*0.006 for x in h]
tmp = 1e6
for i in range(n):
    if tmp > abs(mean_temp[i] - a):
        tmp = abs(mean_temp[i] - a)
        ans = i
print(ans+1)

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  
  ll x,y; cin>>x>>y;
  if (abs(x-y)<=1) out("Brown");
  out("Alice");

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
A = int(input())

# 500円のみで払える
if N / 500 == 0:
    print("Yes")
# 1円を使う
else:
    # 500の剰余を出して、手持ちの1円で払いきれるか判断
    mod = N % 500
    if A >= mod:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 2940
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = (x[-1] - x[0]) ** 2
for i in range(n - k + 1):
    xl = x[i]
    xr = x[i + k - 1]

    a = min(abs(xl) + abs(xr - xl), abs(xr) + abs(xl - xr))
    if a < ans:
        ans = a

print(ans)


Measured memory_bytes: 14252
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define mm 1000000007
int xx,yy,n,m,x,y,z,a,b,c,cc[300000],dd[300000],ff[300000];
char s[500000],ss[500000],g;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a);
		if (i%2==0) dd[a]++;
		else cc[a]++;
	}
	for (int i=1;i<=100000;i++) x=max(cc[i],x);
	for (int i=1;i<=100000;i++) if (cc[i]==x){
		a=i;
		break;
	}
	for (int i=1;i<=100000;i++) y=max(dd[i],y);	
	for (int i=1;i<=100000;i++) if (dd[i]==y){
		b=i;
		break;
	}
	if (b==a){
		for (int i=1;i<=100000;i++) if (i!=a)  xx=max(cc[i],xx);	
		for (int i=1;i<=100000;i++) if (i!=b)  yy=max(dd[i],yy);
		printf("%d\n",min(n-x-yy,n-y-xx));					
	}else
	printf("%d\n",n-x-y);
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  LL N;
  LL A[100000],B[100000];
  cin>>N;
  FOR(i,0,N){
    cin>>A[i]>>B[i];
  }
  LL C=0;
  ROF(i,0,N){
    A[i]+=C;
    if(A[i]%B[i]==0){
      continue;
    }else{
      C+=(A[i]+B[i]-1)/B[i]*B[i]-A[i];
    }
  }
  cout<<C<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void){
    int n, max=-101, min = 101;
    scanf("%d",&n);
    int a[101], c=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i!=0 && a[i-1] == a[i]){
            c++;
        }
        if(max < a[i]) max = a[i];
        if(min > a[i]) min = a[i];
    }
    if(c==n-1) {
        printf("0\n");
        return 0;
    }
    int cost, ans, t;
    for(int i=min;i<=max;i++){
    	cost = 0;
    	for(int k=0;k<n;k++){
    		t = abs(i-a[k]); 
    		cost += t*t;
    	}
    	if(i==min) ans = cost;
    	if(ans > cost) ans = cost;
    }
    
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

int const INF = 1e9;

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

struct state {
  int score_k;
  int type;
  int last[26];
  int score;
  std::vector<state>::iterator prev;
  bool operator< (state const& rhs) const { return score_k > rhs.score_k; } // reverse order
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  int const B = 840;
  int const K = 2;
  std::vector<int> t(D);
  
  std::vector<std::vector<state>> states(D+1);
  auto beam_step = [&](int d, int k) {
    auto& prev = states[d];
    auto& curr = states[d+1];
    curr.reserve(prev.size()*26);
    int dd = std::min(d+k, D-1);
    for(auto it = prev.begin(); it != prev.end(); ++it) {
      for(int T = 0; T < 26; ++T) {
        curr.push_back(*it);
        state& st = curr.back();
        st.prev = it;
        st.last[T] = d;
        st.type = T;
        st.score_k = st.score + s[d][T];
        for(int cx = 0; cx < 26; ++cx) {
          st.score_k -= c[cx]*(d+dd - 2*st.last[cx])*(dd-d+1)/2;
        }
      }
    }
    std::sort(curr.begin(), curr.end());
    if(curr.size() > B) curr.resize(B);
    for(auto& st: curr) {
      st.score += s[d][st.type];
      for(int cx = 0; cx < 26; ++cx) {
        st.score -= c[cx]*(d - st.last[cx]);
      }
    }
  };
  
  auto beam_search = [&](int k) {
    states.assign(D+1, std::vector<state>());
    states[0].emplace_back();
    states[0][0].score = 0;
    states[0][0].score_k = 0;
    std::fill_n(states[0][0].last, 26, -1);
    for(int d = 0; d < D; ++d) beam_step(d, k);
    auto it = states[D].begin();
    for(int d = D-1; d >= 0; it = it->prev, --d) {
      t[d] = it->type;
    }
  };
  beam_search(K);
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 994688
import collections
n,k = map(int,input().split())
line = list(input().split())
c = collections.Counter(line)
answer = 0
if k > len(c):
  answer = 0
else:
  gap = len(c) - k
  sorted_c = list(sorted(c.items(),key = lambda x:x[1]))
  for i in range(gap):
    answer += int(sorted_c[i][1])
print(answer)

Measured memory_bytes: 44056
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    { 
        
        static void Main(string[] args)
        {
            string s = ReadLine();
            if (s.Length < 4)
            {
                WriteLine("No");
            }
            else if (s.Substring(0,4) == "YAKI")
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(){
  int l,a[3];
  int i=0;
  while(cin>>l){
    a[i]=l;
    i++;
  }
  if(a[0]==a[1]+a[2]||a[1]==a[0]+a[2]||a[2]==a[1]+a[0]){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}
  

Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    pii a[110], b[110];
    scanf("%d", &n);
    rep(i, n) scanf("%d %d", &a[i].first, &a[i].second);
    rep(i, n) scanf("%d %d", &b[i].first, &b[i].second);

    sort(begin(a), begin(a) + n, [](pii x, pii y) {return x.first == y.first ? x.second > y.second : x.first < y.first;});
    sort(begin(b), begin(b) + n, [](pii x, pii y) {return x.first == y.first ? x.second > y.second : x.first < y.first;});

    multiset<int, greater<int>> s;
    int ai = 0;
    int ans = 0;
    rep(bi, n) {
        while (ai < n && a[ai].first < b[bi].first) {
            s.insert(a[ai].second);
            ai++;
        }
        auto it = s.upper_bound(b[bi].second);
        if (it != s.end()) {
            s.erase(it);
            ans += 1;
        }
    }

    print(ans);

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char s[500010];
int minDepth[500010];
int szS;

void extendLeft(int startPos)
{
	int p = startPos;
	int curNum = 0;
	if (minDepth[p] < curNum)
		minDepth[p] = curNum;
	p--;
	curNum++;
	
	while ((p >= 0) && (s[p] == '>'))
	{
		if (minDepth[p] < curNum)
			minDepth[p] = curNum;

		p--;
		curNum++;
	}
}

void extendRight(int startPos)
{
	int p = startPos;
	int curNum = 0;
	if (minDepth[p] < curNum)
		minDepth[p] = curNum;
	
	curNum++;
	while ((p < szS) && (s[p] == '<'))
	{
		if (minDepth[p + 1] < curNum)
			minDepth[p + 1] = curNum;

		p++;
		curNum++;
	}
}

int main()
{
	scanf("%s", s);
	szS = strlen(s);
	
	for (int i = 0 ; i <= szS ; i++)
		minDepth[i] = -1;
		
	if (s[0] == '<')
	{
		extendRight(0);
	}
	
	if (s[szS - 1] == '>')
	{
		extendLeft(szS);
	}
	
	
	for (int i = 1 ; i < szS ; i++)
	{
		if ((s[i - 1] == '>') && (s[i] == '<'))
		{
			extendLeft(i);
			extendRight(i);
		}
	}
	
	long long ans = 0;
	for (int i = 0 ; i <= szS ; i++)
		ans = ans + minDepth[i];
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 2560
from heapq import heappop,heappush
from collections import defaultdict

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

for _ in range(N):
  A, B = map(int, input().split())
  D[A].append(B)

H = []
ans = [0]*(M+1)

for i in range(1, M+1):
  for j in D[i]:
    heappush(H, -j)
  if H:
    a = heappop(H)
    ans[i] = -a

print(sum(ans))

Measured memory_bytes: 34160
n = int(input())
s = list(map(int, list(input())))

def aruka(a,b,c):
    i = 0
    while i <= n:
        if i == n:
            return False
        if s[i] == a:
            i += 1
            break
        i += 1
    while i <= n:
        if i == n:
            return False
        if s[i] == b:
            i += 1
            break
        i += 1
    while i <= n:
        if i == n:
            return False
        if s[i] == c:
            return True
        i += 1


ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if aruka(i,j,k):
                ans += 1

print(ans)



Measured memory_bytes: 43832
import java.util.*

fun main(args: Array<String>) {
    var sum = 0L
    var res = 0L

    val M = readLine()!!.toInt()

    for (i in 1 .. M) {
        val (d, c) = readLine()!!.split(" ").map{it.toLong()}

        sum += d * c
        res += c
    }

    res--

    res += (sum - 1) / 9

    println(Math.max(res, 1))
}


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

#define ub upper_bound
#define sum(a) accumulate(all(a),0ll)
#define lb lower_bound
#define all(v) begin(v),end(v)
#define allr(v) rbegin(v),rend(v)
#define sort_dec(v) sort(all(v),[](auto e1,auto e2){return e1>e2;})
#define For(n) for(ll i=0;i<n;i++)
#define Forj(n) for(ll j=0;j<n;j++)
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define Mp 1e9+7
#define vpll vector< pair<ll,ll> >
#define bug(n) {cout<<n;return;}
#define cont(n) {cout<<n<<endl;continue;}
#define pb push_back

ll n;
ll w[101],v[101];

ll dpArray[101][100001];

ll dp(ll i,ll W){
	if(i==n)return 0;
	if(w[i]>W)return dp(i+1,W);
	if(dpArray[i][W]!=-1)return dpArray[i][W];
	return dpArray[i][W]=max(dp(i+1,W-w[i])+v[i],dp(i+1,W));
}
 
void solve()
{
	// ll n;
	memset(dpArray,-1,sizeof(dpArray));
	ll W;
	cin>>n>>W;
	For(n)cin>>w[i]>>v[i];
	cout<<dp(0,W);
}
 
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	 
	// freopen("error.txt", "w", stderr);
	 
	int t=1;
	 
	while(t--)
	{
		solve();
	}

	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	 
	return 0;
}

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

int M, N;
const int MAX_N = 1001;
vector<int> A(MAX_N);
int main() {
    cin >> N >> M;
    double border = 1 / (4.0*M);
    int total = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        total += a;
        A[i] = a;
    }
    border = total * border;
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] >= border) {
            count++;
        }
    }
    if (count >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
def main():
    n = int(input())
    primes = get_primes_less_than(55556)
    out = []
    num = 0
    for prime in primes:
        if prime%5 == 1:
           out.append(prime)
           num += 1
        if n == num:
            print(*out)
            return

def get_primes_less_than(x):
    ans = []
    if x < 3:
        return ans
    if x == 3:
        ans.append(2)
        return ans
    else:
        for i in range(3, x, 2):
            flag = True
            for j in ans:
                if not i%j:
                    flag = False
                    break
            if flag:
                ans.append(i)
    return ans
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}



ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}

string S,T,U;
int a,b,c;
vi A,B,C;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    cin>>S;
    if(S == "ABC") {
        out("ARC");
    }else{
        out("ABC");
    }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(d - t * s <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main()
{
ll n , k ;
cin >> n >> k ;
if((k+k+2*n-1)*2*n/2>(k+2*n+k+3*n-1)*n/2){
cout << -1 << endl;
return 0;
}
ll a=k,b=(n+1)/2+n+k-1;
ll nu=0;
while(1){
  cout << a << " " << b << " " << k+2*n+nu << endl;
  a+=2;
  b--;
  nu++;
  if(a>=n+k)break;
}
a=k+1;
b=k+2*n-1;
while(1){
  if(a>=n+k)break;
  cout << a << " " << b << " " << k+2*n+nu << endl;
  a+=2;
  b--;
  nu++;
  if(a>=n+k)break;
}
return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
int main()
{
    int N,i,b,c,d;
    scanf("%d",&N);
    int a[N];
    for(i=0;i<N;i++)
        scanf("%d",&a[i]);
    b=0;c=0;
    for(i=0;i<N;i++){
        if(a[i]%4==0)
            b++;
        if(a[i]%2==0)
            c++;
    }
    d=(c-b)/2+b;
    if(d>=N/2)
            printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int n; cin >> n;
	int even = 0;
	rep(i, n){
		int t; cin >> t;
		if(t%2 == 1) even++;
	}
	
	if(even%2 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int N = scanner.nextInt();
			int min = scanner.nextInt();
			int max = scanner.nextInt();

			// 下限：上限をみて値をセットする
			List<Integer> integers = new ArrayList<Integer>();
			for (int i = 1; i <= N; i++) {
				int ans = 0;
				int tmp = i;
				for (; tmp > 0;) {
					ans += tmp % 10;
					tmp /= 10;
				}
				if (min <= ans && ans <= max) {
					integers.add(i);
				}
			}
			// 合計
			System.out.println(integers.stream().mapToInt(t -> t).sum());
		}
	}
}

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

const int  mod = 1000000007;
struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }
    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
    mint res(*this);
    return res/=a;
    }
};
 
int main(void){
    int n, m;
    cin>>n>>m;
    vector<ll> v(n);
    rep(i, n) cin>>v[i];
    sort(v.begin(), v.end());
    vector<mint> conb(n);
    conb[m-1] = 1;
    for(int i = m; i<=n-1;i++){
        conb[i] = conb[i-1]*i;
        conb[i] /= (i-m+1);
    }
    mint ans = 0;
    rep(r, 2){
        for(int i = m-1;i<=n-1;i++){
            mint tmp = conb[i];
            tmp *= v[i];
            if(r == 0) ans += tmp;
            else ans -= tmp;
        }
        reverse(v.begin(), v.end());
    }
    cout<<ans.x<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
ll dp[3005][3005]={};
void solve()
{
    int n,k=1,m=0,i=1,j,x,y,l,r,z;
    int ans=0,sum=0,value=0,weight;
    string s,t,answer;
    cin>>s>>t;
    n=s.size();
    m=t.size();
    int pos=0;
    for(i=n;i>=0;i--)
    {
        for(j=m;j>=0;j--)
        {
            if(i==n||j==m)
            {
                dp[i][j]=0;
                continue;
            }
            if(s[i]==t[j])
                dp[i][j]=1+dp[i+1][j+1];
            else
                dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
        }
    }
    ans=dp[0][0];
    string str;
    i=0,j=0;
    while(i<n&&j<m)
    {
            if(i<n&&j<m&&s[i]==t[j])
            {
                str+=s[i];
                i++;
                j++;
            }
            else if(dp[i+1][j]>dp[i][j+1])
            i++;
            else j++;
    }
    cout<<str;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 74056
ABCDE = []
for i in range(5):
    ABCDE.append(int(input()))
K = int(input())

out = 0
for i in range(5):
    for j in range(i+1,5):
        if ABCDE[j] - ABCDE[i] > K:
            out += 1
            break

if out == 0:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;



int main() {
  int r,d,x;
  cin >> r >> d >> x;
  
  
  REP(i,10){
    x = ((r*x) - d);
    cout << x << endl;
  }

  
}

Measured memory_bytes: 3596
def main():
    n, k = tuple([int(e) for e in input().split()])
    arr = [0] + [int(e) for e in input().split()]

    seen = set()
    actual = 1
    seen.add(1)
    pos = [1]
    mp = {1:1}
    while k > 0:
        actual = arr[actual]
        k -= 1
        if actual in seen:
            break
        seen.add(actual)
        pos.append(actual)
        mp[actual] = len(pos)

    c = 1 + len(pos) - mp[actual]
    k = k % c
    print(pos[mp[actual] + k - 1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 42204
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define ss cout << " ";
#define nn cout << "\n";
#define ct(x) cout << x;
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
const int maxn = 200200;

void solve(){

    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vec arr (n);
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int64 money = 1000;
    int64 stocks = 0;
    for (int i = 1; i < n; i++){
        if (arr[i] > arr[i-1]){
            money = (money / arr[i-1]) * arr[i] + money % arr[i-1];
        }
    }
    ctn(money);
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int part, day, rem;
    cin >> part >> day >> rem;

    int* a = new int[part];

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

    int count = 0;
    for (int i = 0; i < part; ++i) {
        int t = 0, j = 0;
        while (t < day) {
            t = j++ * a[i] + 1;
            if(t <= day) count++;
        }
    }
    cout << count + rem;
    return 0;
}

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

#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main() {
	sp;

	////////////////To Remove//////////////
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	///////////////////////////////////////

	int h, c;
	cin>>h>>c;
	vector<string> a(h);
	int top, left;
	vector<vector<int>> dp(h, vector<int>(c, INT_MAX));
	for(int i = 0; i < h; ++i) cin>>a[i];
	dp[0][0] = a[0][0] == '.' ? 0:1;
	for(int i = 1; i < h; ++i) dp[i][0] = dp[i-1][0] + (a[i][0] == '.' ? 0 : a[i-1][0] == '.' ? 1 : 0);
	for(int i = 1; i < c; ++i) dp[0][i] = dp[0][i-1] + (a[0][i] == '.' ? 0: a[0][i-1] == '.' ? 1 : 0);
	
	for(int i = 1; i < h; ++i){
		for(int j = 1; j < c; ++j){
			
			if(a[i][j] == '.') dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
			else if(a[i-1][j-1] == a[i-1][j] && a[i-1][j] == a[i][j-1]){
				if(a[i][j] == a[i-1][j]) dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1]));
				else dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + 1;
			}
			else{
				top = dp[i-1][j] + (a[i-1][j] == '.' ? 1 : 0);
				left = dp[i][j-1] + (a[i][j-1] == '.' ? 1 : 0);
				dp[i][j] = min(top, left);
			}
		}
	}

	// for(auto& row: dp){
	// 	for(auto&col:row){
	// 		cout<<col<<" ";
	// 	}
	// 	cout<<"\n";
	// }

	cout<<dp[h-1][c-1];
  return 0;
}

Measured memory_bytes: 384
/**
*    author:  yuya1234
*    created: 11.07.2020 21:02:26
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))

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

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

  int n;
  cin>>n;

  int a[n];
  REP(i,n)cin>>a[i];

  int cnt=0;
  REP(i,n)
  {
    if(i%2==0 && a[i]%2==1)cnt++;
  }

  cout<<cnt<<endl;

  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str;
  cin >> str;
  string temp=str;
  reverse(temp.begin(),temp.end());
  if(temp==str)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    Scanner sc = new Scanner(System.in);

    String s = sc.nextLine();
    String[] arr = s.split(" ", 0);

    for (int i = 0 ; i < arr.length ; i++){
      System.out.print(arr[i].substring(0,1));
    }

  }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
  char S[6];
  int counter = 0, i;
  scanf("%s", S);
  for(i = 0; i < 6; i++){
    if(S[i] == '1'){
      counter++;
    }
  }
  printf("%d\n", counter);
  return 0;
}


Measured memory_bytes: 128
a,b,c,k=map(int,input().split())
#sum=a*1+b*0-c*1
if a>=k:
    print(1*k)
if a<k and a+b>=k:
    print(1*(k-b))
if a<k and a+b<k and a+b+c>=k:
    print(a-(k-a-b))

Measured memory_bytes: 9112
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),l=sc.nextInt();
        int minabs=Integer.MAX_VALUE;
        int ans=0,finalans=0;
        for(int i=0;i<n;i++){
            ans+=l+i;
        }
        for(int i=0;i<n;i++){
            if(minabs>Math.abs(l+i)){
                finalans=ans-(l+i);
                minabs=Math.abs(l+i);
            }
        }
        System.out.println(finalans);
    }

}

Measured memory_bytes: 21844
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
long long n,h[K],a[K],dp[K],ans,be;
long long fi(long long hi)
{
	long long ret=0;
	while(hi>0)
	{
		ret=max(ret,dp[hi]);
		hi-=(hi&(-hi));
	}
	return ret;
}
void go(long long hi,long long b)
{
	while(hi<=n)
	{
		dp[hi]=max(dp[hi],b);
		hi+=(hi&(-hi));
	}
	return ;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		be=fi(h[i])+a[i];
		ans=max(ans,be);
		go(h[i],be);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;

void printArray(int *a,int n);

void swap(int &a,int &b){
	int temp = a;
	a = b;
	b = temp;
}

void bubbleSort(int *a,int n,int &count){
	bool flag = true; // reverse neighber exists
	while(flag == true){
		flag = false;
		for(int j = n - 1; j > 0; j--){
			if( a[j] < a[j-1]){
				swap(a[j],a[j-1]);
				count++;
				flag = true;
			}
		}
	}
}

void selectionSort(int *a,int n,int &count){
	for(int i = 0; i < n; i++){
		int minj = i;
		for(int j = i; j < n; j++){
			if(a[j] < a[minj]){
				minj = j;
			}
		}
		if( i != minj){
			swap(a[i],a[minj]);
			count++;
			//printArray(a,n);
		}
	}
}

void printArray(int *a,int n){
	cout<<a[0];
	if( n > 1){
		for(int i = 1; i < n; i ++){
			cout <<" "<<a[i];
		}
	}
	cout<<endl;
}


int main()
{
	int n;
	cin >> n ;
	int *targetArray = new int[n];
	for(int i = 0 ; i < n; i++) cin >> targetArray[i];
	int count = 0;
	selectionSort(targetArray,n,count);
	printArray(targetArray,n);
	cout<< count<<endl;
	delete[] targetArray;
	return 0;
}





Measured memory_bytes: 3116
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
using namespace std;

int main()
{
	int a;
	string str;

	cin >> a >> str;

	if (a < 3200)
		cout << "red";
	else cout << str;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define forn(a,n) for(int i = a; i < n; i++)
# define mod 10e9 + 7

using namespace std;

typedef long long int ll;
typedef vector<int> vec;
typedef vector<ll> vecl;
typedef unsigned long long int ull;
typedef vector<ull> vecu;


void print(const vec &a)
{
    forn(0,a.size())
        cout << a[i];
    cout << "\n";
}

int main()
{
    #ifdef WIN32
        freopen("input.txt", "r", stdin);
    #endif
    string s;
    cin >> s;
    if(s[s.size()-1] == 's')
        cout << s << "es";
    else
        cout << s << "s";
}

Measured memory_bytes: 3624
#include <stdlib.h>
#include <stdio.h>
#define min(a,b) a<b?a:b
int main()
{
    int n,k,i;
    long long t,ans=11451919810,x[1000001];
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%lld",&x[i]);
    }
    for(i=0;i<=n-k;i++){
        t=min((abs(x[i])+abs(x[i+k-1]-x[i])),(abs(x[i+k-1])+abs(x[i+k-1]-x[i])));
    ans=min(ans,t);    
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 998244353
#define EPS 0.00000001


ll power(ll a, ll e){
    if(e==0) return 1;
    if(e%2==0){
        ll r = power(a, e/2);
        return r * r % MOD;
    } else {
        ll r = power(a, e/2);
        return r * r % MOD * a % MOD;
    }
}

ll Inv(ll a){
    return power(a, MOD-2);
}

ll Fact(ll a){
    ll r = 1;
    for(int i=2; i<=a; i++)
        r = r * i % MOD;
    return r;
}


ll Combi(ll a, ll b){
    return Fact(a) % MOD * Inv(Fact(b)) % MOD * Inv(Fact(a-b)) % MOD;
}

ll N, A, B, K;
vector<ll> F;
ll solve(ll a, ll b){
    return F[a] % MOD * Inv(F[b]) % MOD * Inv(F[a-b]) % MOD;
}


int main(){
    cin >> N >> A >> B >> K;
    F.resize(N+1);
    ll ans = 0;
    F[0] = 1;
    for(int i=1; i<=N; i++){
        F[i] = F[i-1] * i % MOD;
    }
    
    for(ll i=0; i<=N; i++){
        ll j = (K - i * A)/B;
        if(j>=0 && j<=N && i*A + j*B == K){
            ans += solve(N, i) * solve(N, j) % MOD;
            ans %= MOD;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#define ALP 26
#define SIZE 55

using namespace std;
typedef long long int ll;

int cnt[ALP];
int mn[ALP];
char str[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<ALP;i++) mn[i]=SIZE;
	for(int i=0;i<n;i++)
	{
		scanf("%s",&str);
		int sz=strlen(str);
		memset(cnt,0,sizeof(cnt));
		for(int j=0;j<sz;j++) cnt[str[j]-'a']++;
		for(int j=0;j<ALP;j++) mn[j]=min(mn[j],cnt[j]);
	}
	string ret="";
	for(int i=0;i<ALP;i++)
	{
		for(int j=0;j<mn[i];j++)
		{
			char c='a'+i;
			ret+=c;
		}
	}
	printf("%s\n",ret.c_str());
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
int n,m,d,q,a,b,c,w[100000],x[100000],y[100000];
int main()
{
	cin>>n>>m>>d;
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++){
			cin>>a;a=a-1;
			x[a]=i;y[a]=j;
		}
	cin>>q;
	for (int i=d;i<100000;i++){
		w[i]=w[i-d];
		w[i]+=abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
	}
	for (int i=0;i<q;i++){
		cin>>b>>c;b=b-1;c-=1;
		cout<<w[c]-w[b]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int l=1,r=0,n,k; cin>>n>>k;
  vector<int> a(n,0);
  for(int i=0; i<n; ++i){cin>>a[i]; r=max(r,a[i]);}
  while(r>l){
    int x=(l+r)/2,c=0;
    for(int i=0; i<n; ++i) c+=(a[i]-1)/x;
    if(c<=k) r=x; else l=x+1;
  }
  cout<<r;
  return 0;
}


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

int main() {
	string S; cin >> S;
	string S1 = S.substr(0, 2); int V1 = stoi(S1);
	string S2 = S.substr(2, 2); int V2 = stoi(S2);
	
	int cnt = 0;
	if (V1 >= 1 && V1 <= 12) cnt += 1;
	if (V2 >= 1 && V2 <= 12) cnt += 2;
	if (cnt == 0) cout << "NA" << endl;
	if (cnt == 1) cout << "MMYY" << endl;
	if (cnt == 2) cout << "YYMM" << endl;
	if (cnt == 3) cout << "AMBIGUOUS" << endl;
	return 0;
}

Measured memory_bytes: 256