akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int n;
	vector<ll> A;
	ll a,countP,countM;
	countP=0;countM=0;
	cin>>n;
	rep(i,n){
		cin>>a;
		A.push_back(a);
		if(a>=0){
			countP++;
		}
		if(a<=0){
			countM++;
		}
	}
	
	sort(all(A));
	reverse(all(A));
	ll ans = 0;

	if(countP == 0){
		rep(i,n){
			ans += abs(A[i]);
		}
		ans -= abs(A[0]) * 2;
		cout<<ans<<endl;
		ll memo = A[0];
		rep(i,n){
			if(i==0) continue;
			cout<<memo<<" "<<A[i]<<endl;
			memo -= A[i];
		}
		return 0;
	}else if(countM == 0){
		sort(all(A));
		rep(i,n){
			ans += A[i];
		}
		ans -= A[0] * 2;
		cout<<ans<<endl;
		ll memo = A[0];
		rep(i,n){
			if(i==0) continue;
			if(i == n-1){
				cout<<A[i]<<" "<<memo<<endl;
				return 0;
			}
			cout<<memo<<" "<<A[i]<<endl;
			memo -= A[i];
		}
	}else{//降順
		rep(i,n){
			ans += abs(A[i]);
		}
		cout<<ans<<endl;
		int idx = 1;
		while(A[idx] >= 0 && idx <= n-2){
			cout<<A[n-1]<<" "<<A[idx]<<endl;
			A[n-1] -= A[idx];
			idx++;
		}
		while(idx <= n-2){
			cout<<A[0]<<" "<<A[idx]<<endl;
			A[0] -= A[idx];
			idx++;
		}
		cout<<A[0]<<" "<<A[n-1]<<endl;
		return 0;
	}

	return 0;
}


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

int D, n;
int a[100], e[100], d[100];
int memo[110][110];

int dfs(int tai, int ex){

  if(tai <= 0){
    return 0;
  }

  if(memo[tai][ex] != -1){
    return memo[tai][ex];
  }

  int ans = 100000000;

  for(int i = 0;i < n;i++){
    if((a[i] != 0 && d[i] <= ex) || (a[i] == 0 && d[i] <= ex && ex < 100)){
      ans = min(ans, dfs(tai-a[i], min(ex+e[i],100))+1);
    }
  }

  return memo[tai][ex] = ans;
}

int main(){
  while(cin >> D >> n, D != 0){
    bool zeroFrag = false;
    for(int i = 0;i < n;i++){
      cin >> a[i] >> e[i] >> d[i];
      if(a[i] == 0 && e[i] == 0){
        i--;
        n--;
      }else if(d[i] == 0){
        zeroFrag = true;
      }
    }

    if(zeroFrag){
      memset(memo,-1,sizeof(memo));
      int ans = dfs(D, 0);
      if(ans >= 100000000){
        cout << "NA" << endl;
      }else{
        cout << ans << endl;
      }
    }else{
      cout << "NA" << endl;
    }

  }
  return 0;
}




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

#define ll long long

int main()
{
    ll N;
    std::cin >> N;

    std::vector<ll> A(N);
    for(ll i=0; i < N; i++) {
        std::cin >> A[i];
    }

    ll max_height = A[0];
    ll sum = 0;
    for(ll i=1; i < N; i++) {
        if(max_height > A[i]) {
            sum += (max_height - A[i]);
        }
        else {
            max_height = A[i];
        }
    }
    std::cout << sum << std::endl;
}

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

