akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    string s;
    cin >> s;
    deque<char> d(s.begin(), s.end());
    bool ok = true;
    while (!d.empty()) {
        if (d.size() < 5) {
            ok = false;
            break;
        }
        string s_first_five(d.begin(), d.begin() + 5);

        if (s_first_five == "dream") {
            if (d.size() >= 7) {
                string s_next_two(d.begin() + 5, d.begin() + 7);
                if (s_next_two == "er") {
//                    dreamer -> next or dream + erase
                    if (d.size() == 7) {
                        ok = true;
                        break;
                    } else {
                        if (d.at(7) == 'a') {
                            for (auto &&i: irange(0, 5)) {
                                d.pop_front();
                            }
                            continue;
                        } else {
                            for (auto &&i: irange(0, 7)) {
                                d.pop_front();
                            }
                            continue;
                        }
                    }
                } else {
                    for (auto && i: irange(0, 5)){
                        d.pop_front();
                    }
                    continue;
                }
            } else {
                for (auto &&i: irange(0, 5)) {
                    d.pop_front();
                }
                continue;
            }
        } else if (s_first_five == "erase") {
            if (d.size() >= 6) {
                if (d.at(5) == 'r') {
                    for (auto &&i: irange(0, 6)) {
                        d.pop_front();
                    }
                    continue;
                } else {
                    for (auto &&i: irange(0, 5)) {
                        d.pop_front();
                    }
                    continue;
                }
            } else {
                for (auto &&i: irange(0, 5)) {
                    d.pop_front();
                }
                continue;
            }
        } else {
            ok = false;
            break;
        }
    }
    if (ok) {
        cout << "YES";
    } else {
        cout << "NO";
    };
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int x,vis[100001]={0};
	ll sum=0;
	for(int i=0;i<n;i++)
	{cin>>x;
	sum+=x;
	++vis[x];}
	int q,b,c;
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>b>>c;
		ll temp=vis[b];
		vis[b]=0;
		sum-=temp*b;
		vis[c]+=temp;
		sum+=temp*c;
		cout<<sum<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3984
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        while(true){
            if(!run())
                break;
        }
    }
    public static boolean run(){
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        if(N==0&&M==0){
            return false;
        }
        int[] masu = new int[N];
        int[] sai = new int[M];
        int ans = 0;
        int basho=0;
        for(int i=0;i<N;i++){
            masu[i]=Integer.parseInt(sc.next());
        }
        for(int i=0;i<M;i++){
            sai[i]=Integer.parseInt(sc.next());
        }
        int i=0;
        while(true){
            if(basho>=N-1){
                break;
            }
            ans++;
            basho+=sai[i];
            i++;
            if(basho>=N-1){
                break;
            }
            basho+=masu[basho];
        }
        System.out.println(ans);
        return true;
    }
}

Measured memory_bytes: 24948
//15:36:00 start

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace  std;
using ll=long long;
using pii=pair<int,int>;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k; cin>>n>>k;
	cout<<(n+k-3)/(k-1)<<"\n";
	return 0;
}








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



int main()
{

        char a[1500];
	int i, t, n,len,flag1,flag2;
	while (scanf("%s", a) != EOF)
	{
		flag1=flag2=0;
		len = strlen(a);
		for (i = 0; i < len; i++)
		{
			if (a[i] == 'N'&&flag1 ==0)
				flag1 = 1;
			if (a[i] == 'S'&&flag1 == 0)
				flag1 = -1;
			if (a[i] == 'W'&&flag2 == 0)
				flag2 = 1;
			if (a[i] == 'E'&&flag2 == 0)
				flag2 = -1;
			if (a[i] == 'N'&&flag1 == -1)
				flag1 = 10;
			if (a[i] == 'S'&&flag1 == 1)
				flag1 = 10;
			if (a[i] == 'W'&&flag2 == -1)
				flag2 = 10;
			if (a[i] == 'E'&&flag2 == 1)
				flag2 = 10;
		}
		if ((flag1 == 10 || flag1 == 0) && (flag2 == 10 || flag2 == 0))
			printf("Yes\n");
		else
			printf("No\n");
	}

return 0;
}

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

typedef struct _digits{
    int a,b;
    struct _digits* next;
}digits_t;

