akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int	main()
{
	int arr[2][105];
	int n;
	cin >> n;
	arr[0][0] = 0;
	arr[1][n+1] = 0;
	for (int i = 0; i <2; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin>>arr[i][j];
		}
	}
	
		for (int j = 1; j <= n; j++)
		{
			arr[0][j] += arr[0][j - 1];
		}
		for (int j = n; j >= 1; j--)
		{
			arr[1][j] += arr[1][j + 1];
		}
	int maxn = 0;
	for (int i = 1; i <= n; i++)
	{
		maxn = max(maxn, arr[0][i] + arr[1][i]);
	}
	cout << maxn << endl;
	return 0;
}

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

int main() {
    int n , k;
    cin >> n >> k;
    vector<int> d(k);
    vector<vector<int>> a(k);
    for (int i = 0; i < k; i++) {
        cin >> d.at(i);
        for (int j = 0; j < d.at(i); j++) {
            int data;
            cin >> data;
            a.at(i).push_back(data);
        }
    }

    vector<bool> ans(n, false);
    int cnt = 0;

    for (int i = 0; i < k; i++) {
        //cout << d.at(i);
        for (int j = 0; j < d.at(i); j++) {
            //cout << a.at(i).at(j);
            ans.at(a.at(i).at(j) - 1) = true;
        }
        //cout << endl;
    }

    for (int i = 0; i < n; i++) {
        if (ans.at(i) == false) {
            cnt++;
        }
    }

    cout << cnt << endl;
    
}

Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 100003;
struct Edge {
	int to, nxt;
	Edge() {}
	Edge(int to, int nxt):to(to), nxt(nxt) {}
}e[MAXN << 1];
int h[MAXN], p;
int w[MAXN], du[MAXN], fa[MAXN];
int n, rt;
bool fg = 1;

inline void add_edge(int a, int b) {
	e[++p] = Edge(b, h[a]); h[a] = p;
	e[++p] = Edge(a, h[b]); h[b] = p;
}

