akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    int N; cin >> N;
    int topB = 0, botA = 0;
    ll ans = 0;
    bool non = true;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        if (s[0] == 'B' ^ s[s.length()-1] == 'A') non = false;
        if (s[0] == 'B') topB++;
        if (s[s.length()-1] == 'A') botA++;
        for (int i = 0; i < s.length()-1; i++) {
            if (s[i] == 'A' && s[i+1] == 'B') ans++;
        }
    }
    cout << ans + (min(topB, botA)) - (int)(topB == botA && non && topB > 0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main ()
{
  int x,i,len_s,x_stay;
  int x_min = 1000;
  char s[11];
  scanf("%s",s);
  for(len_s=0;s[len_s]!='\0';len_s++);
  for(i=0;i<=len_s-3;i++){
    x=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    x_stay=abs(753-x);
    x_min=(x_min>x_stay)?x_stay:x_min;
  }
  printf("%d",x_min);
  return 0;
}

Measured memory_bytes: 128
N,S=map(int,input().split())
A=[int(i) for i in input().split()]
mod=998244353
dp=[[0 for j in range(S+1)]for i in range(N+1)]
pow2N=pow(2,N,mod)
dp[0][0]=pow2N
inv2=pow(2,mod-2,mod)
for i in range(N):
    for j in range(S+1):
        if dp[i][j]!=0:
            dp[i+1][j]+=dp[i][j]
            dp[i+1][j]%=mod
            if j+A[i]<=S:
                dp[i+1][j+A[i]]+=(inv2*dp[i][j])%mod
                dp[i+1][j+A[i]]%=mod
print(dp[N][S])

Measured memory_bytes: 146988
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N=S.size();
  vector<char> q;
  for(int i=0;i<N;i++){
    q.push_back(S.at(i));
  }
  int ans1=0;
  int ans2=0;
  vector<char> a,b;
  for(int j=0;j<N;j++){
    if(j%2==0){
      a.push_back('1');
    }else{
      a.push_back('0');
    }
  }
  for(int k=0;k<N;k++){
    if(k%2==0){
      b.push_back('0');
    }else{
      b.push_back('1');
    }
  }
  for(int l=0;l<N;l++){
    if(q.at(l)!=a.at(l)){
      ans1++;
    }
  }
  for(int m=0;m<N;m++){
    if(q.at(m)!=b.at(m)){
      ans2++;
    }
  }
  cout << min(ans1,ans2) << endl;
}

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

int mark[30], n, a;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++){
		char c;
		cin >> c;
		mark[(c - 'A')]++;
	}	
	for (int i = 0; i < 30; i++)
		a += (mark[i] > 0);
	
	if(a == 3)
		cout << "Three";
	else
		cout << "Four";
	
}



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

using namespace std;

int main(){
    char a;
    cin >> a;
    int Ac = (int)('A');
    int Zc = (int)('Z');
    int ac = (int)('a');
    int zc = (int)('z');

    if(ac<=(int)a && (int)a<=zc) cout << 'a' << endl;
    else cout << 'A' << endl;

    return 0;
}


Measured memory_bytes: 3564
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    string s; cin >> s;
    vector<int> cnt(26);
    for(size_t i=0; i<s.size(); i++) {
        cnt[ s[i] - 'a' ]++;
    }

    int odd_cnt = 0;
    for(int i=0; i<26; i++) odd_cnt += (cnt[i] % 2);
    cout << max(0, odd_cnt / 2) << endl;
    return 0;
}



Measured memory_bytes: 3212
#include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int n;

  while ( cin >> n )
    {
      unique_ptr<int[]> tbl(new int[n+1]);
      for ( int i = 2; i <= n; i++ )
        tbl[i] = 1;

      for ( int i = 2; i <= n; i++ )
        if ( tbl[i] == 1 )
          {
            int j = i * 2;
            while ( j <= n )
              {
                tbl[j] = 0;
                j += i;
              }
          }

      int ret = 0;
      
      for ( int i = 2; i <= n; i++ )
        ret += tbl[i];

      cout << ret << endl;
    }
  
  return 0;
}

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