digits_t* init_d(a,b)
{
    digits_t* d;
    d=(digits_t*)malloc(sizeof(digits_t));
    d->a=a; d->b=b;
    d->next=NULL;
    return d;
}

int get_digit(int x)
{
    int cnt=0;
    while(x){
        cnt++;
        x=x/10;
    }
    return cnt;
}

//#define __DEBUG_MODE__

#ifdef __DEBUG_MODE__
#define dbg(fmt, ...)\
    printf("debug:" fmt, __VA_ARGS__)
#else
#define dbg(fmt, ...) 
#endif

int main(void)
{
    int a,b;
    int cnt;
#ifndef __DEBUG_MODE__
    FILE* fp=stdin;
#else
    FILE* fp;
    fp=fopen("./input.txt","r");
#endif
    digits_t *start,*crnt;
    start=crnt=init_d(0,0);  //start is dummy 
    while(feof(fp)==0){
        fscanf(fp,"%d %d\n",&a,&b);
        crnt=crnt->next=init_d(a,b);
        dbg("%d %d\n",a,b);
        dbg("seek:%ld\n",ftell(fp));
    }
    for(crnt=start->next;crnt!=NULL;crnt=crnt->next){
        printf("%d\n",get_digit(crnt->a+crnt->b));
    }
    return 0;
}
               
    
    

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

using namespace std;
#define int64 long long

const int N_MAX = 100010;

map<int, int> valCnt;
int n;

bool isValid() {
	if (valCnt.size() == 1) return valCnt.begin()->first == 0;
	if (valCnt.size() > 3) return false;

	if (valCnt.size() == 2) {
		return valCnt.begin()->first == 0 && valCnt.begin()->second * 2 == valCnt.rbegin()->second;
	}

	auto iter = valCnt.begin();
	auto i1 = iter;
	auto i2 = ++iter;
	auto i3 = ++iter;
	return i1->second == i2->second &&
		i1->second == i3->second &&
		(i1->first ^ i2->first) == i3->first;
}

void outerInit() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto fi = new ifstream("test.inp");
	if (*fi) {
		cin.rdbuf(fi->rdbuf());
	}
}

void readData() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int ai; cin >> ai;
		++valCnt[ai];
	}
}

void initData() {
}

void solveData() {
	cout << (isValid() ? "Yes" : "No") << "\n";
}

int main() {
	outerInit();

	readData();
	initData();
	solveData();
}

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

int main(){
  long long W,H,N,x,y,a,d,e,f,g;
  cin>>W>>H>>N;
  e=0;
  d=0;
  f=H;
  g=W;
  for(int i=0;i<N;i++){
    cin>>x>>y>>a;
    if(a==1){
      e=max(e,x);
    }
    else if(a==2){
      g=min(g,x);
    }
    else if(a==3){
      d=max(d,y);
    }
    else{
      f=min(f,y);
    }
  }
  g-=e;
  f-=d;
  if(f<=0||g<=0){
    cout<<0<<endl;
    return 0;
  }
  else{
    cout<<f*g<<endl;
  return 0;
}
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
int n, m;
char a[55][55], b[55][55];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%s", a[i]+1);
	for (int i = 1; i <= m; i++) scanf("%s", b[i]+1);
	for (int sx = 1; sx <= n - m + 1; sx++)
		for (int sy = 1; sy <= n - m + 1; sy++) {
			bool f = true;
			for (int i = sx; i <= sx + m - 1; i++)
				for (int j = sy; j <= sy + m - 1; j++)
					if (a[i][j] != b[i-sx+1][j-sy+1]) f = false;
			if (f) {
				printf("Yes\n");
				return 0;
			}
		}
	printf("No\n");
	return 0;
}

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

int main() {
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    n--;
    ll ans = max({n/a, n/b, n/c, n/d, n/e})+5;

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


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

const int di[]={0,1};
const int dj[]={1,0};


int main(){
  int h,w,i,j;
  cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  int n=0;
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      cin >> a[i][j];
      if(a[i][j]=='#'){
        n++;
      }
    }
  }
  if(n==h+w-1){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

s = readChar()[::-1]

t = ["maerd","remaerd","esare","resare"]

jud = ["mae","rem","esa","res"]

while s!="":
	if s[:3] in jud:
		x = jud.index(s[:3])
		if x==0 or x==2:
			if s[:5]==t[x]:
				s = s[5:]
			else:
				print("NO")
				exit()
		elif x==1:
			if s[:7]==t[x]:
				s = s[7:]
			else:
				print("NO")
				exit()
		elif x==3:
			if s[:6]==t[x]:
				s = s[6:]
			else:
				print("NO")
				exit()
		else:
			print(-1)
			exit()
	else:
		print("NO")
		exit()

print("YES")

Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}


