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

int main()
{
	int n ; cin >> n;
	int temp[n] ={};
	int arr[n+1] = {};
	for(int i = 0; i < n ; i++)
	{
		int x; cin >> x;
		temp[i] = x;
		arr[x]++;
	}
	long long socach = 0;
	for(int i = 0; i <= n; i++)
	{
		socach += (long long)arr[i]*(arr[i] - 1)/2;
	}
	for(int i = 0; i < n; i++)
	{
		cout << socach - arr[temp[i]] + 1 << endl;
	}	
	return 0;
}

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

using namespace std;

typedef long long ll;

ll mod;

ll powimod(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

ll powi(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int in,s=0,sq=0;
    while(n--)
    {
    cin>>in;
    s+=in;
    sq+=in*in;
    }
    s=s*s-sq;
    s/=2;
    cout<<s;
}


Measured memory_bytes: 3612
import numpy as np

N=int(input())
H=np.array(input().split(),dtype=np.int32)

reverseH=H[::-1]

move_count=0
max_move=0

for i in range(N-1):
    if(reverseH[i]<=reverseH[i+1]):
        move_count+=1
        if(max_move<move_count):
            max_move=move_count
    else:
        move_count=0

print(max_move)


Measured memory_bytes: 24264
#include<stdio.h>

int main(){
  int i,j,k,n,left,right;
  left=249999;
  right=250001;
  int A[500000];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d ",&k);
    if(i==0){
      A[250000]=k;
    }
    else{
      if(n%2 == (i+1)%2){
        A[left--]=k;
      }
      else
        A[right++]=k;
    }
  }
  
  for(i=left+1;i<right;i++)
    printf("%d ",A[i]);
  puts("");
  return 0;
}
    

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int o=0;o<h;o++) cin >> s[o];
    int res=0;
    for(int a=0;a<(1<<h);a++)
    {
        for(int b=0;b<(1<<w);b++)
        {
            int c=0;
            for(int o=0;o<h;o++)
            {
                for(int i=0;i<w;i++)
                {
                    if((a&(1<<o))==0&&(b&(1<<i))==0&&s[o][i]=='#') c++;
                }
            }
            res+=(c==k);
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>

using ll = long long;

const ll INF = std::numeric_limits<ll>::max() / 2;
const ll VMAX = 50;
const ll NMAX = 50;
const ll S = VMAX * NMAX * VMAX;
// ナップザックDPにおける価値の最大値

struct Goods {
    ll v, m, w;
};

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

    std::vector<Goods> goods(N);
    for (auto& g : goods) std::cin >> g.v >> g.w >> g.m;

    // 各商品、最大VMAX個で価値ベースの個数制限ナップザック
    std::vector<ll> dp(S + 1, INF);
    dp[0] = 0;
    for (auto& g : goods) {
        int k = std::min(g.m, VMAX);
        g.m -= k;
        // 高々50回なのでループで済ませる
        for (int i = 0; i < k; ++i) {
            for (int j = S; j - g.v >= 0; --j) {
                dp[j] = std::min(dp[j], dp[j - g.v] + g.w);
            }
        }
    }

    // 価値の密度が高い順にソート
    std::sort(goods.begin(), goods.end(),
              [](const Goods& a, const Goods& b) {
                  return a.v * b.w > b.v * a.w;
              });

    // 後は貪欲に選んでいくDFS
    ll ans = 0;
    for (ll v = 0; v <= S; ++v) {
        if (dp[v] > W) continue;

        ll cap = W - dp[v];
        ll vsum = v;

        for (const auto& g : goods) {
            // 貪欲に選べるだけ選ぶ
            ll num = std::min(g.m, cap / g.w);
            vsum += num * g.v;
            cap -= num * g.w;
        }
        ans = std::max(ans, vsum);
    }

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


Measured memory_bytes: 3884
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	bool judge;
	int n,a[101],flag,cnt=0,at;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		judge = false;
		at = i;
		for (int j = i; j < n; ++j) {
			if (a[j] < a[at]) {
				judge = true;
				at = j;
			}
		}
		if (judge) {
			swap(a[i], a[at]);
			cnt++;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (i == n - 1)cout << a[i] << endl;
		else
		cout << a[i] << " ";
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

// 素因数分解(first要素がfactで、second要素がその個数)
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int f[100];

int num(int n){
    int ret = 0;
    rep(i, 100){
        if(f[i] >= n) ret++;
    }
    return ret;
}

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

    for(int i=1; i<=n; i++){
        auto v = prime_factorize(i);
        for(auto p: v) f[p.first] += p.second;
    }

    int c1 = max(num(4) * (num(4)-1) * (num(2)-2) / 2, 0);
    int c2 = max(num(24) * (num(2)-1), 0);
    int c3 = max(num(14) * (num(4)-1), 0);
    int ans = c1 + c2 + c3 + num(74);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;

const ll inf = 1e9;


int main() {
	string s;
	cin >> s;
	int abc[3] = {};

	for (char c : s) {
		abc[c - 'a'] ++;
	}

	int min_v = 1e9;
	int max_v = 0;
	rep(i, 3) {
		min_v = min(min_v, abc[i]);
		max_v = max(max_v, abc[i]);
	}

	if (max_v - min_v <= 1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;		
	}

	return 0;
}


Measured memory_bytes: 3104
s = input()

c = ['KIHBR',
     'AKIHBR',
     'KIHABR',
     'KIHBAR',
     'KIHBRA',
     'AKIHABR',
     'AKIHBAR',
     'AKIHBRA',
     'KIHABAR',
     'KIHABRA',
     'KIHBARA',
     'AKIHABAR',
     'AKIHABRA',
     'AKIHBARA',
     'KIHABARA',
     'AKIHABARA']

if s in c:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>

using namespace std;

int main(){

    int n;
    int emp[10000];
    long long time;

    while(1){

        cin>>n;
        if(n==0) break;

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

        sort(emp,emp+n);

        time=0;
        for(int i=0;i<n;i++){
            time+=emp[i]*(n-1-i);
        }
        cout<<time<<endl;
    }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define next Next
const int N=1e6+5;
int n,cnt1,cnt2,gs,ama1,aid1,ama2,aid2,bma1,bid1,bma2,bid2,a[N],b[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		if(i&1)a[++cnt1]=read();
		else b[++cnt2]=read();
	sort(a+1,a+cnt1+1);
	gs=1;
	for(int i=2;i<=cnt1;i++)
		if(a[i]!=a[i-1])
		{
			if(gs>ama1)
			{
				
				ama2=ama1;
				aid2=aid1;
				ama1=gs;
				aid1=a[i-1];
			}
			else{
				if(gs>ama2)
				{
					ama2=gs;
					aid2=a[i-1];					
				}
			}
			gs=1;
		}
		else gs++;
	if(gs>1)
	{
		if(gs>ama1)
		{
			
			ama2=ama1;
			aid2=aid1;
			ama1=gs;
			aid1=a[cnt1];
		}
		else{
			if(gs>ama2)
			{
				ama2=gs;
				aid2=a[cnt1];					
			}
		}		
	}
	gs=1;
	sort(b+1,b+cnt2+1);
	for(int i=2;i<=cnt2;i++)
		if(b[i]!=b[i-1])
		{
			if(gs>bma1)
			{
				
				bma2=bma1;
				bid2=bid1;
				bma1=gs;
				bid1=b[i-1];
			}
			else{
				if(gs>bma2)
				{
					bma2=gs;
					bid2=b[i-1];					
				}
			}
			gs=1;
		}
		else gs++;
	if(gs>1)
	{
		if(gs>bma1)
		{
			
			bma2=bma1;
			bid2=bid1;
			bma1=gs;
			bid1=b[cnt2];
		}
		else{
			if(gs>bma2)
			{
				bma2=gs;
				bid2=b[cnt2];					
			}
		}		
	}
	if(aid1!=bid1)cout<<n-ama1-bma1;
	else cout<<min(n-ama1-bma2,n-ama2-bma1);	
}

Measured memory_bytes: 4480
from collections import Counter
from operator import itemgetter
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
As = [list(map(int, input().split())) for _ in range(N)]
indices = [0 for i in range(N)] 
#i+1 th person attends his (indices[i]+1) th best favorite sport.

min_turnout = N
canceled_sports = set()
for _ in range(M-1):
    popular_sport, turnout = max(Counter(As[i][indices[i]] for i in range(N)).items(), key = itemgetter(1))
    min_turnout = min(min_turnout, turnout)
    canceled_sports.add(popular_sport)
    for i in range(N):
        while As[i][indices[i]] in canceled_sports:
            indices[i] += 1

print(min_turnout)



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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int M;
int main() {
    std::cin >> M;
    std::cout << (24 + std::max(0, 24-M)) << std::endl;
}

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

#define F first
#define S second
#define nl '\n'
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define trim_chains(x) (x).resize(unique(btoe(x)) - (x).begin())
#define remove_dups(x) sort(btoe(x)); trim_chains(x);
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using ll  = long long;
using ull = unsigned long long;
using vi  = vector<int>;
using vl  = vector<long>;
using vll = vector<ll>;
using vb  = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vector<int> >;
using ii  = pair<int, int>;
using vii = vector<ii>;
using vs  = vector<string>;
using msi = map<string, int>;
using iss = istringstream;

int main()
{
    FASTIO;
    ll n; cin >> n;
    vi mod26;

    do {
        n--;
        mod26.push_back(n%26);
        n /= 26;
    } while(n > 0);
    reverse(btoe(mod26));

    string ans = "";
    for(int i : mod26) ans += ('a' + i);

    cout << ans << nl;
    return 0;
}


Measured memory_bytes: 3652
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define int long long


class AABD {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n;
      in >> n;
      if (n < 1000) {
        out << "ABC" << endl;
      } else {
        out << "ABD" << endl;
      }
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  AABD solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

ll f(vll & a, ll mid){
	int n = a.size();
    ll ops = 0;
    for (int i=0; i<n; ++i){
        ll x = a[i] / mid;
        ll MOD = a[i] % mid;
        if (MOD) x++;
        ops+=(x-1);
    }
    return ops;
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    int n; cin>>n;
    ll k; cin>>k;
    vll a;
    for (int i=0; i<n; i++){
        ll x; cin>>x;
        a.pb(x);
    }
    sort(all(a));
    ll lo = a[n-1];
    ll hi = 0;
    while(lo - 1 != hi){
        ll mid = (lo + hi) / 2;
        if (f(a, mid) <= k) lo=mid;
        else hi=mid;
    }
    cout<<lo<<'\n';
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 5336
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC\n";
    
    return 0;   
}




 
 


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

int main(){
	while(1){
		string s1,s2;
		cin>>s1;
		if(s1==".")return 0;
		cin>>s2;
		string s11[201],s22[201];
		for(int i=0;i<201;i++){
			s11[i]=".";s22[i]=".";
		}
		s11[0]="";s22[0]="";
		int now1=0,now2=0;
		for(int i=0;i<(int)s1.length();i++){
			if(s1[i]=='"'){
				now1++;
				s11[now1]="";
			}else s11[now1]+=s1[i];
		}
		for(int i=0;i<(int)s2.length();i++){
			if(s2[i]=='"'){
				now2++;
				s22[now2]="";
			}else s22[now2]+=s2[i];
		}
		int d=0;
		for(int i=0;i<201;i++){
			if(s11[i]!=s22[i]){
				if(i&1){
					d++;
				}else d+=2;
			}
		}
		if(d==0)cout<<"IDENTICAL";
		else if(d==1)cout<<"CLOSE";
		else cout<<"DIFFERENT";
		cout<<"\n";
	}
}


Measured memory_bytes: 3200
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if a & (2**i):
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
        ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()


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

void solve(long long K, long long S)
{
    long long cnt = 0;
    vector<long long> S_Z(K, 0);

    for (long long i = 0; i <= K; i++)
    {
        for (long long j = i; j <= K; j++)
        {
            for (long long k = j; k <= K; k++)
            {
                if (i + j + k == S)
                {
                    if (i == j && j == k)
                        cnt++;
                    else if (i == j || j == k || i == k)
                        cnt += 3;
                    else
                        cnt += 6;

                    break;
                }
            }
        }
    }
    cout << cnt << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    long long S;
    scanf("%lld", &S);
    solve(K, S);
    return 0;
}


Measured memory_bytes: 256
import math
import os
import random
import re
import sys

if __name__ == '__main__':
    n = int(input())

    res = math.ceil(math.log(n, 10))
    s = 1 if math.log(n, 10) % 2 == 0 else 0

    for i in range(0, res, 2):
        k = 10**(i + 1) - 1
        if n > k:
            s = s + 9 * (10 ** i)
        else:
            s = s + n - 10**i + 1
    
    print(s)

Measured memory_bytes: 4080
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
dp=[1]+[0 for _ in range(n)]
mod=1000000007
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[-1])

Measured memory_bytes: 13192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i,H)cin >> s[i];
    int cntb = 0;
    rep(i,H)rep(j,W){
        cntb += s[i][j] == '#';
    }
    queue<pair<int, int>> q;
    vector<vector<int>> d(H+5,vector<int>(W+5, -1));
    d[0][0] = 1;
    q.push({0,0});
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        rep(j,4){
            int nx = x + dx[j];
            int ny = y + dy[j];
            if(!(0 <= nx && nx < H && 0 <= ny && ny < W))continue;
            if(s[nx][ny] == '#')continue;
            if(d[nx][ny] > 0)continue;
            d[nx][ny] = d[x][y] + 1;
            q.push({nx, ny});
        }
    }
    if(d[H-1][W-1] == -1){
        cout << -1 << endl;
        return 0;
    }
    cout <<  H * W - cntb - d[H-1][W-1] << endl;
}

Measured memory_bytes: 256
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 100000000000000
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int MOD =998244353;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=2e5+100;
 

int main()
{
	ios_base::sync_with_stdio(0);
   cin.tie(0);
    cout.tie(0);
     ll t;
   //cin>>t;
   
   t=1;	
   while(t--)
    {
        ll i1,i2,k,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,n,m;
        ll x,y,z;
        ll total=0,cnt=0;
        ll flag=0;
        y=0;
        ll res,res1,ans,res2,q;
        ans=0;
        res1=0,res=0;
        ll s1,s2,s3;
        s2=0;
        ll sum=0,flag1=0;
        s1=0;
        ll k1,k2,k3;
        k1=0,k2=0;
        ll d,h,required,days;
        //cin>>h>>c>>required;
        
       cin>>n;
       ll a[n+1];
       for(i=1;i<=n;i++) cin>>a[i];
       
         ll dp[n+1];
       
         dp[1]=0;
         dp[2]=abs(a[1]-a[2]);
         
         if(n==2)
         {
         	cout<<dp[2]<<endl;
         	continue;
		 }
         
         for(i=3;i<=n;i++)
         {
         	//cout<<x<<" "<<y<<endl;
         	 dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
         	// cout<<dp[i]<<" ";
		 }
	//    cout<<endl;
		 cout<<dp[n]<<endl;
	   
	   
    	
		 
        
	  
		 
     }
    
}
	

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,m,n) for(int i=(m);i<(n);i++)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
#define ll long long
const ll INF=1LL<<60;
const ll mod=1E9+7;