int main() {
  int x, y;
  cin >> x >> y;
  if (x <= 8 && y <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
	ll i,j,k,m,n;
	string s,t;
	cin>>s>>t;
	n=t.length()-1;
	string a="";
	fl(i,n) {
		a+=t[i];
	}
	if(s==a) cout<<"Yes\n";
	else cout<<"No\n";
}

int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
 
ll power(ll a, ll b){//a^b
    ll res=1;
    while(b>0){
        if(b&1){res=(res*a);b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}
vl dp(100005,-1);
vl h(100005);
ll k;
ll jump(ll i){
	if(dp[i]!=-1)
		return dp[i];
	if(i==1){
		dp[1]=0;
		return dp[i];
	}
	ll mi=jump(i-1)+abs(h[i]-h[i-1]);
	for(ll j=2;j<=k;j++){
		if(i-j<1)
			break;
		mi=min(mi,jump(i-j)+abs(h[i]-h[i-j]));
	}
	dp[i]=mi;
	return dp[i];
} 
 
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	
	cin>>k;
	for(ll i=1;i<=n;i++)
		cin>>h[i];
	cout<<jump(n)<<"\n";
}

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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  int x_a = abs(x - a);
  int x_b = abs(x - b);
  if(x_a > x_b){
    cout << "B" << endl;
  }else{
    cout << "A" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t)printf("Yes");
    else printf("No");
    return 0;
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[]args)throws Exception{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     String []wd=br.readLine().split(" ");
     int m2=0,m1=0,a2=0,a1=0; 
     for(int i=0;i<wd.length;i++){
    	 int temp=0;
    	 for(int k=i+1;k<wd.length;k++) if(wd[i].equals(wd[k]))temp++;
    	 if(m1<temp){m1=temp; a1=i; }
    	 if(m2<wd[i].length()){m2=wd[i].length(); a2=i;}
    	 }
     System.out.println(wd[a1]+" "+wd[a2]);
    }
}

Measured memory_bytes: 16896
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define vcin(V) for (int i = 0; i < (V).size(); i++) { cin >> (V).at(i); }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define nn int n=0
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool; 
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}
//BEGIN OF CODE.
int main(void){
	int a, b;
	cin >> a >> b;
	string s, t;
	s = to_string(a);
	t = to_string(b);
	string aa, bb;
	rep(i, b) {
		aa += s;
	}
	rep(i, a) {
		bb += t;
	}
	if (a < b) {
		cout << aa << rt;
	}
	else if (a == b) {
		cout << aa << rt;
	}
	else cout << bb << rt;
	please AC;
}
//THE END.

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)























int main(){
    ll Q;
    cin >> Q;
    
    priority_queue<ll> que1;
    priority_queue<ll, vector<ll>, greater<ll>> que2;
    
    ll sum1 = 0, sum2 = 0, bb = 0;
    
    REP(i, Q){
        ll q;
        cin >> q;
        if(q == 1){
            ll a, b;
            cin >> a >> b;
            bb += b;
            
            if(que1.empty()){
                que1.push(a);
                continue;
            }
            if(que2.empty()){
                que1.push(a);
                que2.push(que1.top());
                que1.pop();
                sum2 += que2.top() - que1.top();
                continue;
            }
            
            ll t1 = que1.top(), t2 = que2.top();
            if(a < t2){
                if(t1 < a){
                    sum1 += (a - t1) * que1.size();
                    sum2 -= (a - t1) * que2.size();
                    que1.push(a);
                }
                else{
                    sum1 += t1 - a;
                    que1.push(a);
                }
                
                if(que1.size() > que2.size() + 1){
                    ll t3 = que1.top(); que1.pop();
                    ll t4 = que1.top();
                    sum1 -= (t3 - t4) * que1.size();
                    que2.push(t3);
                    sum2 += (t3 - t4) * que2.size();
                }
            }
            else{
                sum2 += a - t1;
                que2.push(a);
                if(que1.size() < que2.size()){
                    sum2 -= (t2 - t1) * que2.size();
                    sum1 += (t2 - t1) * que1.size();
                    que1.push(t2);
                    que2.pop();
                }
            }
        }
        else{
            cout << que1.top() << " " << sum1 + sum2 + bb << endl;
        }
    }
}