int main() {
    string S;
    cin >> S;
    vector<vector<ll>> dp(S.size(), vector<ll>(4, 0));
    if(S[0]=='?') {
        dp[0][0] = 3;
        dp[0][1] = 1;
    }
    else {
        dp[0][0] = 1;
        if(S[0]=='A') dp[0][1] = 1;
    }
    FOR(i, 1, S.size()-1) {
        if(S[i] == '?') {
            dp[i][0] = dp[i-1][0] * 3 % MOD;
            FOR(j, 1, 3) {
                dp[i][j] = dp[i-1][j-1];
                dp[i][j] = (dp[i][j] + dp[i-1][j] * 3) % MOD;
            }
        } else {
            dp[i][0] = dp[i-1][0];            
            FOR(j, 1, 3) {
                if(S[i]-'A'==j-1) dp[i][j] = dp[i-1][j-1];
                dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            }
        }
    }
    cout << dp[S.size()-1][3] << endl;
	return 0;
}

Measured memory_bytes: 7424
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        String x = scn.next();
        int answer = 0;
        for(int i=0;i<x.length();i++){
            char buf = x.charAt(i);
            if(buf=='+'){
                answer++;
            }else{
                answer--;
            }
        }
        System.out.println(answer);
    }
}


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

string S; int N;
long long power[200009], dp[200009], mod = 998244353;

void init() {
	power[0] = 1;
	for (int i = 1; i <= 200000; i++) power[i] = (2LL * power[i - 1]) % mod;
}