int dfs(int u) {
	int s = 0, mx = 0;
	bool son = 0;
	for(int i = h[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if(v == fa[u]) continue;
		son = 1;
		fa[v] = u;
		int cur = dfs(v);
		s += cur;
		mx = max(mx, cur);
	}
	if(!son) return w[u];
	if(w[u] > s || w[u] < mx || 2 * w[u] < s) {
		fg = 0;
		return 0;
	}
	return 2 * w[u] - s;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", w + i);
	for(int i = 1, a, b; i < n; i++) {
		scanf("%d%d", &a, &b);
		add_edge(a, b);
		du[a]++; du[b]++;
	}
	if(n == 2) {
		if(w[1] == w[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	int res = 0;
	for(int i = 1; i <= n; i++) if(du[i] > 1) {
		res = dfs(i);
		break;
	}
	if(res == 0 && fg == 1) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int n;

int nagomi(long long num, int thr, int fiv, int sev){
	if(num>n)
		return 0;
	int num1=0;
	if(thr && fiv && sev)
		num1++;
	int num3 = nagomi(num*10+3, thr+1, fiv, sev);
	int num5 = nagomi(num*10+5, thr, fiv+1, sev);
	int num7 = nagomi(num*10+7, thr, fiv, sev+1);
	return num1+num3+num5+num7;
}

int main(){
	cin >> n;
	cout << nagomi(0,0,0,0) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder.ABC101
{
    public class A
    {
        public static void Solve()
        {
            string[] input = Console.ReadLine().Split(' ');
            string s1 = input[0];

            int cnt = 0;
            for (int i = 0; i < s1.Length; i++)
            {
                if (s1[i].ToString() == "+")
                {
                    cnt++;
                }
                if (s1[i].ToString() == "-")
                {
                    cnt--;
                }
            }
            
            Console.WriteLine(cnt);
        }    
    }
}

namespace AtCoder {
    class Program
    {
        static void Main(string[] args)
        {
            ABC101.A.Solve();
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main()
{
	int M, K;

	scanf("%d %d", &M, &K);

	if (K != 0)
	{
		int res = 0;

		for (int i = 0; i < (1 << M); ++i)
		{
			if (i == K) continue;
			res ^= i;
		}

		if (res != K) printf("-1\n");
		else
		{
			printf("%d ", K);
			for (int i = 0; i < (1 << M); ++i)
			{
				if (i == K) continue;
				printf("%d ", i);
			}
			printf("%d ", K);
			for (int i = (1 << M) - 1; i >= 0; --i)
			{
				if (i == K) continue;
				printf("%d ", i);
			}
			printf("\n");
		}
	}
	else
	{
		for (int i = 0; i < (1 << M); ++i) printf("%d %d ", i, i);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    ll m;
    cin>>m;
    int v,p;
    cin>>v>>p;
    p = n-p;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    //rep(i,n)cout<<a[i];cout<<endl;
    ll ok=n-1;
    ll ng=-1;
    while(1<abs(ok-ng)){
        int mi=(ok+ng)/2;
        //cout<<mi<<endl;
        if (mi>=p){
            ok=mi;
        }
        else if(p>mi){
            if(a[mi]+m<a[p]){
                ng=mi;
            }
            else{
                ll cnt=abs(p-mi);
                if(v<=n-cnt){
                    //cout<<mi<<" "<<cnt<<" "<<ng<<endl;
                    ok=mi;
                }
                else{
                    ll res = 0;
                    REP(j,mi+1,p+1){
                        res+=a[mi]+m-a[j];
                    }
                    if(res+(n-cnt)*m>=v*m){
                        ok=mi;
                    }
                    else{
                        ng=mi;
                    }
                }
            }
        }
    }
    cout<<n-ok<<endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	int a, b;
	int cnt[102];
	while (scanf("%d %d", &a, &b) != EOF) {
		Fill(cnt, 0);
		cnt[a]++, cnt[b]++;
		while (scanf("%d %d", &a, &b), a) {
			cnt[a]++, cnt[b]++;
		}
		int ok = 0;
		for (int i = 3; i <= 100; i++) {
			ok += cnt[i] % 2;
		}
		string ans = (ok == 0 && cnt[1] % 2 && cnt[2] % 2) ? "OK" : "NG";
		dump(ans);
	}

	return 0;
}



Measured memory_bytes: 3200
#include <stdio.h>
#include <math.h> 
int main()
{   long long n,k;
    scanf("%lld%lld",&n,&k);
    if(k%2==1){
        long long z=pow(n/k,3);
        printf("%lld",z);
    }else if(n%k>=k/2){
        long long z=pow(n/k+1,3)+pow(n/k,3);
        printf("%lld",z);
    }else{
        long long z=2*pow(n/k,3);
        printf("%lld",z);
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n + 1 - h) * (n + 1 - w) << endl;
}


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

using namespace std;

int main(void) {
    vector<int> v(3);
    for(int i=0; i<3; i++) {
        cin >> v[i];
    }

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

    cout << v[0] + v[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
vector<int> P, Q;

vector<int> tmp;
int solveA(int n){
    if(n == N){
        if(tmp <= P) return 1;
        else return 0;
    }
    int ret = 0;
    rep(i, N){
        bool flg = false;
        rep(j, n)
            if(tmp[j] == i) flg = true;
        if(!flg){
            tmp.pb(i);
            ret += solveA(n+1);
            tmp.pop_back();
        }
    }
    return ret;
}
int solveB(int n){
    if(n == N){
        if(tmp <= Q) return 1;
        else return 0;
    }
    int ret = 0;
    rep(i, N){
        bool flg = false;
        rep(j, n)
            if(tmp[j] == i) flg = true;
        if(!flg){
            tmp.pb(i);
            ret += solveB(n+1);
            tmp.pop_back();
        }
    }
    return ret;
}
signed main(){
    cin >> N;
    P.resize(N); Q.resize(N);
    rep(i, N){
        cin >> P[i];
        P[i]--;
    }
    rep(i, N){
        cin >> Q[i];
        Q[i]--;
    }

    int a = solveA(0);
    int b = solveB(0);
    cout << abs(a-b) << endl;
}

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

int main() {
	// your code goes here
	int k;
	cin>>k;
	int a,b;
	cin>>a>>b;
	bool flag=false;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			flag=true;
			break;
		}
	}
	if(flag)
		cout<<"OK\n";
	else
		cout<<"NG\n";
		
	return 0;
}

Measured memory_bytes: 3632
main=do
 getLine
 a<-map read.words<$>getLine
 b<-map read.words<$>getLine
 let u=zipWith(-)b a
 let s=sum u
 putStrLn$if s<(negate$sum$filter(<0)u)||s<(sum$map(flip div 2.(1+))$filter(>0)u) then "No" else "Yes"

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

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

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, p;cin >> a >> p;
    cout << (a*3+p)/2 << endl;
    return 0;
}


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

#define N 100
#define MAX 100000

int main(void) {
    int n, p[N + 1], m[N + 1][N + 1];
    
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> p[i - 1] >> p[i];
    }
    
    for(int i = 1; i<= n; ++i) m[i][i] = 0; //対角成分は0;
    for(int l = 2; l <= n; ++l) {
        for(int i = 1; i <= n - l + 1; ++i) {
            int j = i + l - 1;
            m[i][j] = MAX;
            for(int k = i; k <= j - 1; ++k) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
}


Measured memory_bytes: 3120
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
int main(){
    init();

    ll M,N;cin>>M>>N;
    cout<<M*N<<endl;
}


Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
 
using namespace std;



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

    int a,b; cin >> a >> b;
    cout << max(0, a-2*b) << endl;

    //     int N; cin >> N;
    // for (int i = 0; i < N; i++) {
    //     cin >> arr[i];
    // }

    // for (int i = 0; i < N-1; i++) {
    //     for (int j = i+1; j < N; j++) {
            
    //     }
    // }
}



Measured memory_bytes: 256
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using ll=            long long;
using ld=            long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    cout<<(n-1)/(2*m+1)+1<<nl;
    return 0;
}


Measured memory_bytes: 3624
import numpy as np
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = []
for j in range(N):
    b = int(input())
    B.append(b)
A = np.array(A)
B = np.array(B)
boolean_matrix = np.isin(A, B)
if boolean_matrix.sum(axis=1).max() >= 3 or \
   boolean_matrix.sum(axis=0).max() >= 3 or \
   np.diag(boolean_matrix).sum() >= 3 or \
   np.diag(np.fliplr(boolean_matrix)).sum() >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27120
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N, Q;
vector<ll> to[200005];
ll num[200005];

void dfs(ll pa, ll cur, ll point) {
	num[cur] += point;
	for(ll next: to[cur]) {
		if(pa == next) continue;
		dfs(cur, next, num[cur]);
	}
}

int main(){
	cin >> N >> Q;

	rep(i, N - 1) {
		ll a, b;
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	rep(i, Q) {
		ll p, x;
		cin >> p >> x;
		p--;
		num[p] += x;
	}

	dfs(-1, 0, 0);

	rep(i, N) {
		cout << num[i];
		if(i != N - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}



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

int main(void) {
	_Bool flag[1000000] = {0};
	int n;
	long int total;
	int i,j;
	for (i = 2; i <= 3 || i <= sqrt(1000000); i++) {
		for (j = 2; i * j <= 1000000; j++) {
			flag[i*j-1] = 1;
		}
	}
	while (scanf("%d", &n)) {
		if (n == 0)
			break;
		total = 0;
		j = 1;
		for (i = 0; i < n; i++) {
			while (1) {
				j++;
				if (!flag[j-1]) {
					total += j;
					break;
				}
			}
		}
		printf("%ld\n", total);
	}
	return 0;
}

Measured memory_bytes: 1584
h = int(input())
h_s = bin(h)[2:]
h_s_len = len(h_s)

count_dict = {1: 1}
for i in range(2, h_s_len + 1):
    x = int(h_s[:i], 2)
    count_dict[x] = 1 + 2 * count_dict[x >> 1]

ans = count_dict[h]
print(ans)

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

int Si(vector<int> A,int idx_init, int idx_end){
    int sum = 0;
    rep2(i,idx_init,idx_end){
        sum += A.at(i);
    }
    return sum;
}

int main()
{
    int N;
    cin >> N;
    
    vector<int> Wi(N);
	for (auto& v : Wi){
		cin >> v;
	}

    int ans = 100 * N;
    rep(j,N){
        int Sidif;
        Sidif = abs(Si(Wi,0,j-1) - Si(Wi,j,N-1));
        ans = min(ans, Sidif);
    }

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


Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = map(int, input().split())
list_A = set(prime_factorize(a))
list_B = set(prime_factorize(b))
ans = list_A & list_B
print(len(ans) + 1)


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


LL mod = 1000000007;

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

  vector<int> a(n);
  REP (i, n) {
    cin >> a[i];
  }

  vector<int> b(n);
  REP (i, n) {
    cin >> b[i];
  }

  int x = 0;
  FOR (i, 1, n) {
    if (a[i] != a[i - 1]) x = i;
  }

  int y = n - 1;
  RFOR (i, 1, n) {
    if (b[i] != b[i - 1]) y = i - 1;
  }

  if (x > y || (x == 0 && y == n - 1 && a[0] != b[0])) {
    cout << 0 << endl;
    exit(0);
  }

  LL ans = 1;
  FOR (i, 1, n - 1) {
    if (a[i] == a[i - 1] && b[i + 1] == b[i]) {
      ans = ans * min(a[i], b[i]) % mod;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
function main(input) {
  	var length = input.length;
 // 	console.log(length);
  	var array = [];
//arrayに文字列を1文字ずつ追加する。
  	for(var i = 0;i<length;i++){
		var char = input.charAt(i);
      	array.push(char);
    }
//  	console.log(array);
  var c = array.filter(function (val, idx, arr) {
           return arr.indexOf(val) === idx && idx !== arr.lastIndexOf(val);
        });
	if(c.length == 2){
     	console.log('Yes'); 
    }else{
	    console.log('No'); 
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

ll a[100001] = {};
ll b[100001] = {};
ll c[100001] = {};
ll N;

ll upper_bs(ll b) {
	ll lb = -1;
	ll ub = N;
	ll m;
	while (ub - lb != 1) {
		m = (lb + ub) / 2;
		if (c[m] > b) {
			ub = m;
		}
		else {
			lb = m;
		}
	}
	return lb;
}
ll lower_bs(ll b) {
	ll lb = -1;
	ll ub = N;
	ll m;
	while (ub - lb != 1) {
		m = (lb + ub) / 2;
		if (a[m] >= b) {
			ub = m;
		}
		else {
			lb = m;
		}
	}
	return lb;
}

int main() {
	cin >> N;
	rep(i, 0, N)cin >> a[i];
	rep(i, 0, N)cin >> b[i];
	rep(i, 0, N)cin >> c[i];
	sort(a, a + N);
	sort(b, b + N);
	sort(c, c + N);

	ll cnt = 0;
	rep(i, 0, N) {
		ll A = lower_bs(b[i]) + 1;
		ll C = N - (upper_bs(b[i]) + 1);
		cnt += A * C;
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
  int A,B;
  cin>>A>>B;
  int x;
  if(A>B){
    x=2*A-1;
  }
  else if(A<B){
    x=2*B-1;
  }
  else{
    x=2*A;
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];
llong merge(int A[], int n, int left, int mid, int right) {
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	for (i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}
llong mergeSort(int A[], int n, int left, int right) {
	int mid;
	llong v1, v2, v3;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else {
		return 0;
	}
}
int main() {
	int A[MAX], n, i;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> A[i];
	}
	llong ans = mergeSort(A, n, 0, n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4648
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st s, t;
  ci(s, t);
  int N = sz(s), M = sz(t);
  ve<char> S(N), T(M);
  rep(i, N){
    S.at(i) = s.at(i);
  }
  rep(i, M){
    T.at(i) = t.at(i);
  }
  sort all(S);
  sort all(T);
  if(S.at(0) < T.at(M - 1)){
    co("Yes");
    rt;
  }
  else if(N < M){
    bool f = 1;
    rep(i, N){
      if(S.at(i) != T.at(i)){
        f = 0;
      }
    }
    if(f){
      co("Yes");
      rt;
    }
    else{
      co("No");
      rt;
    }
  }
  co("No");
}


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

int main() {
    int N; cin>> N;
    queue<pair<string, int>> table;
    table.push({"a", 1});
    if (N == 1) {
        cout << 'a' << endl;
    } else {
        for (int i = 1; i < N; i++) {
            while (true) {
                pair<string, int> t = table.front();
                if (t.first.length() == i) {
                    table.pop();
                    string s = t.first;
                    int count = t.second;
                    for (int j = 0; j < count+1; j++) {
                        table.push({s + (char)('a' + j), max(count, j+1)});
                    }
                } else {
                    break;
                }
            }
        }
        while (!table.empty()) {
        pair<string, int> t = table.front();
        table.pop();
        cout << t.first << endl;
        }
    }
}


Measured memory_bytes: 8832
def f(s)
    if s.even? then
        s/2
    else
        (3*s)+1
    end
end

c=1
ary = []
s = gets.to_i
1000000.times do |i|
    ary.push(s)
    s=f(s)
    c+=1
    if ary.include?(s) then
        break
    end
end

puts c

Measured memory_bytes: 1788
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1,n - 1):
    if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i+1] < p[i] and p[i] < p[i-1]):
        count += 1
print(count)


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

int money(int n){
	int sum = 0;
	int month = 0;
	int flag = 0;
	for(int i=0; i<12; ++i){
		int a,b;
		cin >> a >> b;
		sum += a-b;
		if(flag == 0){
			if(sum >= n){
				month = i+1;
				flag = 1;
			}
		}
	}
	return month;
}

int main(){
	int n;
	int result;
	while(cin >> n&& n){
		result = money(n);
		if(result == 0){
			cout << "NA" << endl;
		} else {
			cout << result << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iterator>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include<functional>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <numeric>
//#include<unordered_map>
#define inf  2e9
#define seed 131
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define lrtnb srand(unsigned(time(NULL)))
#define lrtlh ios::sync_with_stdio(0)
#define lowb(a,n,x) lower_bound(a,a+n,x) - a
#define uppb(a,n,x) upper_bound(a,a+n,x) - a
#define lson l,mid,i<<1;
#define rson mid+1,r,i<<1|1;
#define ALL(x) x.begin(),x.end()
#define inv inline void
#define INS(x) inserter(x,x.begin())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> Si;
typedef set<ll> Sl;
ll gcd(ll n, ll m) { long long r; if (n < m)swap(n, m); while (m) { r = n % m; n = m; m = r; }return n; }
ll lcm(ll b, ll y) { return b * y / gcd(b, y); }
double dis(double x1, double y1, double x2, double y2) { double ans = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return sqrt(ans); }
double random(double start, double en) { return start + (en - start)*rand() / (RAND_MAX + 1.0); }
void read(int &n) { char c = '+'; int x = 0; bool flag = 0; while (c<'0' || c>'9') { c = getchar(); if (c == '-')flag = 1; }while (c >= '0'&&c <= '9')x = x * 10 + c - 48, c = getchar(); n = flag == 1 ? -x : x; }
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int a5 = 0, a7 = 0;
	if (a == 5)
		a5++;
	if (b == 5)
		a5++;
	if (c == 5)
		a5++;
	if (a == 7)
		a7++;
	if (b == 7)
		a7++;
	if (c == 7)
		a7++;
	if (a5 == 2 && a7 == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

cost = [0,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 1)] #dp[i] i本のマッチを使って作れる最大の桁数
dp[0] = 0

for i in range(1, N + 1):
    for a in A:
        if i - cost[a] >= 0:
            dp[i] = max(dp[i], dp[i - cost[a]] + 1)

ans = ''

i = N
for k in range(dp[N]):
    for a in A:
        if i - cost[a] >= 0 and dp[i - cost[a]] != -1 and dp[i - cost[a]] == dp[i] - 1:
            ans += str(a)
            i -= cost[a]
            break

print(ans)

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

using namespace std;
 
int main() {
  long double a, b,  h, m, c, kakuc;

  cin >> a >> b >> h >> m;
  kakuc = (h + m/60.0 )/6.0 - m/30.0;

  while(kakuc > 2.0){kakuc -= 2.0;}
  c = sqrt( a*a + b*b - 2.0*a*b*cos(kakuc*M_PI) );
  cout << fixed << setprecision(15) << c;
}

Measured memory_bytes: 4148
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int insertion_sort(vector<int> *vec, int n, int g)
{
	auto cnt = 0;
	for (int i=g; i<n; i++) {
		int v = (*vec)[i];
		int j = i - g;
		while (j >= 0 && (*vec)[j] > v) {
			(*vec)[j+g] = (*vec)[j];
			j -= g;
			cnt++;
		}
		(*vec)[j+g] = v;
	}
	return cnt;
}

void shell_sort(vector<int> vec, int n)
{
	vector<int> g = {1};
	int cnt=0, m = 1, last;
	while ((last=pow(4, m) + 3 * pow(2, m-1) + 1) < n) {
		m++;
		g.push_back(last);
	}

	for (int i=m-1; i>=0; i--)
		cnt += insertion_sort(&vec, n, g[i]);
	
	cout << m << endl;
	for (int i=m-1; i>0; i--)
		cout << g[i] << " ";
	cout << g[0] << endl
	     << cnt << endl;
	for (int i=0; i<n; i++)
		cout << vec[i] << endl;
}

int main(void)
{
	int n;
	vector<int> vec;
	cin >> n;
	for (int i=0; i<n; i++) {
		int x;
		cin >> x;
		vec.push_back(x);
	}

	shell_sort(vec, n);

	return 0;
}

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

using namespace std;

const int N = 1e2 + 10;

int n, m, g[N][N], f[N][N][N][N];
int posx, posy;
char s[N][N];

int calc(int ax, int ay, int bx, int by) {
  if (bx < ax || by < ay) return 0;
  return g[bx][by] - g[bx][ay - 1] - g[ax - 1][by] + g[ax - 1][ay - 1];
}

void ckmax(int &a, int b) {
  if (a < b) {
    a = b;
  }
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'E') {
        posx = i;
        posy = j;
      } else if (s[i][j] == 'o') {
        g[i][j] = 1;
      }
      g[i][j] += g[i][j - 1] + g[i - 1][j] - g[i - 1][j - 1];
    }
  } 

#define nxtu (u + 1)
#define nxtd (d + 1)
#define nxtl (l + 1)
#define nxtr (r + 1)

  for (int u = 0; u <= posx - 1; u++) {
    for (int d = 0; d <= n - posx; d++) {
      for (int l = 0; l <= posy - 1; l++) {
        for (int r = 0; r <= m - posy; r++) {
          int cur = f[u][d][l][r];
          if (nxtu + d <= posx - 1) {
            ckmax(f[nxtu][d][l][r], cur + calc(posx - nxtu, max(posy - l, r + 1), posx - nxtu, min(posy + r, m - l)));
          } else if (nxtu <= posx - 1) {
            ckmax(f[nxtu][d][l][r], cur);
          }
          if (nxtd + u <= n - posx) {
            ckmax(f[u][nxtd][l][r], cur + calc(posx + nxtd, max(posy - l, r + 1), posx + nxtd, min(posy + r, m - l)));
          } else if (nxtd <= n - posx) {
            ckmax(f[u][nxtd][l][r], cur);
          }
          if (nxtl + r <= posy - 1) {
            ckmax(f[u][d][nxtl][r], cur + calc(max(posx - u, d + 1), posy - nxtl, min(posx + d, n - u), posy - nxtl));
          } else if (nxtl <= posy - 1) {
            ckmax(f[u][d][nxtl][r], cur);
          }
          if (nxtr + l <= m - posy) {
            ckmax(f[u][d][l][nxtr], cur + calc(max(posx - u, d + 1), posy + nxtr, min(posx + d, n - u), posy + nxtr));
          } else if (nxtr <= m - posy) {
            ckmax(f[u][d][l][nxtr], cur);
          }
        }
      }
    } 
  }
  printf("%d\n", f[posx - 1][n - posx][posy - 1][m - posy]);
  // for (int i = 1; i <= n; i++) {
  //   for (int j = 1; j <= m; j++) {
  //     printf("%d ", g[i][j]);
  //   }
  //   printf("\n");
  // }
  return 0;
}

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



int
main ()
{
string s;
cin>>s;
if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){
    cout<<"3"<<endl;
}
else if((s[0]=='R'&&s[1]=='R'&&s[2]=='S')||(s[0]=='S'&&s[1]=='R'&&s[2]=='R')){
    cout<<"2"<<endl;
}

else if((s[0]=='R'&&s[1]=='S'&&s[2]=='S')||(s[0]=='S'&&s[1]=='R'&&s[2]=='S')||(s[0]=='S'&&s[1]=='S'&&s[2]=='R')||(s[0]=='R'&&s[1]=='S'&&s[2]=='R')){
     cout<<"1"<<endl;
}
else {
    cout<<"0\n";
}
}







Measured memory_bytes: 3620
I = int(input())
L = list(map(int, input().split()))

print(2*I-1, flush=True)

m = 0
m_index = 0
for i, item in enumerate(L):
    if abs(item) > abs(m):
        m = item
        m_index = i

for i in range(I):
    print(m_index+1, i+1, flush=True)

if m >= 0:
    for i in range(0, I-1):
        print(i+1, i+2)
else:
    for i in range(I, 1, -1):
        print(i, i-1)


Measured memory_bytes: 9148
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int>a(3);
  rep(i,3)cin>>a[i];
  sort(all(a));
  if(a[0]==5&&a[1]==5&&a[2]==7){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
  return 0;

}


Measured memory_bytes: 256
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())

v1 = A1-B1
v2 = A2-B2

if v1==0:
    print("infinity")
elif v2==0:
    print(0)
elif v1>0 and v2>0:
    print(0)
elif v1<0 and v2<0:
    print(0)
else:
    cycle = v1*T1+v2*T2
    if cycle==0:
        print("infinity")
    elif v1 > 0 and cycle > 0:
        print(0)
    elif v1 < 0 and cycle < 0:
        print(0)
    else:
        n = -(v1*T1) // cycle
        if abs(v1*T1)%abs(cycle)!=0:
            print(2*n+1)
        else:
            print(2*n)

Measured memory_bytes: 3064
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  c7 = n//7
  c4 = n//4
  for i in range(c7,-1,-1):
    for j in range(c4,-1,-1):
      su_ = 7 * i + 4 * j
      if su_ == n:
        print('Yes')
        exit()
  print('No')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

    return 0;
    

}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	unordered_map<string ,int>u;
	string t;
	while(n--)
	{	
		cin>>t;
		u[t]++;
	}
	printf("%lu",u.size());
}

Measured memory_bytes: 17796
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	long long n,m,a,b;
	long long sum;
	while(scanf("%lld",&n)==1)
	{
		sum=1;
		for(int i=1;i<=n;i++)
		{
			sum=sum*i;
			a=pow(10,9)+7;
		    sum=sum%a;
		}
		printf("%lld\n",sum);
	}
	return 0;
}

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

ll mod = 1000000007;


int main() {
int a,b; cin >> a>>b;
if(a+b>=10) cout <<"error" <<endl;
else cout <<a+b <<endl;
}


Measured memory_bytes: 256
#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>;
#define chmax(x,y) x = max(x,y);

int main() {
    int n;
    cin >> n;
    vector<pair<ll,ll>> p(n);
    rep(i,n) {
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(), p.end());
    ll now = 0;
    rep(i,n) {
        now += p[i].second;
        if (now > p[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int i,j,n,three[1000000],four[1000000],four_2[1000000],c[1000000],c_2[1000000];

int main(){
  
  three[0] = 1;
  four[0] = 1;
  for( i = 1; i < 1000000; i++ )three[i] = i+1 + three[i-1];
  for( i = 1; i < 1000000; i++ )four[i] = three[i] + four[i-1];
  
  int k = 0;
  for( i = 0; i < 1000000; i++ ){
    if(four[i] %2 == 1 ){
      four_2[k] = four[i];
      k++;
    }
  }
  
  for( i = 0; i < 1000000; i++ ){
    c[i] = 2000000;
    c_2[i] = 2000000;
  }

  c[0] = 0;
  for( i = 0; i < 1000; i++ ){
    for( j = four[i]; j <= 1000000; j++ ){
      c[j] = min( c[j],c[j-four[i]] + 1 );
    }
  }

  c_2[0] = 0;
  for( i = 0; i < 1000; i++ ){
    for ( j = four_2[i]; j <= 1000000; j++ ){
      c_2[j] = min( c_2[j],c_2[j-four_2[i]] + 1 );
    }
  }
  
  while(1){
    int n; cin >> n;
    if(n==0)break;
   
    cout << c[n] << " " << c_2[n] << endl;
  }
  return 0;
}
  

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

int main()
{
    long long a[200005],n,i,cnt=0,k;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    k=a[1];
    for(i=1; i<=n; i++)
    {
        if(a[i]<=k)
        {
            k=a[i];
            cnt++;
        }

    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

LL N;
LL A[100000];
LL B[100000];

bool solve(){
    cin >> N;
    REP(i, N){
        cin >> A[i];
    }

    LL sum = 0;
    LL unit = N*(N+1LL)/2LL;
    REP(i, N)sum += A[i];

    if((sum % unit) != 0){
        return false;
    }

    LL loop = sum / unit;
    LL life = loop;

    REP(i, N){
        LL b = A[i] - A[(i+1)%N] + loop;
        if(b < 0)return false;
        if((b % N) != 0)return false;
        life -= b / N;
    }
    return life == 0;
}

int main(){
    cout << (solve() ? "YES" : "NO") << endl;
    return 0;
}


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

bool enough(const std::vector<int> &h, const int t, const int A, const int B) {
    int extra_attack = A - B;
    int extra_attacks = t;
    int initial_attack = B * t;
    for (int I = 0; I < h.size(); I++) {
        int remainder = h[I] - initial_attack;
        if (remainder > 0) {
            extra_attacks -= (remainder + extra_attack - 1) / extra_attack;
            if (extra_attacks < 0) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int N, A, B;
    std::cin >> N >> A >> B;
    std::vector<int> h(N);

    int max_value = 0;
    for (int I = 0; I < N; I++) {
        std::cin >> h[I];
        max_value = std::max(max_value, h[I]);
    }

    int low = 0, high = max_value / B + 1;

    while (high > low) {
        int mid = low + ((high - low) / 2);
        if (enough(h, mid, A, B)) {
            high = mid;
        } else {
            low = mid + 1;
        }
    }
    std::cout << high << std::endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n), b(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    int ans = 0;
    int now = 0;
    rep(i, 0, n){
        if(now + a[i] > x){
            int tmp = (now + a[i]) - x;
            ans += tmp;
            a[i] -= tmp;
        }
        now = a[i];
    }
    o(ans);
}

Measured memory_bytes: 1920
object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    var cnt = 0
      for {
        i <- 0 to a
        if 500*i <= x
        j <- 0 to b
        if 500*i + 100*j <= x
        k <- 0 to c
        if 500*i + 100*j + 50*k == x
      } {cnt += 1}
    cnt
  }

  println(ans)
}

Measured memory_bytes: 27332
// Problem : A - Lucky 7
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	string s;
    	cin>>s;
    	bool flag = 0;
    	for(int i=0;i<3;++i)
    	{
    		if(s[i]=='7')
    		flag = 1;
    	}
    	if(flag)
    	cout<<"Yes";
    	else
    	cout<<"No";
    	
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int ctoi(char c){
  return int(c) - int('0');
}

int main() {
  int A, B, N;
  cin >> N >> A >> B;
  int sum = 0;                                //条件を満たす数の和を格納する変数
 
  for(int i = 1; i <= N; i++){
    int count = 0;                                      //N以下の数の、各桁の数字の和を格納する変数   
    string S = to_string(i);                   //桁の値の利用は文字またはシフト演算が有効
    
    for(int j = 0; j < S.size(); j++)        
      count += ctoi(S.at(j));                       //桁はすべて1文字 ctoiで変換
    
    if(A <= count && count <= B)          //iが条件を満たすなら...
      sum += i;
  
  }

  cout << sum << endl;                            //計算量はO(N)なので問題nothing

}

Measured memory_bytes: 256
import math
K = int(input())
Sum = 0
for i in range(K):
  for j in range(i + 1):
    x = math.gcd(i + 1, j + 1)
    for k in range(j + 1):
      y = math.gcd(j + 1, k + 1)
      if (i == j) and (i == k):
        Sum = Sum + math.gcd(x, y)
      elif (i == j) or (i == k) or (j == k):
        Sum = Sum + 3 * math.gcd(x, y)
      else:
        Sum = Sum + 6 * math.gcd(x, y)
print(Sum)

Measured memory_bytes: 9200
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    if (N - K) <= 0:
        print(N * X)
    else:
        print(K * X + (N - K) * Y)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    string days[7]={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for (int i=0;i<7;i++){
        if (days[i]==s)
            cout<<7-i;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0): d(n, -1) {}
  int find(int x) {
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};

ll comb(ll n){
  return n * (n - 1) / 2;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  rep(i, m){
    int s, t;
    cin >> s >> t;
    --s; --t;
    a[i] = s;
    b[i] = t;
  }
  UnionFind uf(n);
  vector<ll> ans;
  ll cur = comb(n);
  for (int i = m - 1; i >= 0; --i) {
    ans.push_back(cur);
    if (uf.same(a[i], b[i])) {
      continue;
    }
    cur += comb(uf.size(a[i])) + comb(uf.size(b[i]));
    bool ok = uf.unite(a[i], b[i]);
    cur -= comb(uf.size(a[i]));
  }
  reverse(ans.begin(), ans.end());

  rep(i, m) cout << ans[i] << endl;

}

Measured memory_bytes: 4212
n = int(input())
h = list(map(int,input().split()))
ans = 0
if n == 1:
    print(0)
    exit()
now = 0
for i in range(n-2,-1,-1):
    if h[i] >= h[i+1]:
        now += 1
    else:
        ans = max(ans,now)
        now = 0
ans = max(ans,now)
print(ans)

Measured memory_bytes: 63856
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<ll,ll> pint;
int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(){
  ll n;cin>>n;
  ll ans =0;
  ll a=0;
  REP(i,1,n+1){
    REP(j,1,n+1){
      a=gcd(i,j);
      REP(k,1,n+1){
        ans+=gcd(a,k);
      }
    }
  }
  cout<<ans<<endl;
}

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

bool isRectangle(int a, int b, int c);
bool isLozenge(int a, int b);

int main()
{
    int a;
    int b;
    int c;
    int rect_num = 0;
    int loze_num = 0;
    string in_str;
    while(getline(cin, in_str))
    {
        sscanf(in_str.c_str(),"%d,%d,%d",&a,&b,&c);
        if(isRectangle(a, b, c))
        {
            rect_num++;
        }
        if(isLozenge(a, b))
        {
            loze_num++;
        }
    }
    cout << rect_num << endl;
    cout << loze_num << endl;
    return 0;
}

bool isRectangle(int a, int b, int c)
{
    if(a * a + b * b == c * c)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool isLozenge(int a, int b)
{
    if(a == b)
    {
        return true;
    }
    else
    {
        return false;
    }
}



Measured memory_bytes: 3112
#include<cstdio>
#include<string>
#include<map>
#include<iostream>
#define maxn 40
#define LL long long
using namespace std;
typedef pair<string,string> PSS;
int n;
LL ans;
string s;
map<PSS,LL> cnt;
void dfs0(string s1,string s2,int i)
{
	if(i==n)
	{
		cnt[PSS(s1,s2)]++;
		return;
	}
	dfs0(s1+s[i],s2,i+1);
	dfs0(s1,s2+s[i],i+1);
}
void dfs1(string s1,string s2,int i)
{
	if(i==n-1)
	{
		if(cnt.count(PSS(s1,s2))) ans+=cnt[PSS(s1,s2)];
		return;
	}
	dfs1(s1+s[i],s2,i-1);
	dfs1(s1,s2+s[i],i-1);
}
int main()
{
	scanf("%d",&n);
	cin>>s;
	string s1,s2;
	dfs0(s1,s2,0);
	dfs1(s1,s2,2*n-1);
	printf("%lld\n",ans);
}

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


int main(){

    string s;
    int x, y;
    cin >> s >> x >> y;
    vector<int> x_step;
    vector<int> y_step;
    bool odd_even = true;
    int pointer = 0;
    int temp_count = 0;
    while(pointer < s.length()){
        if(s[pointer] == 'T'){
            if(odd_even){
                x_step.push_back(temp_count);
                odd_even = !odd_even;
                temp_count = 0;
                pointer ++;
            }else{
                y_step.push_back(temp_count);
                odd_even = !odd_even;
                temp_count = 0;
                pointer ++;
            }
        }else{
            temp_count ++;
            pointer ++;
        }
    }

    if(odd_even){
        x_step.push_back(temp_count);
    }else{
        y_step.push_back(temp_count);
    }

    bool x_position[x_step.size() + 1][16000+1] = {};
    x_position[0][8000] = 1;
    x_position[1][8000 + x_step[0]] = 1;
    for(int i=2; i<x_step.size()+1; i++){
        for(int j=0; j<=16000; j++){
            
            x_position[i][j] = x_position[i-1][j+x_step[i-1]] | x_position[i-1][j-x_step[i-1]];
            
        }
    }


    if (!x_position[x_step.size()][x + 8000]){
        cout << "No" << endl;
        return 0;
    }

    bool y_position[y_step.size() + 1][16000+1] = {};
    y_position[0][8000] = 1;
    for(int i=1; i<y_step.size()+1; i++){
        for(int j=0; j<=16000; j++){
            
            
            y_position[i][j] = y_position[i-1][j+y_step[i-1]] | y_position[i-1][j-y_step[i-1]];
            
        }
    }

    if(!y_position[y_step.size()][y + 8000]){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 121600