int main() {
	int N ;
  	cin >> N ;
  	int A;
  	int Max = 30;
    int counter;
  	for(int i = 0; i < N; i++){
    	cin >> A;
      	counter = 0;
      	while(A % 2 == 0){
        	counter++;
          	A /= 2;
        }
      	if(counter < Max){
        	Max = counter;
        }
    }
    cout << Max << endl;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

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

int t;

void solve(){
    int n;
    cin>>n;
    vector<char> a(n);
    vector<char> b(n);
    for(auto &it:a)cin>>it;
    for(auto &it:b)cin>>it;
    string x, y, str;
    for(auto it:a){
        x.push_back(it);
        str.push_back(it);
    }
    for(auto it:b){
        y.push_back(it);
    }
    sort(str.begin(),str.end());
    vector<string> p;
    p.push_back(str);
    while(next_permutation(str.begin(),str.end())){
        p.push_back(str);
    }
    int idx1=-1, idx2=-1;
    for(int i=0;i<p.size();i++){
        if(x==p[i])idx1=i+1;
        if(y==p[i])idx2=i+1;
    }
    cout<<abs(idx1-idx2)<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ASSERT(C, ...) assert( (C) || (PRINT(__VA_ARGS__), false) )
template <class Head> void PRINT(Head head) {
    std::cout << head << "\n";
}
template <class Head, class... Tail> void PRINT(Head head, Tail... tail) {
    std::cout << head << " ";
    PRINT(tail...);
}


ll gcd(ll a, ll b) {
    while ( b != 0 ) {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

ll solve(ll N, ll M, vector<ll>& A) {
    ll a = A[0], b = 1;
    while ( (a & 1) == 0 ) {
        a >>= 1;
        b <<= 1;
    }
    for ( int i = 0; i < N; i++ ) {
        if ( A[i] % b != 0 ) return 0;
        if ( A[i] % (2*b) == 0 ) return 0;
        A[i] /= b;
    }

    ll d = A[0];
    for ( int i = 1; i < N; i++ ) {
        ll g = gcd(d, A[i]);
        d = d / g * A[i];
        if ( d > 2 * M ) return 0;
    }
    ll ans = 2*M/b/d - 2*M/b/(2*d);
    return ans;
}

ll solve_2(ll N, ll M, vector<ll>& A) {

    ll d = A[0];
    for ( int i = 1; i < N; i++ ) {
        ll g = gcd(d, A[i]);
        d = d / g * A[i];
        if ( d > 2 * M ) return 0;
    }
    ll c = 0;
    for ( ll m = d; m <= 2*M; m+=d ) {
        bool ok = true;
        for ( int i = 0; i < N; i++ ) {
            if ( m / A[i] % 2 == 0 ) {
                ok = false;
                break;
            }
        }
        if ( ok ) c++;
    }
    return c;

}

void test() {
   
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd(30, 50);
    ll x = rnd(mt64);

    ll N = 4;
    ll M = 1e5+1;

    for ( int t = 0; t < 1000; t++ ) {
        vector<ll> A;
        // A.push_back(6);
        // A.push_back(10);
        // ll ans2 = solve_2(2, 50, A);
        // ll ans1 = solve(2, 50, A);

        for ( int i = 0; i < N; i++ ) {
            ll x = rnd(mt64);
            while ( (x & 1) == 0 ) x >>= 1;
            A.push_back(x*8);
        }
        // if ( t == 13 ){ 
        //     ll x = 1;
        // }
        vector<ll> AA(A);
        ll ans1 = solve(N, M, AA);
        ll ans2 = solve_2(N, M, A);
        ASSERT(ans2 == ans1, t, ans1, ans2);
        cout << ans1 << "\n";
    }

}


int main() {
    //test();
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }    
    auto ans = solve(N, M, A);
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

const int mod = 998244353, N = 303;

bool can[N][N][N];
long long dp[N][N][N];


void add(long long & var, long long val) {
  var += val;
  if (var >= mod)
    var -= mod;
}

char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  int one = 0;
  for (int i = 0; i < n; ++i)
    one += s[i] == '1';
  int zero = n - one;
  queue<tuple<int, int, int>> que;
  
  auto check = [&](int x, int y, int z) {
    if (can[x][y][z]) {
      return;
    }
    can[x][y][z] = true;
    que.emplace(x, y, z);
  };

  check(0, 0, 0);
  while (!que.empty()) {
    int i, j, k;
    tie(i, j, k) = que.front();
    que.pop();
    if (i+1 <= n) {
      if (j) {
        check(i+1, j - 1 + (s[i] == '0'), k + (s[i] == '1'));
      }
      if (k) {
        check(i+1, j + (s[i] == '0'), k - 1 + (s[i] == '1'));
      }
    }
    if (j+k > 1) {
      if (j)
        check(i, j-1, k);
      if (k)
        check(i, j, k-1);
    }
    if (i + 2 <= n) {
      check(i+2, j + (s[i] == '0'), k + (s[i] == '1'));
      check(i+2, j + (s[i+1] == '0'), k + (s[i+1] == '1'));
    }
    if (i > 0) {
      if (j && s[i-1] == '0')
        check(i-1, j-1, k);
      if (k && s[i-1] == '1')
        check(i-1, j, k-1);
    }
  }
  dp[n][0][0] = 1;
  long long ans = 1;
  for (int i = n; i >= 1; --i) {
    char c = s[i-1];
    for (int j = 0; j <= zero; ++j) {
      for (int k = 0; k <= one; ++k) {
        // cerr << i << " " << j << " " << k << " " << (int)can[i][j][k] << " " << dp[i][j][k] << endl;
        if (dp[i][j][k] == 0) continue;
        if (c == '1') {
          add(dp[i][j+1][k], dp[i][j][k]);
        } else {
          add(dp[i][j][k+1], dp[i][j][k]);
        }
        add(dp[i-1][j][k], dp[i][j][k]);
        if (can[i][j][k]) {
          // cerr << i << " " << j << " " << k << " " << " " << dp[i][j][k] << endl;
          add(ans, dp[i][j][k]);
        }
      }
    }
  }
  ans %= mod;
  if (ans < 0)
    ans += mod;
  printf("%lld\n", ans);
  return 0;
}


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

int main(){
	int N;
	cin >> N;
	bool zero=true;
	int ans=0;
	while(N>0){
		if(N%10!=0 && N!=1)zero=false;
		ans+=N%10;
		N/=10;
	}
	if(zero)ans=10;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  int x;
  cin >> n >> m >> x;
  for (int i = 0; i < m; ++i) cin >> a[i];
  int cz = 0, cm = 0;
  for (int i = 0; i < m; ++i) {
    if (a[i] < x) ++cz;
    if (a[i] > x) ++cm;
  }
  cout << min(cz, cm);

  return 0;
}



Measured memory_bytes: 3616
K,R,L = map(int,raw_input().split())
P = float(raw_input())
E = float(raw_input())
T = float(raw_input())

def rec(r,l,k):
    h = (r+l)/2.0
    if k == 0:
        return 1.0 if T-E <= h <= T+E else 0.0
    if T-E <= r and l <= T+E: return 1.0
    if T+E <= r or l <= T-E: return 0.0

    if h >= T:
        return (1-P)*rec(r,h,k-1)+P*rec(h,l,k-1)
    else:
        return (1-P)*rec(h,l,k-1)+P*rec(r,h,k-1)

print "%.10f"%rec(R,L,K)

Measured memory_bytes: 4280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;

const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 1e5+10;
bool imp = false;

void solve() {
    ll n;cin>>n;

    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        vis[a[i]] += 1;
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll x = a[i];
        vis[x] -= 1;
//        cout<<vis[x]<<endl;
        bool flag = false;

        for(ll j = 1;j*j<=x;j+=1)
        {

            if(x%j == 0){
                if(vis[j] > 0) {
                    flag = true;
                    break;
                }

                if(x /j != j){
                    if(vis[x/j] > 0){
                        flag = true;
                        break;
                    }
                }

            }
        }
        vis[a[i]] +=1;

        if(!flag)  {
            ans++;
//            cout<<a[i]<<" ";
        }
    }

    cout<<ans<<endl;


}

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

    fio
    int t=1;
    if(imp) cin>>t;
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }

}