long long find_value(long long K) {
	string V1 = S.substr(0, S.size() / K);
	string V2 = V1; for (int i = 0; i < V2.size(); i++) { if (V2[i] == '0') V2[i] = '1'; else V2[i] = '0'; }

	string V = "";
	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) V += V1;
		else V += V2;
	}

	long long val = 0;
	for (int i = 0; i < V1.size(); i++) {
		if (V1[i] == '1') val += power[V1.size() - 1 - i];
		val %= mod;
	}

	if (V <= S) return (val + 1LL) % mod;
	return val;
}

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

	vector<long long> R;
	for (int i = 1; i <= N; i += 2) {
		if (N%i != 0) continue;
		R.push_back(i);
	}

	for (int i = (int)R.size() - 1; i >= 0; i--) {
		dp[i] = find_value(R[i]);
		for (int j = i + 1; j < (int)R.size(); j++) {
			if (R[j] % R[i] == 0) { dp[i] -= dp[j]; dp[i] += mod; dp[i] %= mod; }
		}
	}

	long long ans = 0;
	for (int i = 0; i < R.size(); i++) {
		long long c1 = ((2LL * N) / R[i]);
		long long c2 = dp[i];
		ans += c1 * c2;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const int N = 2e5 + 5;
const int mod = 998244353;
const int inf = 2e9;
const ll INF = 2e18;
const ld eps = 1e-9;

int n, s;
int dp[3001][3001];
int a[N];

int add(int a, int b) {
    a += b;
    if(a >= mod) return a - mod;
    return a;
}

int main() {
#ifndef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
    cin >> n >> s;
    fr(i, 1, n) cin >> a[i];
    dp[0][0] = 1;
    fr(i, 1, n) {
        fr(j, 0, s) {
            if(j - a[i] >= 0) {
                dp[i][j] = add(dp[i][j], dp[i - 1][j - a[i]]);
            }
            dp[i][j] = add(dp[i][j], dp[i - 1][j]);
            dp[i][j] = add(dp[i][j], dp[i - 1][j]);
        }
    }
    cout << dp[n][s] << "\n";
}

Measured memory_bytes: 38848
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    constexpr int K = 10, L = K * 2, T = (1 << K) - 1;
    constexpr ll S = T | (ll)T << L | (ll)T << (L * 2), X = ((1ULL << (L * 3)) - 1) / T;
    ll p0[L] = {};
    ll r = 0;

    for (int i0 = 0; i0 < n; i0 += T) {
        ll p[K] = {};
        int i1 = min(T, n - i0);
        for (int i = 0; i < i1; i++) {
            ll a;
            cin >> a;

            for (int k = 0; k < K; k++) {
                p[k] += a & X;
                a >>= 1;
            }
        }

        for (int k = 0; k < K; k++) {
            ll c = p[k];
            for (int h = 0; h < 2; h++) {
                p0[K * h + k] += c & S;
                c >>= K;
            }
        }
    }

    for (int k = 0; k < L; k++) {
        ll c = p0[k];
        for (int h = 0; h < 3; h++) {
            ll t = c & ((1LL << L) - 1);
            c >>= L;
            r += (1LL << (L * h + k)) % P * t % P * (n - t) % P;
        }
    }
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <string>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;



int main(){
	
	int n; cin >> n;
	
	int f[n][10] = {};
	for(int i=0; i<n; i++){
		for(int j=0; j<10; j++){
			cin >> f[i][j];
		}
	}
	
	int p[n][10];
	for(int i=0; i<n; i++){
		for(int j=0; j<11; j++){
			cin >> p[i][j];
		}
	}
	
	int fbit[n]={};
	for(int i=0; i<n; i++){
		int mal = 1;
		for(int j=0; j<10; j++){
			fbit[i] += mal*f[i][j];
			mal *= 2;
		}
	}
	
	//cout << fbit[0] << " " << fbit[1] << endl;
	
	
	// for(int i=0; i<n; i++){
	// 	for(int j=0; j<10; j++){
	// 		cout << f[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	
	// for(int i=0; i<n; i++){
	// 	for(int j=0; j<11; j++){
	// 		cout << p[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	
	
	//cout << "input completed" << endl;
	
	ll ans = -1e18;
	for(int bit=1; bit < (1<<10); bit++){
		//cout << bit << endl;
		ll tempans = 0;
		for(int i=0; i<n; i++){
			int c = 0;
			int bothbit = (bit & fbit[i]);
			while(bothbit > 0){
				if(bothbit % 2 == 1) c++;
				bothbit /= 2;
			}
			tempans += p[i][c];
		}
		ans = max(ans, tempans);
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	int S[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &S[i]);
	}

	int cnt = 0;

	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int T;
		scanf("%d", &T);
		for (int j = 0; j < n; ++j) {
			if (S[j] == T) {
				++cnt;
				break;
			}
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3212
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
bool used[110];
int b[110];
vector<int> out;
int main()
{
	int n;cin>>n;rep(i,n) cin>>b[i];
	rep(i,n){
		if(b[i]>i+1){
			cout<<-1<<endl;return 0;
		}
	}
	memset(used,false,sizeof(used));
	rep(i,n){
		int f=0,t=0;
		rep(j,n){
			if(used[j]) continue;
			t++;
			assert(b[j]<=t);
			if(b[j]==t) f=max(f,j);
		}
		out.pb(b[f]);
		used[f]=true;
	}
	reverse(All(out));
	rep(i,n) cout<<out[i]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
  
  int main(void) {
  
  	int a=0,b=0,c=0;
   	scanf("%d%d%d",&a,&b,&c);
  
   	if (c>=a&&c<=b) {
    	printf("Yes\n");
    }
    else {
    	printf("No\n");
    }
    
    return 0;
  }

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    int n;
    string s;
    cin>>s;
    n=s.size()+1;
    vector<ll> a(n, 0);
    for(int i=0;i<n-1;i++){
        if(s[i]=='<'){
            a[i+1]=max(a[i+1], a[i]+1);
        }
    }
    for(int i=n-2;i>=0;i--){
        if(s[i]=='>'){
            a[i]=max(a[i],a[i+1]+1);
        }
    }
    ll ans=0;
    rep(i,n){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int s[1010];
int k[1010];
int c[1010][10010];
vector<int> anst;
int max_point[10010];
int min_point[10010];

int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		REP(i,10010){
			max_point[i]=0;
			min_point[i]=0;
		}
		for(int i=0;i<m;i++){
			cin>>s[i];
			cin>>k[i];
			for(int j=0;j<k[i];j++){
				cin>>c[i][j];
				max_point[c[i][j]]+=s[i];
			}
			if(k[i]==1)min_point[c[i][0]]+=s[i];
		}
		int amax=1,amin=1;
		int amax2=2,amin2=2;
		if(max_point[amax]<max_point[amax2]){
			amax=2;
			amax2=1;
		}
		if(min_point[amin]>min_point[amin2]){
			amin=2;
			amin2=1;
		}
		for(int i=3;i<=n;i++){
			if(max_point[amax]<max_point[i]){
				amax2=amax;
				amax=i;
			}else if(max_point[amax2]<max_point[i]){
				amax2=i;
			}
			if(min_point[amin]>min_point[i]){
				amin2=amin;
				amin=i;
			}else if(min_point[amin2]>min_point[i]){
				amin2=i;
			}
		}
		int ans;
		if(amax!=amin){
			ans=max_point[amax]-min_point[amin];
		}else{
			ans=max(max_point[amax2]-min_point[amin],max_point[amax]-min_point[amin2]);
		}	
		cout<<ans+1<<endl;	
	}
	return 0;
}


Measured memory_bytes: 8132
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define isOdd(a) ((a) % 2 == 1)

int main(int argc, char *argv[]){

	int N;

	scanf("%d", &N);

	int A[N];

	int peternNum = 1;
	int allOddPeternNum = 1;
	int i;
	for(i=0;i<N;i++){
		scanf("%d", &A[i]);

		peternNum *= 3;

		if(!isOdd(A[i])){
			allOddPeternNum *= 2;
		}
	}

	printf("%d\n", peternNum - allOddPeternNum);

	return 0;
}

Measured memory_bytes: 128
N,K=map(int,input().split())
A=[int(x) for x in input().split()]

dic={}
for i in range(N):
  if A[i] in dic:
    dic[A[i]]+=1
  else:
    dic[A[i]]=1

if K >= len(dic):
  print(0)
else:
  cnt=len(dic)-K
  ans=0
  for k, v in sorted(dic.items(), key=lambda x:x[1]):
    if cnt==0:
      break
    else:
      cnt-=1
      ans+=v
  print(ans)

Measured memory_bytes: 40068
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

// {waapu, h, w}
using p = tuple<int, int, int>;

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

    int h_size, w_size;
    cin >> h_size >> w_size;
    auto in_sq = [&](int h, int w) {
        return 0 <= h and h < h_size and 0 <= w and w < w_size;
    };
    int h_from, w_from;
    cin >> h_from >> w_from;
    --h_from;
    --w_from;
    int h_to, w_to;
    cin >> h_to >> w_to;
    --h_to;
    --w_to;
    vector can_go(h_size, vector<bool>(w_size));
    rep(h, h_size)
    {
        rep(w, w_size)
        {
            char c;
            cin >> c;
            can_go[h][w] = (c == '.');
        }
    }

    // 01bfs
    int ans = -1;
    vector dist(h_size, vector<int>(w_size, 1000'000));
    deque<p> qu;
    vector used(h_size, vector<bool>(w_size, false));

    qu.emplace_back(0, h_from, w_from);
    while (not qu.empty())
    {
        auto [cost, h_old, w_old] = qu.front();
        qu.pop_front();
        if (h_old == h_to and w_old == w_to)
        {
            ans = cost;
            break;
        }
        if (used[h_old][w_old])
        {
            continue;
        }
        used[h_old][w_old] = true;
        FOR(dh, -2, 2)
        {
            FOR(dw, -2, 2)
            {
                auto h_new = h_old + dh, w_new = w_old + dw;
                if (not in_sq(h_new, w_new) or not can_go[h_new][w_new] or used[h_new][w_new])
                {
                    continue;
                }
                int dcost = (abs(dh) + abs(dw) > 1);
                if (not chmin(dist[h_new][w_new], cost + dcost))
                {
                    continue;
                }
                if (dcost)
                {
                    qu.emplace_back(cost + dcost, h_new, w_new);
                }
                else
                {
                    qu.emplace_front(cost + dcost, h_new, w_new);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7956
# Problem_name : Otoshidama
'''
story_is_true = False
bills = [0, 0, 0]

N = int(input())
Y = int(input())

if story_is_true:
    print('10000円札{0}枚，5000円札{1}枚，1000円札{2}枚'.format(bills[0],bills[1],bills[2]))
'''

A = set(int(e) for e in input().split())
if len(A) == 2:
    print('Yes')
else:
    print('No')

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

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





using ll = long long;


const int maxn = 1e6 + 5;
const int inf = 1e9;


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

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

    int n, m, k;
    cin>>n>>m>>k;

    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    --x1; --y1; --x2; --y2;

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



    vector<vector<int>> dist(n, vector<int>(m, inf));
    vector<vector<int>> viz(n, vector<int>(m, 0));

    dist[x1][y1] = 0;
    viz[x1][y1] = 0;


    queue<pair<int,int>> qq;
    qq.push({x1,y1});

    while (qq.size()) {
	int x = qq.front().first;
	int y = qq.front().second;
	qq.pop();

	for (int dir=0; dir<4; dir++) {
	    for (int i=1; i<=k; i++) {
		int nx = x+dx[dir]*i;
		int ny = y+dy[dir]*i;
		if (nx<0 || ny<0 || nx>=n || ny>=m) break;
		if (g[nx][ny] == '@') break;
		
		if (1+dist[x][y] > dist[nx][ny]) break;
		if (viz[nx][ny]) continue;

		dist[nx][ny] = 1+dist[x][y];
		viz[nx][ny] = 1;
		qq.push({nx,ny});
	    }
	}
    }

    if (!viz[x2][y2]) out(-1);
    cout<<dist[x2][y2]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 16276
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
    if(a>b){swap(a,b);}
    if(a==0){return b;}
    else{return gcd(a,b%a);}
}
long long factor(long long n){
    long long ret=0;
    long long m=n;
    for(long long i=2;i*i<=n;i++){
        if(m%i==0){
            ret++;
                while(m%i==0){
                m/=i;
            }
        }
    }
    if(m!=1){ret++;}
    return ret;
}
int main(){
    long long a,b,ans=0;
    cin>>a>>b;
    long long g=gcd(a,b);
    cout<<factor(g)+1<<endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
main(){
  int x,y,w,h,n,tx,ty,cnt,i;
  cin>>x;
  while(cin>>x>>y>>w>>h>>n){
    for(i=0,cnt=0;i<n;i++){
      cin>>tx>>ty;
      if (x<=tx&&tx<=x+w&&y<=ty&&ty<=y+h)cnt++;
    }
    cout <<cnt<< endl;
  }
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 2001

using namespace std;

int main()
{
	int a, b, x, v;
	cin >> a >> b >> x;
	v = a*a*b;

	double Rad_to_deg = 45.0 / atan(1.0);

	if (x <= v/2)
	{
		double tan = double(a)*b*b / (2 * x);
		printf("%0.7lf\n", atan(tan)*Rad_to_deg);
	}
	else
	{
		double tan = double(v-x)*2/(a*a*a);
		printf("%0.7lf\n", atan(tan)*Rad_to_deg);
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int N; cin >> N;
    int ans = 0;
    rep(i, 0, N){
        int l, r; cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
p = [False for _ in range(n + 1)]
ze = [0 for _ in range(n + 1)]
ac = 0
wa = 0

for i in range(m):
    string = input().split()
    prob = int(string[0])
    res = string[1]
    if p[prob]:
        pass
    elif res == "AC":
        p[prob] = True
        wa += ze[prob]
        ac += 1
    else:
        ze[prob] += 1

print(ac, wa)


Measured memory_bytes: 4760
r, c = map(int, input().split())
table = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
  work = list(map(int, input().split()))
  for j in range(c):
    table[i][j] = work[j]

for i in range(r):
  sum = 0
  for j in range(c):
    sum += int(table[i][j])
  table[i][c] = sum

for i in range(c+1):
  sum = 0
  for j in range(r):
    sum += int(table[j][i])
  table[r][i] = sum

for i in range(0,r+1):
  print("%d"%(table[i][0]),end="")
  for j in range(1,c+1):
    print(" %d"%(table[i][j]),end = "")
  print()


Measured memory_bytes: 6300
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	int n, m,tmp=0,ax=0;
	string str, str2[5000];
	cin >>n>> str;
	
	for (int i = 0; i < n; i++) {
		if (str[i] == 'I') { tmp++; }
		if (str[i] == 'D') { tmp--; }
		if (tmp > ax) { ax = tmp; }
	}
	cout <<ax;
}

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

int main()
{
	int h, w; cin >> h >> w;
	
	const int cSize = 10;

	vector<vector<int>> c(cSize, vector<int>(cSize));
	for (int i = 0; i < cSize; i++) {
		for (int j = 0; j < cSize; j++) {
			cin >> c[i][j];
		}
	}

	const int rangeMaximum = 10;
	vector<int> num(rangeMaximum, 0);
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			int tmp_a; cin >> tmp_a;
			if(0 <= tmp_a) num[tmp_a]++;
		}
	}

	int n = cSize;
	for (int k = 0; k < n; k++) {       // 経由する頂点
		for (int i = 0; i < n; i++) {    // 始点
			for (int j = 0; j < n; j++) {  // 終点
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < rangeMaximum; i++) ans += c[i][1] * num[i];

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

Measured memory_bytes: 256
H,W=map(int,input().split())
s=[input() for _ in range(H)]

for i in range(H):
  h=i
  for j in range(W):
    if s[h][j]=='#':
      w=j
      cnt=0
      for k,l in ([1,0], [-1,0], [0,1], [0,-1]):
        new_h, new_w=h+k, w+l
        if new_h<0 or new_h>=H or new_w<0 or new_w>=W:
          continue
        elif s[new_h][new_w] == '#':
          cnt+=1
          break
      if cnt==0:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
h, w = map(int, input().split())
while (not ((h == 0)and(w==0)) ):
    for i in range(0,h):
        if ((i % 2)==0):
            c = '#'
            s = ''
            for j in range(0,w):
                s += c
                if (c == '#'):
                    c = '.'
                else:
                    c = '#'
            print(s)
        else:
            c = '.'
            s = ''
            for j in range(0,w):
                s += c
                if (c == '#'):
                    c = '.'
                else:
                    c = '#'
            print(s)
    print()
    h, w = map(int, input().split())



Measured memory_bytes: 5608
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL d;
    cin >> n >> d;
    vector<LL> x(n);
    vector<LL> y(n);
    for(LL i=0; i<n; i++){
        cin >> x[i] >> y[i];
    }
    LL ans=0;
    for(LL i=0; i<n; i++){
        if(x[i]*x[i]+y[i]*y[i]<=d*d){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}


signed main(void){
    ll n,k;
    cin>>n>>k;
    cout << min(n%k,k-n%k) << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    a = input()
    if a.islower():
        print("a")
    else:
        print("A")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9040
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200005];
	scanf("%s", s);
	int i, n = strlen(s);
	int ans = 1;
	int l;
	l = 1;
	for (i = 1; i < n; i++)
	{
		if (l == 2)
		{
			ans++;
			l = 1;
		}
		else
		{
			if (i < n - 1)
			{
				if (s[i] != s[i - 1])
					ans++;
				else
				{
					ans++;
					i++;
					l = 2;
				}
			}
			else
			{
				if (s[i] != s[i - 1])
					ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

int N, A, B;
vi h(100050);

bool ok(int k) {
    int cnt = 0;
    rep(i, N) {
        cnt += (max(0, h[i]-k*B)+(A-B-1))/(A-B);
    }
    return cnt<=k;
}

signed main() {
    cin >> N >> A >> B;
    rep(i, N) cin >> h[i];

    int l=-1, r=1e9, mid;
    while(abs(l-r)>1) {
        mid = (l+r)/2;
        if(ok(mid)) r=mid;
        else l=mid; 
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
int cnt=0;
int longPath(int *dp,int u,vector<vector<int> > &graph){
    //cout<<u<<" ";
    cnt++;
    if(dp[u] != -1){
        return dp[u];
    }
    if(graph[u].empty()){
        dp[u]=0;
        return dp[u];
    }
    int i;
    for(i = 0;i<graph[u].size();i++){
        dp[u] = max(dp[u],1+longPath(dp,graph[u][i],graph));
    }
    return dp[u];
}
int solve(vector<vector<int> > &graph,int*dp,int n){
    int i;
    for(i=1;i<=n;i++)
    {
        if(graph[i].empty())
            dp[i]=0;
        if(dp[i] == -1)
            dp[i]= longPath(dp,i,graph);
    }
    int max = 0;
    for(i=1;i<=n;i++){
        if(max<dp[i]){
            max = dp[i];
        }
    }
    return max;
}
int main() {
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<vector<int> > graph(n+2);
    int dp[n+2];
    int i;
    memset(dp,-1,sizeof(dp));
    for(i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
    }
    cout<<solve(graph,dp,n)<<endl;
   // cout<<cnt;
    return 0;
}

Measured memory_bytes: 8192
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n,k;
  cin >> n >> k;

  vll as(n);
  rep(i, n) cin >> as[i];

  Sort(as);
  ll ans = 0;
  rep(i, k) ans += as[n - 1 - i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long int memo[100001]={0};

int main(){
  int N,M;
  bool a[100000]={false};
  cin >> N >> M ;
  for(int i=0;i<M;i++){
    int in;
    cin >> in;
    a[in]=true;
  }
  memo[0]=1;
  for(int i=1;i<=N;i++){
    if(a[i]==true)continue;
    if(i==1){
      memo[i]=memo[0];
    }else{
      memo[i]=memo[i-1]+memo[i-2];
      memo[i]%=1000000007;
    }
  }
  cout << memo[N] << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<queue>
#include<cstdlib>
#include<string>
#include<algorithm>

#define MAX_N 100000

using namespace std;

struct Job {
    string name;
    int time;
};

int main()
{
    int n, q, i, j, time;
    string name;
    queue<Job> jobs;
    Job nowJob;
    cin >> n >> q;
    for (i = 0; i < n; i++) {
        cin >> nowJob.name >> nowJob.time;
        jobs.push(nowJob);
    }
    time = 0;
    while (!jobs.empty()) {
        nowJob = jobs.front();
        if (nowJob.time <= q) {
            time += nowJob.time;
            cout << nowJob.name << ' ' << time << endl;
            jobs.pop();
        }
        else {
            nowJob.time -= q;
            time += q;
            jobs.pop();
            jobs.push(nowJob);
        }
    }

    return 0;
}

Measured memory_bytes: 6332
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;


int main(void){
    string s;
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy"<<endl;
    if(s=="Cloudy")cout<<"Rainy"<<endl;
    if(s=="Rainy")cout<<"Sunny"<<endl;
    return 0;
}

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

typedef struct{
  double x;
  double y;
} Point;

void koch(int n,Point a,Point b){
  double rad;
  Point s,t,u;
  if (n == 0) return ;
  rad = M_PI*60.0/180.0;

  s.x = (2.0*a.x + 1.0*b.x)/3.0;
  s.y = (2.0*a.y + 1.0*b.y)/3,0;
  t.x = (1.0*a.x + 2.0*b.x)/3.0;
  t.y = (1.0*a.y + 2.0*b.y)/3.0;
  u.x = (t.x - s.x)*cos(rad) - (t.y - s.y)*sin(rad) + s.x;
  u.y = (t.x - s.x)*sin(rad) + (t.y - s.y)*cos(rad) + s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  Point a,b;
  int n;
  scanf("%d",&n);

  a.x = 0.0;
  a.y = 0.0;
  b.x = 100.0;
  b.y = 0.0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main()
{
  while (1)
  {
    string x;
    getline(cin, x);
    if (x == "0")
      break;

    int sum = 0;
    for (int i = 0; i < x.size(); i++)
    {
      sum += (x[i] - '0');
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>
int main(void){
  int n,m,i,max=0;
  int num[10000];
  
  scanf("%d",&n);
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&num[i]);
    max+=num[i];
  }
  if(n>=max){
    printf("%d",n-max);
  }
  else{
    printf("%d",-1);
  }
  return 0;
}


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


int main()
{
	int n;
	cin >> n;
	vector<tuple<string, int, int>> ap(n);
	for (int i = 0; i < n; i++) {
		string s_in;
		int p_in;
		cin >> s_in >> p_in;
		ap.at(i) = (make_tuple(s_in, p_in, i + 1));
	}

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

	stack<int> s;
	for (int i = 0; i < n; i++) {
		s.push(get<2>(ap.at(i)));
		int s_size = s.size();
		if (i != n - 1) {
			if (get<0>(ap.at(i)) != get<0>(ap.at(i + 1))) {
				for (int j = 0; j < s_size; j++) {
					int s_out = s.top();
					s.pop();
					cout << s_out << endl;
				}
			}
		}
		if (i == n - 1) {
			for (int j = 0; j < s_size; j++) {
				int s_out = s.top();
				s.pop();
				cout << s_out << endl;
			}
		}
	}

}


Measured memory_bytes: 256