Measured memory_bytes: 3828
//
// Created by yamunaku on 2019/11/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n,k;
    cin >> n >> k;
    int h;
    int ans=0;
    rep(i,n){
        cin >> h;
        if(h>=k) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

int dp[410][410];

void solve() {
  rep(i, 410) rep(j, 410) dp[i][j] = 1e9;
  dp[0][0] = 0;

  int N, Ma, Mb; cin >> N >> Ma >> Mb;
  vi32 a(N), b(N), c(N);
  rep(i, N) cin >> a[i] >> b[i] >> c[i];
  
  rrep(i, N) rrep(j, 410) rrep(k, 410) {
    if (dp[j][k] == 1e9) continue;
    amin(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
  }

  int ans = 1e9;
  reps(i, 400) {
    if (i * Ma > 400 || i * Mb > 400) break;
    amin(ans, dp[i * Ma][i * Mb]);
  }
  if (ans == 1e9) cout << -1 << '\n';
  else cout << ans << '\n';
}


Measured memory_bytes: 896
///
// File:  d.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 31 17:45:55 2017
//

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(uint32_t n)
{
  for (uint32_t i = 2; i <= (uint32_t)sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

int32_t main()
{
  vector<uint32_t> like2017;
  for (uint32_t i = 2; i < 100000; i++) {
    if (i % 2 == 1) {
      if (is_prime(i) && is_prime((i + 1) / 2)) {
        like2017.push_back(i);
      }
    }
  }

  uint32_t Q;
  cin >> Q;

  for (uint32_t i = 0; i < Q; i++) {
    uint32_t n, m;
    cin >> n >> m;
    cout << upper_bound(like2017.begin(), like2017.end(), m) - lower_bound(like2017.begin(), like2017.end(), n) << endl;
  }
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>

using namespace std;

typedef long long int ll;

const ll INF = 1e12;

int main()
{
  int n, W;

  cin >> n >> W;

  vector <int> w(n+1, 0);
  vector <int> v(n+1, 0);

  int V = 0;
  for (int i = 1; i <= n; i++)
  {
    cin >> w[i] >> v[i];

    V += v[i];
  }

  ll dp[V+1][n+1];

  for (int i = 0; i <= V; i++)
  {
    for (int j = 0; j <= n; j++)
    {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;

  for (int i = 0; i <= V; i++)
  {
    for (int j = 1; j <= n; j++)
    {
      if (v[j] <= i)
      {
        dp[i][j] = min(dp[i][j], dp[i-v[j]][j-1] + w[j]);
      }
      dp[i][j] = min(dp[i][j], dp[i][j-1]);
    }
  }

  int ans = 0;

  for (int i = 0; i <= V; i++)
  {
    for (int j = 1; j <= n; j++)
    {
      if (dp[i][j] == INF)
        continue;

      if (dp[i][j] <= W)
        ans = i;
    }
  }

  cout << ans << "\n";
  
  return 0;
}


Measured memory_bytes: 79104
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

const int N = 2e3 + 10;
int d[N];
vector<int> a[N];

int solve_even(int bound, int n) {
  int ret = INF;
  for (int i = 0; i < n; ++i) {
    queue<int> Q;
    Q.push(i);
    fill(d, d + n, -1);
    d[i] = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (auto& v : a[u]) {
        if (d[v] >= 0) continue;
        d[v] = d[u] + 1;
        Q.push(v);
      }
    }
    int cnt = 0;
    for (int j = 0; j < n; ++j) {
      if (d[j] > bound) ++cnt;
    }
    ret = min(ret, cnt);
  }
  return ret;
}

int solve_odd(int bound, int n) {
  int ret = INF;
  for (int i = 0; i < n; ++i) {
    for (auto& j : a[i]) {
      queue<int> Q;
      Q.push(i);
      Q.push(j);
      fill(d, d + n, -1);
      d[i] = d[j] = 0;
      while (!Q.empty()) {
        int u = Q.front();
        Q.pop();
        for (auto& v : a[u]) {
          if (d[v] >= 0) continue;
          d[v] = d[u] + 1;
          Q.push(v);
        }
      }
      int cnt = 0;
      for (int j = 0; j < n; ++j) {
        if (d[j] > bound) ++cnt;
      }
      ret = min(ret, cnt);
    }
  }
  return ret;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  if (m % 2 == 0) {
    printf("%d\n", solve_even(m / 2, n));
  } else {
    printf("%d\n", solve_odd(m / 2, n));
  }
  return 0;
}


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


int main()
{
	int N,H;
	cin>>N>>H;
	vector<pair<int,int>> ab(N,make_pair<int,int>(-1,-1));
	rep(i,N)
	{
		cin>>ab[i].first>>ab[i].second;
	}
	sort(ab.begin(),ab.end(),[](auto const &x,auto const &y){
			return x.first>y.first;
			});
	pair<int,int> best=ab[0];
	vector<int> throw_sord;
	throw_sord.push_back(best.second);
	for(int i=1;i<N;i++)
	{
		if(best.first<=ab[i].second)
		{
			throw_sord.push_back(ab[i].second);
		}
	}
	sort(throw_sord.begin(),throw_sord.end(),greater<int>());
	int ans=0;
	for(int s : throw_sord)
	{
		H-=s;
		ans++;
		if(H<=0) break;
	}
	if(H<=0)
	{
		cout<<ans<<endl;
	}
	else
	{
		cout<<ans+(H+best.first-1)/best.first<<endl;
	}
	return 0;
}


Measured memory_bytes: 4688
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
	string s;
	cin >> s;
	bool mf=false,ms=false;
	int n=atoi(s.substr(0,2).c_str());
	if(0<n && n<=12) mf=true;
	n=atoi(s.substr(2,2).c_str());
	if(0<n && n<=12) ms=true;
	if(mf&&ms) cout << "AMBIGUOUS" << endl;
	else if(mf) cout << "MMYY" << endl;
	else if(ms) cout << "YYMM" << endl;
	else cout << "NA" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N=scan.nextInt();
        int M=scan.nextInt();
        int i,sum=0;
        for(i=0;i<M;i++){
            int A=scan.nextInt();
            sum=sum+A;
        }
        int result=N-sum;
        if(result>=0){
            System.out.println(result); 
        }
        else{
            System.out.println("-1");
        }
    }
}

Measured memory_bytes: 37964
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    if (k >= 2){
        int max = n - k +1;
        int min = 1;
        cout << max - min << endl;
    }
    else{
        cout << 0 <<endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
light = [0] * M
switch = []
for i in range(M):
    ks = list(map(int, input().split()))
    light[i] = ks[0]
    switch.append(ks[1:])
P = list(map(int, input().split()))

count = 2 ** N
for i in range(2 ** N):
    switch_state = [0] * N
    for j in range(N):
        if ((i >> j) & 1):
            switch_state[j] = 1
    for m in range(M):
        point = 0
        for s in switch[m]:
            point += switch_state[s-1]
        if point %2 != P[m]:
            count -= 1
            break
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
typedef long long ll;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	ll q, h, s, d;
	ll n;
	cin >> q >> h >> s >> d >> n;
	double qq = n;
	
	ll qhc = 2 * q;
	ll qsc = 4 * q;
	ll qdc = 8 * q;

	ll hsc = 2 * h;
	ll hdc = 4 * h;

	ll sdc = 2 * s;
	ll c = 0;

	if (qq >= 2) {
		ll mn = min(qdc, hdc);
		mn = min(mn, sdc);
		mn = min(mn, d);
		int qa = qq / 2;
		qq -= qa * 2;
		c += qa * mn;
	}

	if (qq >= 1) {
		ll mn = min(qsc, hsc);
		mn = min(mn, s);
		int qa = qq / 1;
		qq -= qa;
		c += qa * mn;
	}

	if (qq >= 0.5) {
		ll mn = min(qhc, h);
		double qa = qq / 0.5;
		qq -= qa * 0.5;
		c += qa * mn;
		cout << qq << ":" << c << endl;
	}

	if (qq >= 0.25) {
		ll mn = q;
		double qa = qq / 0.25;
		qq -= qa * 0.25;
		c += qa * mn;
		cout << qq << ":" << c << endl;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int a,b,c,d;
    
    scanf("%d",&a);
    
    b=a/3600;
    c=(a/60)-(b*60);
    d=a%60;

    printf("%d:%d:%d\n",b,c,d);
    
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	double sum = 0;
	VE a(n);
	rep(i, n) {
		cin >> a[i]; sum += a[i];
	}
	sum /= n;
	double ans = INF;
	rep(i, n) {
		chmin(ans, (double)abs(sum - a[i]));
	}
	rep(i, n) {
		if ((double)abs(sum - a[i]) == ans) {
			cout << i << endl; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    const ll p1 = 673;
    const ll p2 = 3;

    vl rui1(n+1);
    ll ten1 = 1;
    for(ll i = n-1; i >= 0; i--) {
        ll x = (s[i] - '0')*ten1%p1;
        rui1[i] = (rui1[i+1] + x)%p1;
        ten1 *= 10;
        ten1 %= p1;
    }

    vl rui2(n+1);
    ll ten2 = 1;
    for(ll i = n-1; i >= 0; i--) {
        ll x = (s[i] - '0')*ten2%p2;
        rui2[i] = (rui2[i+1] + x)%p2;
        ten2 *= 10;
        ten2 %= p2;
    }

    map<pair<ll, ll>, ll> mp;
    ll ans = 0;
    for(ll i = n; i >= 0; i--) {
        ll a = rui1[i];
        ll b = rui2[i];
        ans += mp[make_pair(a, b)];
        mp[make_pair(a, b)]++;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 6772
// C - Digits in Multiplication
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll ans = 0, b = 0, N; cin>>N;
	for(ll a=1; a*a<=N; a++) if(N%a==0) b = N/a;
	while(b){ b /= 10; ans++; }
	cout<< ans <<endl;
}

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

bool is_ACGT(char s);

int main() {
    string S;
    cin >> S;
    int count, max = 0;
    for (int i = 0; i < S.length(); i++) {
        if (is_ACGT(S[i])) {
            count++;
            if (count > max) {
                max = count;
            }
            else {}
        }
        else {
            count = 0;
        }
    }
    cout << max << endl;
    return 0;
}

bool is_ACGT(char s) {
    if (s == 'A' || s == 'C' || s == 'G' || s == 'T') {
        return true;
    }
    else {
        return false;
    }
}


Measured memory_bytes: 256
H, W, K = gets.split.map(&:to_i)
S = readlines.map{|l| l.chomp.chars.map(&:to_i)}

@s = S.map{|a| a.each_with_object([0]){|e, o| o << o.last + e}}
as = Enumerator.new do |y|
  (0 .. H).each do |n|
    [*1 ... H].combination(n){|c| y << [0, *c, H].each_cons(2).map{|i, j| @s[i ... j]}}
  end
end
mi = ->(x){@m ||= 10**10; @m = x if @m > x}
ok = ->(a, i, j){a.all?{|b| b.inject(0){|r, e| r +e[j + 1] - e[i]} <= K}}
as.each do |s|
  i = 0
  ct = s.size - 1
  next if  (0 ... W).any? do |j|
    unless ok[s, i, j]
      ct += 1
      i = j
      !ok[s, j, j]
    end
  end
  mi[ct]
end
puts @m

Measured memory_bytes: 4220
package main

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

/*-----------Main-----------*/

func main() {
	x := readI()

	for a := -1000; a < 1000; a++ {
		for b := -1000; b < 1000; b++ {
			if pow(a, 5)-pow(b, 5) == x {
				fmt.Println(a, b)
				return
			}
		}
	}
}

func pow(a, b int) int {
	c := 1
	for i := 0; i < b; i++ {
		c *= a
	}
	return c
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-2.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

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

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

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

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1808
(set! *unchecked-math* true)
(defn input []
  (let [[N M] (->> (clojure.string/split (read-line) #"\s")
                (map #(Integer/parseInt %)))]
    (list N M
      (->> (repeatedly M read-line)
        (sequence
          (comp (map #(clojure.string/split % #"\s"))
            (map (partial mapv #(Integer/parseInt %)))))))))

(defn CoutningRoads [^"[I" Array Rs]
  (doseq [r Rs
          :let [id1 (unchecked-dec-int (r 0))
                id2 (unchecked-dec-int (r 1))]]
    (do
      (->> (aget ^"[I" Array id1)
        unchecked-inc-int
        (aset ^"[I" Array id1))
      (->> (aget ^"[I" Array id2)
        unchecked-inc-int
        (aset ^"[I" Array id2)))))

(defn output [^"[I" Array]
  (->> Array
    (transduce (map #(format "%s\n" %)) str "")
    print))

(let [[N _ Rs] (input)]
  (doto (int-array N (int 0))
    (CoutningRoads Rs)
    (output)))

Measured memory_bytes: 69756
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int cnt = 0;
int N, M;
bool graph[60][60];
bool visited[60];
int a[50], b[50];
void dfs(int v){//頂点vを訪れる
    visited[v] = true;//頂点v訪問済み
    rep(v2, N){
        //頂点v2: 頂点vに隣接している　かつ　未訪問
        if(graph[v][v2] == false) continue;//以下スキップ
        if(visited[v2] == true) continue;//以下スキップ
        dfs(v2);
    }
}
void dfs2(int x){
    if(visited[x]) return;
    visited[x] = true;
    rep(i, N) if(graph[x][i]) dfs2(i);
}

int main(){
    cin >> N >> M;
    rep(i, M){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    rep(i, M){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        rep(j, N) visited[j] = false;
        dfs(0);//頂点0から辿る事が可能なところに印をつける
        bool bridge = false;
        rep(j, N) if(visited[j] == false) bridge = true;//未訪問なら
        if(bridge) ans += 1;
        
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int main()
{
  init_main();

  ll a, b, n;
  cin >> a >> b >> n;
  /*
  for (ll i = 0; i <= 100; i++)
  {
    cout << i << ":" << (a * i) / b - a * (i / b) << endl;
  }*/
  if (n >= b - 1)
  {
    ll i = b - 1;
    cout << (a * i) / b - a * (i / b) << endl;
  }
  else
  {
    cout << (a * n) / b - a * (n / b) << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
int T[20][20],X,Y,x,y,p,q,i,c;
#define t T[y][x]
void R(x,y){(0<=x&&x<X&&0<=y&&y<Y&&!t)?t=1,i++,R(x-1,y),R(x+1,y),R(x,y-1),R(x,y+1):0;}
main(){for(;scanf("%d%d",&X,&Y),X;printf("%d\n",i)){
	for(i=0;i<X*Y;i++){
		for(x=i%X,y=i/X;(c=getchar())=='\n';);
		switch(c){
			case'@':p=x;q=y;
			case'.':t=0;break;
			case'#':t=1;
		}
	}
	i=0;R(p,q);
}exit(0);}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<map>

using namespace std;

int N,i,j,k;

string S;

map<string,int> mp;

int main()
{
  cin >> N;
  
  for(i=0;i<N;i++)
  {
    cin >>S;
    mp[S]+=1;
    
  }
  
  k=0;
  
  for(auto e:mp)
  {
    j=e.second;
    k=max(k,j);
  }
  
  for(auto e:mp)
  {
    j=e.second;
    if(j==k)
    {
      cout << e.first << endl;
    }
  }
  

  
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
 int main(){
    int n;
    cin >> n;
    vector<int>a;
    for(int i=0; i<n; ++i){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    } 
    sort(a.begin(), a.end());
    cout << abs(a[n-1]-a[0]) << endl;
}

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

int main(){
  int N,D,X;
  cin >> N >> D >> X;
  int a[100];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int ans = X;
  for(int i=0;i<N;++i){
    int tmp = (D-1)/a[i] +1;
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)
static const int INF = (1 << 29);
static const int dx[] = {1,-1,0,0};
static const int dy[] = {0,0,1,-1};

struct State{
   int x,y,t,sum,unvisit;
   State(int x, int y, int t, int s, int v):x(x),y(y),t(t),sum(s),unvisit(v){};
};

struct Goods{
   int price,s,e;
   Goods(){}
   Goods(int p, int s, int e):price(p),s(s),e(e){};
};

int h,w,n;
int sx,sy;
int G[20][20];
Goods goods[10];
bool visited[20][20][(1 << 10)][101];

int bfs(){
   memset(visited,false,sizeof(visited));  int ans = 0;
   queue<State> q;
   q.push(State(sx, sy, 0, 0, (1<<10)-1));

   while(!q.empty()){
      State s = q.front(); q.pop();
      if(s.t > 100)continue;
      if(visited[s.x][s.y][s.unvisit][s.t])continue;
      visited[s.x][s.y][s.unvisit][s.t] = true;
      ans = max(ans, s.sum);
      rep(k,4){
    	 int nx = s.x + dx[k];int ny = s.y + dy[k];
    	 if(0<=nx&&nx<h && 0<=ny&&ny<w && G[nx][ny]!=-1){
	     int num = G[nx][ny];
	     if((s.unvisit >> num) & 1){
	        if(goods[num].s <= s.t && s.t < goods[num].e){
		  s.sum += goods[num].price;
		  s.unvisit = s.unvisit & ~(1 << num);
	       }
	    }
	   }
      }

     rep(k,4){
	 int nx = s.x + dx[k]; int ny = s.y + dy[k];
	 if(0<=nx&&nx<h && 0<=ny&&ny<w && G[nx][ny]==-1){
	    q.push(State(nx, ny, s.t+1, s.sum, s.unvisit));
	 }
      }
   }
   return ans;
}

void input(){
   rep(i,h){rep(j,w){char c;cin >> c;
	 if(c=='P'){sx = i;sy = j;G[i][j] = -1;}
	 else if(c=='.')G[i][j] = -1; else G[i][j] = (int)(c - '0');}
   }
   cin >> n;
   rep(i,n){int g,d,s,e; cin >> g >> d >> s >> e;
      goods[g] = Goods(d,s,e);
   }
}

int main(){
   while(cin >> w >> h){
      if(w==0 && h==0)break;
      input();
      cout << bfs() << endl;
   }
   return 0;
}

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

int main() {
  string S;
  cin >> S;
  if(S == "SSS"){cout << 0 << endl;}
  else if(S == "SSR"){cout << 1 << endl;}
  else if(S == "SRS"){cout << 1 << endl;}
  else if(S == "RSS"){cout << 1 << endl;}
  else if(S == "RRS"){cout << 2 << endl;}
  else if(S == "RSR"){cout << 1 << endl;}
  else if(S == "SRR"){cout << 2 << endl;}
  else{cout << 3 << endl;}
}


Measured memory_bytes: 3628
#include<bits/stdc++.h> 
using namespace std; 
  
void CountTriangles(vector <int> A){  
  
    int n=A.size(); 
  
    sort(A.begin(), A.end());  
  
    int count = 0; 
      
    for( int i = n-1; i >= 1; i--){ 
        int l = 0, r = i-1; 
        while( l < r){ 
            if( A[l] + A[r] > A[i]){ 
                count += r - l ;  
                r--;   
            } 
            else 
                l++;   
        } 
    } 
    cout<<count; 
} 
int main(){ 
  	int n;
  	cin>>n;
  	vector<int> arr;
  	for(int i=0;i<n;i++)
  	{
  		int a;
  		cin>>a;
  		arr.push_back(a);
	  }
    CountTriangles(arr);
	return 0; 
    
}  

Measured memory_bytes: 256
n, q = [ int( val ) for val in raw_input( ).split( " " ) ]
ps = [0]*n
t = [0]*n
for i in range( n ):
	ps[i], t[i] = raw_input( ).split( " " )


output = []
qsum = 0
while t:
	psi = ps.pop( 0 )
	ti = int( t.pop( 0 ) )
	if ti <= q:
		qsum += ti	
		output.append( psi+" "+str( qsum ) )
	else:
		t.append( ti - q )
		ps.append( psi )
		qsum += q

print( "\n".join( output ) )

Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
double dp[301][301][301];
double n;
double dfs(int i,int j,int k){
    if(dp[i][j][k]!=0)return dp[i][j][k];
    if(i+j+k==0)return 0;
    if(i)dp[i][j][k]+=(dfs(i-1,j,k)+n/(i+j+k))*i/(i+j+k);
    if(j)dp[i][j][k]+=(dfs(i+1,j-1,k)+n/(i+j+k))*j/(i+j+k);
    if(k)dp[i][j][k]+=(dfs(i,j+1,k-1)+n/(i+j+k))*k/(i+j+k);
    return dp[i][j][k];
}
int main(){
    cin>>n;
    int a=0,b=0,c=0;
    rep(i,n){
        ll x;cin>>x;
        if(x==1)a++;
        if(x==2)b++;
        if(x==3)c++;
    }
    decimal;
    out(dfs(a,b,c));
}

Measured memory_bytes: 213376
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	vector <int> ele(5);
	for(int j = 0 ; j < 5 ; j++)
	{
		cin>>ele[j];
	}
	for(int j = 0 ; j < 5; j++)
	{
		if(ele[j] == 0)
		{
			cout<<j+1<<"\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
ll ans[500001];
int main()
{
  //flash;
  for (int i = 1; i <= 200; ++i)
  {
    for (int j = 1; j <= 200; ++j)
    {
        for (int k = 1; k <= 200; ++k)
        {
            ll yo=(i+j+k)*(i+j+k)-i*j-i*k-j*k;
            ans[yo]++;
        }
    }
  }
  ll n;
  cin>>n;
  for (int i = 1; i <= n; ++i)
  {
      cout<<ans[i]<<'\n';
  }
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 5424
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define P push
#define B begin()
#define E end()
#define SI size()
#define RE return
#define C continue
#define W while
#define SF(x) scanf("%d",&x);
#define MEM(vis,i) memset(vis,i,sizeof(vis))
#define rep(i,x,n) for(int i=x;i<n;i++)
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> pll;
const long long MOD = 1e9+7;
const long long MAX = 1e14+8;
const long long MAXN = 1e5+8;
const long long eps = 1e-4;
ll a[200003];
ll l[200003];
ll r[200003];
stack<ll> s;
ll n;
void R(){
    for(int i=0;i<n;i++){
            W(!s.empty()){
                ll y=s.top();
                if(a[y]<a[i]){
                    break;
                }
                r[y]=i-y;
                s.pop();
            }
            s.P(i);
    }
    W(!s.empty()){
        ll y=s.top();
        r[y]=n-y;
        s.pop();
    }
}
void L(){
    for(int i=n-1;i>=0;i--){
            W(!s.empty()){
                ll y=s.top();
                if(a[y]<a[i]){
                    break;
                }
                l[y]=y-i;
                s.pop();
            }
            s.P(i);
    }
    W(!s.empty()){
        ll y=s.top();
        l[y]=y+1;
        s.pop();
    }
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    R();
    L();
    ll res=0;
    for(int i=0;i<n;i++){
        res+=(l[i]*r[i])*a[i];
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 6072
n, y = map(int, input().split())
for a in range(n + 1):
    for b in range(n + 1):
        c = n - (a + b)
        if c >= 0 and 10000 * a + 5000 * b + 1000 * c == y:
            print(a, b, c)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,m;
signed main(){
	cin>>n>>m;
	cout<<pow(2,m)*(100*(n-m)+1900*m)<<endl;
	return 0;
}

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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int pref[300003], suff[300003];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int n; cin >> n;
	string s; cin >> s;
	for(int i = 0; i < n; i++)
	{
		if(i) pref[i] = pref[i-1] + (s[i] == 'W');
		else pref[i] = (s[i] == 'W');
	}

	for(int i = n-1; i >= 0; i--)
	{
		suff[i] = suff[i+1] + (s[i] == 'E');
	}
	int mx = 1e9;
	
	for(int i = 0; i < n; i++)
	{
		if(i) mx = min(pref[i-1]+suff[i+1],mx);
		else mx = suff[i+1];
	}
	cout << mx << "\n";
}	










 

Measured memory_bytes: 2964