Measured memory_bytes: 33304
#include<bits/stdc++.h>
using namespace std;
char c[109][109];
int p[109];
int q[109];

int main(){
  int h,w;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>c[i][j];
    }
  }
  for(int i=0;i<h;i++){
    int cnt=0;
    for(int j=0;j<w;j++){
      if(c[i][j]=='#')cnt++;
    }
    if(cnt==0)p[i]=1;
  }
  for(int i=0;i<w;i++){
    int cnt=0;
    for(int j=0;j<h;j++){
      if(c[j][i]=='#')cnt++;
    }
    if(cnt==0)q[i]=1;
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(p[i]==0&&q[j]==0){
        cout<<c[i][j];
      }
    }
    if(p[i]==0)cout<<endl;
  }
  return(0);
}

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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a, a + n);
  queue<int> q1;
  queue<int> q2;
  long long ans = 0;
  if (a[0] >= 0) {
    q2.push(a[0]);
    ans -= a[0];
    for (int i=1; i<n; i++) {
      q1.push(a[i]);
      ans += a[i];
    }
  } else if (a[n-1] <= 0) {
    q1.push(a[n-1]);
    ans += a[n-1];
    for (int i=0; i<n-1; i++) {
      q2.push(a[i]);
      ans -= a[i];
    }
  } else {
    for (int i=0; i<n; i++) {
      if (a[i] >= 0) {
        q1.push(a[i]);
        ans += a[i];
      } else {
        q2.push(a[i]);
        ans -= a[i];
      }
    }
  }
  cout<<ans<<endl;
  while (q1.size() > 0 && q2.size() > 0) {
    int t1 = q1.front();
    int t2 = q2.front();
    q1.pop();
    q2.pop();
    if (q1.size() > 0 && q2.size() == 0) {
      cout<<t2<<" "<<t1<<endl;
      q2.push(t2-t1);
    } else {
      cout<<t1<<" "<<t2<<endl;
      q1.push(t1-t2);
    }
  }
}