int main(){
  int n;
  cin >> n;
  int s=0;
  vector<int>a(n);
  vector<vector<int>> x(n,vector<int>(n));
  vector<vector<int>> y(n,vector<int>(n));
  rep(i,n){
    cin >> a[i];
    rep(j,a[i]){
      cin >> x[i][j] >> y[i][j];
    }
  }
  int num=0,ans=0;
  for(int bit=0;bit<(1<<n);bit++){
    num=0;
    vector<int>man(n+1,0);
    rep(i,n){
      if(bit&(1<<i)){man[i+1]=1;num++;}
    }
    rep(i,n){
      if(man[i+1]==1){
	rep(j,a[i]){
	  if(man[x[i][j]]!=y[i][j])num=0;
	}
      }
    }
    ans=max(ans,num);
  }
  cout << ans;
}


Measured memory_bytes: 384
import java.util.*;
public class Main{
  public static void main(String [] args){
   Scanner i = new Scanner(System.in);
    int t = i.nextInt();
    int x = i.nextInt();
    int y = i.nextInt();
    System.out.println(Math.min(x,y) + " " + (x+y>t ? x+y-t : 0));
  }
  
  
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a[100000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int minv = a[0];
    int cnt = 0;
    while (cnt != n - 1) {
        for (int i = 1 + cnt; i < n; i++) {
            if (a[i] % minv == 0) {
                cnt++;
                a[i] = 0;
            } else {
                int tmp = a[i];
                a[i] %= minv;
                minv = min(tmp % minv, minv);
            }
        }
        sort(a, a + n);
    }
    cout << minv << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader fr = new FastReader();
		long n = fr.nextLong();
		long sum = 0;
		sum = n*(n-1)/2;
		System.out.println(sum);
	}
	
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


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

int main()
{
    int N;
    int K;
    cin >> N >> K;
    int H[N];
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    if (K >= N)
    {
        cout << "0" << endl;
        return 0;
    }
    sort(H, H + N);
    long sum = 0;
    for (int i = 0; i < N - K; i++)
    {
        sum += H[i];
    }
    cout << sum << endl;
}

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



 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.in","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	int n,i,j,t;
   	cin>>n;
   	int c1,c2,c3,c4;
   	c1=c2=c3=c4=0;
   	string s;
   	while(n--){
   		cin>>s;
   		if(s[0]=='A')c1++;
   		if(s[0]=='W')c2++;
   		if(s[0]=='T')c3++;
   		if(s[0]=='R')c4++;

   	}
   	cout<<"AC x "<<c1<<"\nWA x "<<c2<<"\nTLE x "<<c3;
   	cout<<"\nRE x "<<c4;
	
	
 
 
 
 
 
 
 
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#define NN 600
int f(int x){ return x*x; }
int main(){
	int d,h,s;
	while(scanf("%d",&d)!=EOF){
		s=0;
		for(h=d;h<NN;h+=d){
			s += d*f(h);
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var dp = new int[n];
        dp[1] = Math.Abs(h[1] - h[0]);

        for (int i = 2; i < n; i++)
        {
            dp[i] = Math.Min(
                dp[i - 1] + Math.Abs(h[i] - h[i - 1]),
                dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
        }

        Console.WriteLine(dp[n - 1]);
    }
}


Measured memory_bytes: 16864
def factorial(num):
  res = 1
  for i in range(1, num+1):
    res = res * i % (10**9+7)
  return res
a,b = map(int, input().split())
if(a - b == 0):
  print(factorial(a) * factorial(b) * 2 % (10**9+7))
elif(abs(a - b) == 1):
  print(factorial(a) * factorial(b) % (10**9+7))
else:
  print(0)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
        int n,k;
        cin >> n >> k;
        string s;
        cin >> s;

        vector<long long> a;

        int cnt=0;
        char bef='1';
        for(int i=0;i<n;i++)
        {
                if(bef==s[i])
                {
                        cnt++;
                }
                else
                {
                        a.push_back(cnt);
                        cnt=1;
                        bef=s[i];
                }
        }
        a.push_back(cnt);

        long long ans=0;
        long long tmp=0;

        if(a.size()<k*2+1)
        {
                for(int i=0;i<a.size();i++)
                        ans+=a[i];
                cout << ans << endl;
                return 0;
        }
        for(int i=0;i<k*2+1;i++)
                ans+=a[i];
  
  		tmp=ans;
  		for(int i=k*2+1;i<a.size();i+=2)
        {
				tmp-=a[i-(k*2+1)];
          		tmp-=a[i-(k*2+1)+1];
          		tmp+=a[i];
          		tmp+=a[i+1];
          		if(tmp>ans)
                  ans=tmp;
        }

//		for(int i=0;i<a.size();i++)
//			cout << a[i] << endl;

		cout << ans << endl;

}



Measured memory_bytes: 1528
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;


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

	sort(a, a + 5,greater<int>());

	for (int i = 0; i < 4; i++) {
		cout << a[i] << " ";
	}
	cout << a[4] << endl;
	
	return 0;
}

Measured memory_bytes: 3136
#include <stdio.h>
#include <math.h>

int main(){

    int A, B, H, M;
    scanf("%d%d%d%d", &A, &B, &H, &M);
    
    double pi = M_PI; // %.9f

    double thetaB = (2.0*pi*M)/60.0;
    double thetaA = (H*pi)/6.0 + (pi*M)/(6.0*60.0);
    //double thetaB = 6.0*M;
    //double thetaA = 30.0*H + M*0.50;
    //printf("%f %f\n", thetaA, thetaB);

    double theta = fabs( thetaA - thetaB );
    if( theta > pi ){
        theta = 2*pi - theta;
    }
    /*
    if( theta > 180.0 ){
        theta = 360.0 - theta;
    }
    */
    //printf("%lf\n", theta);

    //theta = (theta*pi)/180.0;

    double ans;
    ans = A*A + B*B - 2.0*A*B*cos(theta);

    printf("%.9lf\n", sqrt(ans));

    return 0;
}


Measured memory_bytes: 2596
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <tuple>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
using namespace std;

int main(void) {
    int N[4];
    cin >> N[0] >> N[1] >> N[2] >> N[3];
    sort(N, N+4);
    do {
        if (N[0]*1000 + N[1]*100 + N[2]*10 + N[3] == 1974) {
            cout << "YES" << endl;
            return 0;
        }
    } while(next_permutation(N, N+4));
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations

H, W, K = map(int, input().split())

map = [None] * H
for i in range(H):
  map[i] = [int(c) for c in input().strip()]


def a(heights=[]) -> int:
  assert len(heights) > 0
  count = len(heights) - 1

  total = {i: (0, 0) for i in range(len(heights))}
  for i in range(W):
    violate = False
    for j, height in enumerate(heights):
      n = 0
      for k in range(height[0], height[1]):
        n += map[k][i]
      if n > K:
        return -1
      total[j] = (total[j][0] + n, n)
      if total[j][0] > K:
        violate = True
    if violate:
      count += 1
      for j in range(len(heights)):
        tmp = total[j][1]
        total[j] = (tmp, tmp)
  return count


patterns = [[(0, H)]]
iterable = [i + 1 for i in range(H - 1)]
for r in range(1, H):
  for c in combinations(iterable, r):
    pattern = []
    last = 0
    for i in c:
      pattern.append((last, i))
      last = i
    pattern.append((last, H))
    patterns.append(pattern)

print(min(filter(lambda x: x >= 0, [a(p) for p in patterns])))


Measured memory_bytes: 43356
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;
int main() {
	int N, M;
	cin >> N >> M;
	bitset<10> b(false);
	vector<int> K(M);
	vector<vector<bool>> v(M,vector<bool>(N,false));
	for (int i = 0; i < M; i++) {
		int k;
		cin >> k;
		K[i] = k;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			v[i][a - 1] = true;
		}
	}
	vector<int> p(M);
	for (int i = 0; i < M; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for(ulli bi = 0ULL; bi < (1ULL << N); bi++) {
		b = bitset<10>(bi);
		int on = 0;
		for (int i = 0; i < M; i++) {
			int counter = 0;
			for (int j = 0; j < N; j++) {
				if (v[i][j] && b[j])counter++;
			}
			if (counter % 2 == p[i]) {
				on++;
			}
			else {
				break;
			}
		}
		if (on == M) {
			ans++;
		}
		
	}
	cout << ans << endl;
	return 0;
}

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

//ax+b
struct line
{
	double a;
	double b;
	line(){a=0,b=0;}
	line(double x0, double y0, double x1, double y1)
	{
		a=-(x1-x0)/(y1-y0);
		b=(y0+y1)/2.0-a*(x0+x1)/2.0;
	}
};

int main()
{
	int n;
	cin >> n;
	for(int i=0; i<n; ++i)
	{
		double x1,y1,x2,y2,x3,y3;
		cin >> x1>>y1>>x2>>y2>>x3>>y3;
		line l[2];

		if(y1==y2)
		{
			l[0] = line(x2,y2,x3,y3);
			l[1] = line(x3,y3,x1,y1);
		}
		else if(y2==y3)
		{
			l[0] = line(x1,y1,x2,y2);
			l[1] = line(x3,y3,x1,y1);
		}
		else
		{
			l[0] = line(x1,y1,x2,y2);
			l[1] = line(x2,y2,x3,y3);
		}
		
		double x = (l[1].b-l[0].b)/(l[0].a-l[1].a);
		double y = l[0].a*x+l[0].b;
		double r = sqrt( (x-x1)*(x-x1) + (y-y1)*(y-y1) );
		printf("%.3f %.3f %.3f\n", x, y, r);
	}
}

Measured memory_bytes: 0
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
a = list(map(int,input().split()))
b = [0 for _ in range(-300,301)]
for y in a:
  b[y+300] = 1
c = []
for i in range(601):
  j = i - 300
  if b[i] == 0:
    c.append([abs(x-j),j])
print(min(c)[1])

Measured memory_bytes: 9212
#include<bits/stdc++.h>
const int maxn = 5001;
typedef long long ll;
int p[maxn], n;
ll dp[maxn], a, b;
int main()
{
	std::cin >> n >> a >> b;
	for(int i = 1;i <= n;++i) std::cin >> p[i], dp[i] = (i - 1) * a;
	ll ans = 1e18;
	for(int i = 1;i <= n;++i) {
		ll s = 0; int min = 1e9;
		for(int j = i + 1;j <= n;++j) {
			if(p[i] < p[j] && p[j] < min) {
				min = p[j];
				dp[j] = std::min(dp[j], dp[i] + s);
			}
			s += p[j] < p[i] ? b : a;
		}
		ans = std::min(ans, dp[i] + (n - i) * b);
	}
	std::cout << ans << '\n';
}


Measured memory_bytes: 384
def main():
    n = int(input())
    a = list(map(int, input().split()))
    score = [0, 0]
    sort_a = sorted(a, reverse=True)

    for i in range(n):
        if i >= 2:
            sub_i = i % 2
        else:
            sub_i = i
        score[sub_i] += sort_a[i]

    print(score[0] - score[1])


if __name__ == "__main__":
    main()
    

Measured memory_bytes: 61792
def solve(string):
    n, m, *ps = string.split()
    n = int(n)
    ac = [0] * n
    wa = [0] * n
    for p, s in zip(*[iter(ps)] * 2):
        p = int(p) - 1
        if s == "AC":
            ac[p] = 1
        elif not ac[p]:
            wa[p] += 1
    return "{} {}".format(sum(ac), sum([w * a for a, w in zip(ac, wa)]))
 
 
if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Measured memory_bytes: 18980
a, b, c = map(int, input().split())
A, B, C = sorted([a, b, c])
if (C - A) % 2 == (C - B) % 2 == 0:
    print((C - A) // 2 + (C - B) // 2)
elif (C - A) % 2 == (C - B) % 2 == 1:
    print((C - A) // 2 + (C - B) // 2 + 1)
else:
    print((C - A) // 2 + (C - B) // 2 + 2)

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

using namespace std;

int main() {
  int Tc;
  double arr[6] = {}, x;
  cin >> Tc;
  while(Tc--) {
    cin >> x;
    if(x < 165.0) arr[0] ++;
    else if(x < 170.0) arr[1] ++;
    else if(x < 175.0) arr[2] ++;
    else if(x < 180.0) arr[3] ++;
    else if(x < 185.0) arr[4] ++;
    else arr[5] ++;
  }
  
  for(int i=0; i<6; i++) {
    cout << i+1 << ":";
    for(int j=0; j<arr[i]; j++) {
      cout << '*';
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>

void init(int h[],int N);
int comp(int h[],int N,int K);
int main(){
  int N,K,ct;
  int h[100000];

  scanf("%d %d",&N,&K);
  init(h,N);
  printf("%d\n",comp(h,N,K));

  return 0;
}
void init(int h[],int N){
  for(int i=0;i<N;i++)scanf("%d",&h[i]);
}
int comp(int h[],int N,int K){
  int ct=0;
  for(int i=0;i<N;i++)if(h[i]>=K)ct++;
  return ct;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		
		int x = 0;
		int xmax = 0;
		
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'I') {
				x++;
			} else {
				x--;
			}
			if(x > xmax) {
				xmax = x;
			}
		}
		System.out.println(xmax);

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
ll N, A, B;
vector<ll> h;
//X以下の爆発で全滅させることができるか？
//まず全員にBダメージをX回与え、倒せない敵に対しては追加で(A-B)ダメージを何回か与え、
//その回数の合計がX以下ならtrue
bool check(ll X)
{
    ll count = 0;
    loop(i, N)
    {
        ll now = h[i];
        now -= B * X;
        if (now > 0)
            count += (now + (A - B - 1)) / (A - B);
    }
    if (count <= X)
        return true;
    else
        return false;
}
int main()
{
    cout << fixed << setprecision(30);
    cin >> N >> A >> B;
    h.resize(N);
    loop(i, N) cin >> h[i];
    ll ok = 1e10, ng = 0;
    loop(i, 100)
    {
        ll mid = (ok + ng) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    putout(ok);
    return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

//宣言
ll N;
vector<vector<ll>> A(3,vector<ll>(3));
ll B;
vector<vector<bool>> ok(3,vector<bool>(3,false));

void solve(){
    bool ans;

    rep(i,3){
        ans = true;
        rep(j,3) if(! ok[i][j]) ans = false;
        if(ans){print("Yes");return;}
    }

    rep(i,3){
        ans = true;
        rep(j,3) if(! ok[j][i]) ans = false;
        if(ans){print("Yes");return;}
    }

    ans = true;
    rep(j,3) if(! ok[j][j]) ans = false;
    if(ans){print("Yes");return;}

    ans = true;
    rep(j,3) if(! ok[2-j][j]) ans = false;
    if(ans){print("Yes");return;}

    print("No");
    return;
}

int main() {
  //入力忘れるなよ～
  rep(i,3)rep(j,3) cin >> A[i][j];
  cin >> N;
  rep(k,N){
      cin >> B;
      rep(i,3)rep(j,3) if(A[i][j] == B) ok[i][j] = true;
  }

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int H, W;
    char s[2000][2000];
    cin >> H >> W;
    vector<int> h[2000], w[2000];
    for(int i = 0; i < H; i++) {
        h[i].push_back(-1);
    }
    for(int j = 0; j < W; j++){
        w[j].push_back(-1);
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
            if(s[i][j] == '#') {
                h[i].push_back(j);
                w[j].push_back(i);
            }
        }
    }
    for(int i = 0; i < H; i++) {
        h[i].push_back(W);
    }
    for(int j = 0; j < W; j++){
        w[j].push_back(H);
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#') continue;
            auto ptrh = upper_bound(h[i].begin(), h[i].end(), j);
            int r = *ptrh;
            ptrh--;
            int l = *ptrh;
            auto ptrw = upper_bound(w[j].begin(), w[j].end(), i);
            int u = *ptrw;
            ptrw--;
            int d = *ptrw;
            ans = max(ans, (r-l)+(u-d)-3);
            //cout << l << ' ' << r << ' ' << u << ' ' << d << endl;
        }
    }
    cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int N;

ll bit[2][1000000];

void init(){
  rep(i, 2) rep(j, 1000000) bit[i][j] = 0;
}

void add(int l, int r, int val){
  for(int i = l; i <= N; i+= (i & -i)) bit[0][i] += -val * (l-1);
  for(int i = l; i <= N; i+= (i & -i)) bit[1][i] += val;
  for(int i = r+1; i <= N; i += (i & -i)) bit[0][i] += val*r;
  for(int i = r+1; i <= N; i += (i & -i)) bit[1][i] += -val;
}

ll sum(int i){
  vector<ll> ret(2);
  for(int idx = i; idx > 0; idx -= (idx & -idx)) ret[0] += bit[0][idx];
  for(int idx = i; idx > 0; idx -= (idx & -idx)) ret[1] += bit[1][idx];
  ret[1] *= i;
  return ret[0] + ret[1];
}

int mod = 1000000007;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int Q; cin >> N >> Q;
  vector<int> A(N+1); rep(i, N) cin >> A[i+1];
  vector<int> prev(N+1, 0);
  vector<pair<pair<int, int>, int>> query(Q);
  vector<ll> ans(Q);
  
  rep(i, Q){
    int l, r; cin >> l >> r;
    query[i] = make_pair(pair<int, int>(r, l), i);
  }
  sort(query.begin(), query.end());

  int idx = 1;
  rep(q, Q){
    int right = query[q].first.first, left = query[q].first.second;
    while(idx <= right){
      add(prev[A[idx]]+1, idx, 1);
      prev[A[idx]] = idx;
      idx++;
    }
    ans[query[q].second] = sum(left) - sum(left-1);
  }
  rep(i, Q) printf("%d\n", ans[i]);
  
  /*
  add(1, 3, 1);
  rep(i, N) cout << sum(i+1) << " "; cout << endl;
  add(1, 1, 1);
  rep(i, N) cout << sum(i+1) << " "; cout << endl;
  add(3, 5, 1);
  rep(i, N) cout << sum(i+1) << " "; cout << endl;
  */
  return 0;
}

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

using namespace std;

int main(){
  string s; cin >> s;
  if((s[0]=='0' && s[1]!='0') || s[0]=='1' && (s[1]== '0' || s[1]=='1' || s[1]=='2')){
    if((s[2]=='0' && s[3]!='0') || s[2]=='1' && (s[3]== '0' || s[3]=='1' || s[3]=='2')){
      cout << "AMBIGUOUS" << endl;
    }
    else{
      cout << "MMYY" << endl;
    }
  }
  else{
    if((s[2]=='0' && s[3]!='0') || s[2]=='1' && (s[3]== '0' || s[3]=='1' || s[3]=='2')){
      cout << "YYMM" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = [0,0,0,0,0,0,0,0]
R = 0
for i in A:
    if i<400 : B[0] = 1
    elif i<800 : B[1] = 1
    elif i<1200 : B[2] = 1
    elif i<1600 : B[3] = 1
    elif i<2000 : B[4] = 1
    elif i<2400 : B[5] = 1
    elif i<2800 : B[6] = 1
    elif i<3200 : B[7] = 1
    else : R += 1
print(max(B.count(1),1),B.count(1)+R)


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

int main() {
  string S;
  cin >> S;
  if (S == "ABC") cout << "ARC" << endl;
  if (S == "ARC") cout << "ABC" << endl;
}


Measured memory_bytes: 3572