Measured memory_bytes: 2688
nums = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

N = int(input())
for _ in range(N):
  b, f, r, v = map(int, input().split())
  nums[b - 1][f - 1][r - 1] += v

for b in range(4):
  for f in range(3):
    for r in range(10):
      print(f' {nums[b][f][r]}', end = '')
    print()
  if b != 3:
    print('#' * 20)


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

int main(){
	int w,d,h;
	while(1){
		cin >> w >> d;
		if(!w) break;
		int num1[20] = {},num2[20] = {},sum = 0;
		for(int i = 0;i < w;i++){
			cin >> h;
			num1[h - 1]++;
			sum += h;
		}
		for(int i = 0;i < d;i++){
			cin >> h;
			num2[h - 1]++;
			sum += h;
		}
		for(int i = 0;i < 20;i++){
			sum -= min(num1[i],num2[i]) * (i + 1);
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<vector<char> > g;
vector<bool> type;           // 0:L 1:R

string parse(const string &s) {
  REP(i, g.size()) {
    int start = 0, end = s.size(), d = 1;
    if (type[i]==0) start = s.size()-1, end = 0, d = -1;
    int a = 0;
    for (int j=start; j!=end; j+=d) {
      if (s[j] == '(') a++;
      else if(s[j] == ')') a--;
      else if (a==0) {
        FOR(it, g[i]) {
          if (s[j] == *it)
            return "("+ parse(s.substr(0,j)) + string(1,*it) + parse(s.substr(j+1)) + ")";
        }
      }
    }
  }
  if (s[0] == '(') {
    return parse(s.substr(1,s.size()-2));
  }
  return s;
}

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

  REP(t,T) {
    if (t) cout << endl;
    int G;cin >> G;
    g.resize(G);
    type.clear();
    REP(i,G) {
      char A; cin >> A;
      int M; cin >> M;
      type.push_back(A=='R');
      vector<char> tmp(M);
      REP(j,M) cin>>tmp[j];
      //g[G-i-1] = tmp;
      g[i] = tmp;
    }
    int n;cin >> n;
    REP(i,n) {
      string e;
      cin >> e;
      cout << parse(e) << endl;
    }
  }
  
  
}

Measured memory_bytes: 928
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
A[0] = B[0]
for i in range(N-1):
    if i == N-2:
        A[i+1] = B[i]
    else:
        A[i+1] = min(B[i], B[i+1]) 
print(sum(A))

Measured memory_bytes: 3060
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for a in range(A+1):
	for b in range(B+1):
		for c in range(C+1):
			total=500*a+100*b+50*c
			if total==X:
				ans+=1
 
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef short int sh;

const ll inf=0x3f3f3f3f3f3f3f3f;
const int MAX=5e4+10;
const int mod=1e9+7;

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int m,ans;
        m=n%1000;
        ans=1000-m;
        if(ans==1000)
            ans=0;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3216
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    vl snuke(N, 0);
    rep(i, K){
        ll d;
        cin >> d;
        rep(j, d){
            ll a;
            cin >> a;
            a--;
            snuke[a]++;
        }
    }
    rep(i, N){
        if(snuke[i] == 0) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    n,m=list(map(int,input().split()))
    a=[0 for _ in range(m)]
    b=[0 for _ in range(m)]
    c=[0 for _ in range(m)]
    d=[[INF for i in range(n)] for i in range(n)]
    for i in range(m):
        a[i],b[i],c[i]=list(map(int,input().split()))
        a[i]-=1
        b[i]-=1
        d[a[i]][b[i]]=c[i]
        d[b[i]][a[i]]=c[i]
    
    for i in range(n):
        d[i][i]=0
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
                d[j][i]=d[i][j]
    ans=0
    for j in range(m):
        temp=1
        for i in range(n):
            if d[i][b[j]]==d[i][a[j]]+c[j]:
                temp=0
                break
        ans+=temp
    print(ans)
    
    
    
        
        
    
if __name__=="__main__":
    main()
    

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    map<string, int> M;
    for (int i = 0; i < N; i++) {
        string S; cin >> S; M[S]++;
    }
    vector<string> ans;
    int maxcnt = 0;
    for (auto &p : M) {
        if (p.second > maxcnt) {
            ans.clear();
            ans.push_back(p.first);
            maxcnt = p.second;
        } else if (p.second == maxcnt) {
            ans.push_back(p.first);
        }
    }
    sort(begin(ans), end(ans));
    for (auto &s : ans) cout << s << '\n';
    return 0;
}


Measured memory_bytes: 26868
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			long X = scan.nextLong();
			long Y = scan.nextLong();
			
			long point = X;
			int count = 1;
			
			while(true) {
				point*=2;
				if(point<=Y) {
					count++;
				}else{
					break;
				}
			}
			
			System.out.println(count);
			
			
			
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int use[100010][40];
int main()
{
	int N, C;
	cin >> N >> C;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		c--;
		use[s - 1][c]++;
		use[t][c]--;
	}
	for (int i = 0; i < C; i++) {
		for (int j = 1; j < 100010; j++) {
			use[j][i] += use[j - 1][i];
		}
	}
	for (int i = 0; i < 100010; i++) {
		int cnt = 0;
		for (int j = 0; j < C; j++) {
			if (use[i][j] >= 1) cnt++;
		}
		ans = max(ans, cnt);
	}
	/*for (int i = 0; i < C; i++) {
		for (int j = 0; j < 15; j++) {
			cout << use[j][i] << " ";
		}
		cout << endl;
	}*/
	cout << ans << endl;
}

Measured memory_bytes: 19216
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    string s;
    cin>>s;
    if(s == "Sunny")cout<<"Cloudy";
    if(s == "Cloudy")cout<<"Rainy";
    if(s == "Rainy")cout<<"Sunny";
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    Q = int(readline())

    hi = []
    lo = []
    hi_sum = lo_sum = 0
    b_sum = 0

    ans = []
    for _ in range(Q):
        A = list(map(int, readline().split()))
        if len(A) == 3:
            a, b = A[1], A[2]
            b_sum += b

            if not lo:
                lo.append(-a)
                lo_sum += a
            else:
                if a <= -lo[0]:
                    heappush(lo, -a)
                    lo_sum += a
                else:
                    heappush(hi, a)
                    hi_sum += a

            if len(hi) > len(lo):
                x = heappop(hi)
                hi_sum -= x
                heappush(lo, -x)
                lo_sum += x
            elif len(hi) + 1 < len(lo):
                x = -heappop(lo)
                lo_sum -= x
                heappush(hi, x)
                hi_sum += x
        else:
            x = -lo[0]
            val = x * (len(lo) - 1) - (lo_sum - x) + hi_sum - x * len(hi) + b_sum
            ans.append((x, val))

    for x, val in ans:
        print(x, val)

    return


if __name__ == '__main__':
    main()


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

const int N = 100005;

int n, a[N];
map<int,int> cnt;
vector<int> vec;
long long ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i], cnt[a[i]]++;

	for (map<int,int>::iterator it = cnt.begin(); it != cnt.end(); ++it) {
		if (it->second >= 2) vec.push_back(it->first);
		if (it->second >= 4) ans = 1LL * it->first * it->first;
	}

	if (vec.size() < 2) cout << 0 << endl;
	else {
		cout << max(ans, 1LL * vec[vec.size()-1] * vec[vec.size()-2]) << endl;
	}
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,A,B,C,X,s,d;
    while(scanf("%d%d%d%d",&A,&B,&C,&X)==4)
    {
        s=0;
        for(a=A; a>=0; a--)
        {
            for(b=B; b>=0; b--)
            {
                d=X-500*a-100*b;
                if(d%50==0&&d/50<=C&&d>=0)
                    s++;
            }
        }
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &i : x)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int s, w;
void solve() {
    cin >> s >> w;
    if (s <= w)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{   
   int D,L,C,U,F,O;
	scanf("%d",&D);
	scanf("%d",&L);
	C=D/L; 
	F=D%L;
	printf("%d\n",C+F);
	return 0;
}	
// printf("%d\n",A+S);


Measured memory_bytes: 2048
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
int a[222222];
pair<int, int> tree[1<<22];
int n;
ll ans;

void build(void)
{
	int i;
	for(i=n-1 ; i>0 ; i--)
	{
		tree[i]=min(tree[i<<1],tree[i<<1|1]);
	}
}

int query(int l, int r)
{
	pair<int, int> ret=make_pair(10000000, -1);
	for(l+=n, r+=n ;  l<r ; l>>=1, r>>=1)
	{
		if(l&1) ret=min(ret,tree[l++]);
		if(r&1) ret=min(ret,tree[--r]);
	}
	return ret.second;
}

void call(int l, int r)
{
	if(l>=r  || l<0 || r<0)
	{
		return;
	}
	int mind=query(l, r);
	ans+=(ll)a[mind]*(mind-l+1)*(r-mind);
	call(l,mind);
	call(mind+1,r);
}

int main(void)
{
	int i, j;
	cin>>n;
	for(i=0 ; i<n ; i++)
	{
		scanf("%d",&a[i]);
		tree[n+i].first=a[i];
		tree[n+i].second=i;
	}

	build();
	call(0,n);
	
	cout<<ans;
}

Measured memory_bytes: 10368
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

void solve(){
	int H,W,n ;
	cin >> H >> W >> n ;
	int ans = INF ;
	for(int i = 0 ; i <= 100 ; i++){
		for(int j = 0 ; j <= 100 ; j++){
			if(H*i+W*j-i*j-n >= 0) ans = min(ans,i+j) ;
		}
	}
	cout << ans << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


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

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void preParse(Node *u) {
  if (u == NIL) {
    return;
  }
  cout << " " << u->key;
  preParse(u->left);
  preParse(u->right);
}

void inParse(Node *u) {
  if (u == NIL) {
    return;
  }
  inParse(u->left);
  cout << " " << u->key;
  inParse(u->right);
}

void insert(int k) {
  Node* y = NIL;
  Node* x = root;
  Node* z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->right = NIL;
  z->left = NIL;

  while(x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if ( z->key < y->key ) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

Node* find(Node *u, int k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) {
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return u;
}

int main() {
  int m;
  cin >> m;
  for (int i = 0; i < m; i ++) {
    string command;
    int x;
    cin >> command;
    if (command == "insert") {
      cin >> x;
      insert(x);
    } else if (command == "find") {
      cin >> x;
      Node* t = find(root, x);
      if (t != NIL) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    } else if (command == "print") {
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }
  }
}



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

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

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    double l, r;
    vector<int> a(4), b(4);
    while(cin >> l >> r){
        if(l >= 1.1) a[0]++;
        else if(l >= 0.6) a[1]++;
        else if(l >= 0.2) a[2]++;
        else a[3]++;
        if(r >= 1.1) b[0]++;
        else if(r >= 0.6) b[1]++;
        else if(r >= 0.2) b[2]++;
        else b[3]++;
    }
    for (int i = 0; i < 4; ++i) {
        printf("%d %d\n", a[i], b[i]);
    }
    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#define N 100

int size[N], m[N][N], count[N][N], d[N], n;

void DFS(int, int);

int main(){
	int i, j, a;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%d", &a);
		scanf("%d", &size[a]);
		
		for(j = 0; j < size[a]; j++){
			scanf("%d", &m[a][j]);
			scanf("%d", &count[a][j]);
		}
	}
	for(i = 0; i < n; i++)
		d[i] = 1000000;
	
	DFS(0, 0);
	
	for(i = 0; i < n; i++)
		printf("%d %d\n", i, d[i]);
	
	return 0;
}

void DFS(int a, int b){
	int i;
	
	d[a] = b;
	
	for(i = 0; i < size[a]; i++){
		if(d[m[a][i]] > b + count[a][i])
			DFS(m[a][i], b + count[a][i]);
	}
}

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

int main() {
	int n, counter=0;
	int sequence[100];

	for(int i=0;i<100;i++) sequence[i]=0;

	cin >> n;

	while(cin >> sequence[counter]) {
		counter++;
		if(counter==n) break;
	}

	for(int i=n-1;i>=0;i--) {
		if(i==0) cout << sequence[i] << endl;
		else cout << sequence[i] << " ";
	}

	return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		int[] d1=new int[n];
		int[] d2=new int[n];
		for(int i=0;i<=n-1;i++) {
			d1[i]=sc.nextInt();
			d2[i]=sc.nextInt();
		}
		
		for(int i=0;i<=n-3;i++) {
				if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2]) {
					System.out.println("Yes");
					break;
					}
				else if(i==n-3) {
					System.out.println("No");
				}		
		}
		sc.close();
		}
	}

Measured memory_bytes: 36036
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n;
	cin >> n;
	map<int, int> S;
	vector<int> a(n);
	rep(i, 0, n) {
		cin >> a[i];
		S[a[i]]++;
		if (i != 0 && a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	if (a[0] != 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ANS = 1;
	bool ans = true;
	for (auto x : S) {
		if (x.first == 0)continue;
		if (S[x.first - 1] == 0)ans = false;
		int A = x.second;
		int B = S[x.first - 1];
		ANS = (ANS * modpow(B, A, 998244353)) % 998244353;
	}
	ANS %= 998244353;
	if (!ans)cout << 0 << endl;
	else cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
using mii = map<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define pb(x) push_back((x))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
int ans;
vb bricks;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N;
    bricks.assign(N, false);
    int idx = 0;
    rep(i, N) {
        int a; cin >> a; a--;
        if (a == idx) {
            bricks[a] = true;
            idx++;
        }
    }

    if (bricks[0] == false) {
        cout << -1 << endl;
        return 0;
    }

    ans = N;
    rep(i, N) {
        if (bricks[i] == true) ans--;
        else break;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
long long N, M, a[100009][3], maxn = -(10000000000);
 
int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { 
                if ((i / (1 << k)) % 2 == 0) 
                    S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3664
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
    val a = (1..n).map { it }.toTypedArray()

    var c = 0
    for(i in 0 until n){
        if(p[i] != a[i]) c++
    }

    println(if(c == 2 || c == 0) "YES" else "NO")
}

Measured memory_bytes: 37900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  if(A>=13){
    cout << B << endl;
  }
  
  else if(A>=6){
    cout << B/2 << endl;
  }
  
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
'use strict';

let lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');

let N = +(lines[0].split(' ')[0]);
let ABs = lines.slice(1).map(line => line.split(' ').map(Number));

let res = [];
for (let i = 0; i < N; i++) res[i] = 0;

ABs.forEach(ab => {
    res[ab[0]-1]++;
    res[ab[1]-1]++;
});

res.forEach(n => console.log(n));

Measured memory_bytes: 7500
from collections import Counter, defaultdict

n, m = [int(c) for c in input().split()]
xs = [int(c) for c in input().split()]


def ring_cost(fr, to):
    return to - fr if to >= fr else (m - fr) + to

from_counter = Counter(xs[:-1])
to_counter = Counter(xs[1:])

fav = 1
cost = 0
use_fav = 0
nofav_cost = defaultdict(int)

for i in range(n - 1):
    normal_cost = ring_cost(xs[i], xs[i+1])
    fav_cost = ring_cost(fav, xs[i+1]) + 1
    cost += min(normal_cost, fav_cost)
    nofav_cost[xs[i+1]] += normal_cost
    if fav_cost <= normal_cost:
        use_fav += 1

ans = cost
for fav in range(2, m+1):
    stop_using_fav = to_counter[fav - 1]
    use_fav -= stop_using_fav
    cost += nofav_cost[fav - 1] - stop_using_fav

    cost -= use_fav

    use_fav += from_counter[fav - 1]
    ans = min(ans, cost)
    # print(fav, cost)

print(ans)

Measured memory_bytes: 72428
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

template<int M>
struct ModInt {
public:
	using value_type = long long;
	
	ModInt(value_type val = 0) : val(val < 0 ? (M - (-val % M)) % M : val % M) {}
	
	explicit operator bool() const noexcept { return val; }
	bool operator ==(const ModInt & rhs) const noexcept { return val == rhs.val; }
	bool operator !=(const ModInt & rhs) const noexcept { return !(*this == rhs); }
	ModInt operator +() const noexcept { return ModInt(*this); }
	ModInt operator -() const noexcept { return ModInt(0) -= *this; }
	ModInt operator +(const ModInt & rhs) const noexcept { return ModInt(*this) += rhs; }
	ModInt operator -(const ModInt & rhs) const noexcept { return ModInt(*this) -= rhs; }
	ModInt operator *(const ModInt & rhs) const noexcept { return ModInt(*this) *= rhs; }
	ModInt operator /(const ModInt & rhs) const noexcept { return ModInt(*this) /= rhs; }
	
	ModInt & operator +=(const ModInt & rhs) noexcept {
		val += rhs.val;
		if (val >= M) val -= M;
		return *this;
	}
	ModInt & operator -=(const ModInt & rhs) noexcept {
		if (val < rhs.val) val += M;
		val -= rhs.val;
		return *this;
	}
	ModInt & operator *=(const ModInt & rhs) noexcept {
		val = val * rhs.val % M;
		return *this;
	}
	ModInt & operator /=(const ModInt & rhs) noexcept {
		*this *= rhs.inverse();
		return *this;
	}
	
	ModInt pow(value_type n) const {
		ModInt res = 1, x = val;
		if (n < 0) { x = x.inverse(); n = -n; }
		while (n) { if (n & 1) res *= x; x *= x; n >>= 1; }
		return res;
	}
	
	ModInt inverse() const {
		long long a = val, a1 = 1, a2 = 0, b = M, b1 = 0, b2 = 1;
		while (b > 0) {
			value_type q = a / b, r = a % b;
			value_type nb1 = a1 - q * b1, nb2 = a2 - q * b2;
			a = b; b = r;
			a1 = b1; b1 = nb1;
			a2 = b2; b2 = nb2;
		}
		assert(a == 1);
		return a1;
	}
	
	const value_type & get() const noexcept { return val; }
	static decltype(M) get_mod() noexcept { return M; }
	
	friend std::ostream & operator <<(std::ostream & os, const ModInt & rhs) { return os << rhs.val; }
	friend std::istream & operator >>(std::istream & is, ModInt & rhs) {
		value_type x;
		is >> x;
		rhs = ModInt(x);
		return is;
	}
private:
	value_type val;
};
using mint = ModInt<MOD>;

int main() {
	int N;
	cin >> N;
	mint ans = mint(10).pow(N) - mint(9).pow(N) * 2 + mint(8).pow(N);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
def solve():
    input()
    H = map(int, input().split())
    res = 0
    r = 0
    h_ = 0
    for h in H:
        if h <= h_:
            r += 1
        else:
            res = max(res, r)
            r = 0
        h_ = h
    res = max(res, r)
    return str(res)

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 11136
n = gets.to_i
a = gets.split(' ').map(&:to_i)

result = 0

200.times { |i|
  if i == 0
    a.all?{|item| (item/2).even? } ? result +=1 : break
  end
  a.all?{|item| (item/(2**(i+1))).even? } ? result +=1 : break
}

p result

Measured memory_bytes: 1788
import sys
from collections import Counter
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))

dc = Counter(d)
tc = Counter(t)

for i in tc.keys():
    if dc[i]<tc[i]:
        print('NO')
        sys.exit()
print('YES')

Measured memory_bytes: 57112
using System;

class Diverta_2019_C
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        int count = 0;

        int A = 0;
        int B = 0;
        int BA = 0;

        string[] s = new string[N];
        for (int i = 0; i < N; i++)
        {
            s[i] = Console.ReadLine();
            for (int j = 0; j < s[i].Length; j++)
            {
                int pos = s[i].IndexOf("AB", j);
                if (pos < 0) break;

                count++;
                j += pos;
            }

            if (s[i][0] == 'B' && s[i][s[i].Length-1] =='A') BA++;
            else if(s[i][0] == 'B') B++;
            else if(s[i][s[i].Length-1] == 'A') A++;
        }

        if(A==0 && B==0 && BA>1) count += BA-1;
        else count += Math.Min(A, B) + BA;

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13464
h,w,a,b=map(int,input().split())
ans=['']*h
for i in range(h):
    for j in range(w):
        if (i<b and j<a) or (i>=b and j>=a):
            ans[i]+='0'
        else:
            ans[i]+='1'
for i in range(h):
    print(ans[i])

Measured memory_bytes: 4980
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<math.h>
using namespace std;

int main(){
    int N;
    int d[110];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> d[i];
    }
    
    int num[110]={0};
    for(int i=0; i<N; i++){
        num[d[i]]++;
    }
    
    int res=0;
    for(int i=1; i<=100; i++){
        if(num[i]){
            ++res;
        }
    }
    
    cout << res << endl;
    
    return 0;
}


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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >

//------------------------------------------------------

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k % 2 == 0) cout << a - b << endl;
    else {
        ll d = b + c;
        ll e = a + c;
        cout << d - e << endl;
    }


    return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
//const LL LINF = INF * (LL) INF;


int main()
{
	int a , b;
	cin >> a >> b;
	int ans = ((a - b) * 100 + b * 1900);
	ans <<= b;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    int n, ans = 0; cin >> n;
    map<int, int> mp;
    REP(i, n){
        int a; cin >> a;
        ++mp[a-1];
        ++mp[a];
        ++mp[a+1];
    }
    for(auto it = mp.begin(); it != mp.end(); ++it){
        ans = max(ans, it->second);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4736