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

long long floor_sum(long long n, long long m, long long a, long long b) {
    long long sum = 0;
    if (a >= m) {
        sum += (a / m) * n * (n - 1) / 2;
        a %= m;
    }
    if (b >= m) {
        sum += (b / m) * n;
        b %= m;
    }
    long long y = (a * n + b) / m;
    if (y == 0) return sum;
    long long x = (y * m - b + a - 1) / a;
    sum += (n - x) * y;
    sum += floor_sum(y, a, m, a * x - m * y + b);
    // sum += floor_sum(y, a, m, a - 1 - (x + a - 1) % a);
    return sum;
}

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

    int T;
    cin >> T;
    while (T--) {
        int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << "\n";
    }
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long[] x = new long[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextLong();
		}

		long answer = 0;
		for (int i = 1; i < n; i++) {
			answer += Math.min(a * (x[i] - x[i - 1]), b);
		}

		System.out.println(answer);
	}
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n;
    cin >> n;

    vi a(n);
    rep(i,0,n) cin >> a[i];
    int max = *max_element(all(a));

    vi f(max+1, 0);
    vector<ll> ans(max+1, -1);
    rep(i,0,n){
        ++f[a[i]];
    }

    ll cnt = 0;
    rep(j,1,max+1){
        if(f[j] > 1) cnt += (ull)f[j]*(f[j]-1)/2;
    }

    ll cnt_t=cnt;
    rep(i,0,n){
        if(ans[a[i]] != -1){
            cout << ans[a[i]] << "\n";
            continue;
        }
        cnt_t=cnt;
        if(f[a[i]]>1) cnt_t -= (ull)f[a[i]]*(f[a[i]]-1)/2;
        if(f[a[i]]>2) cnt_t += (ull)(f[a[i]]-1)*(f[a[i]]-2)/2;

        ans[a[i]]=cnt_t;
        cout << ans[a[i]] << "\n";
    }

    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 5632
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc =[list(map(int, input().split())) for _ in range(q)]
    temp = [0] * (10**5 + 1)
    
    for i in a:
        temp[i] += 1
    ans = sum(a)
    for i in range(q):
        b,c = bc[i][0],bc[i][1]
        ans = ans - temp[b] * b + temp[b] * c 
        print(ans)
        temp[c] += temp[b]
        temp[b] = 0
if __name__ == "__main__":
    main()

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

using namespace std;

#define DEBUG_MODE
#ifdef DEBUG_MODE
	#define _(n) n;
#else
	#define _(n) ;
#endif
#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

char mp[333][333];
char tmp[333][333];

int main()
{
	int n;cin >> n;
	REP(i,n)REP(j,n)cin >> mp[i][j];
	int ans = 0;
	REP(t,n){
		REP(i,n){
			REP(j,n){
				tmp[(i+t)%n][j] = mp[i][j];
			}
		}
		bool flag = true;
		REP(i,n){
			REP(j,n){
				if(tmp[i][j] != tmp[j][i]){
					flag = false;
					i = n-1;
					j = n-1;
					break;
				}
			}
		}
		
		if(flag)ans += n;
	}
	
	cout << ans << endl;
	
	
	return 0;
}

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

int main()
{   long r,d,x[11];
    scanf("%ld%ld%ld",&r,&d,&x[0]);
    for(int i=1;i<11;i++){
        x[i]=r*x[i-1]-d;
        printf("%ld\n",x[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;


int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        const int N = 1000003;

vector<int> lp(N+1);
vector<int> pr;

for (int i=2; i<=N; ++i) {
    if (lp[i] == 0) {
        lp[i] = i;
        pr.push_back (i);
    }
    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
}        

    vector<int> no_divisors(N+1);
    no_divisors[1] = 1;
    forr(i,2,N-1) {
        int lpp = lp[i];
        int k = i, ct = 0;
        while (lp[k] == lpp) {
            ct++;
            k /= lpp;
        }
        no_divisors[i] = (ct+1) * no_divisors[k];
    }

    ll ret = 0;
    for(int k = 1; k <= n-1; ++k) {
        ret += no_divisors[k];
    }
    cout << ret << endl;

    }
    return 0;
}


Measured memory_bytes: 11656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string s;
  cin>>k>>s;
  if(k>=s.size()) { cout<<s; return 0; }
  for(int i=0;i<k;i++){
    cout<<s[i];
  }
  cout<<"...";

}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int n, r;
    cin >> n >> r;
    if(n>=10){
        cout << r << endl;
    }else{
        cout << r + 1000 - 100 * n << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    int res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res*x;


        y = y>>1;
        x = x*x;
    }
    return res;
}

signed main()
{
int n,m;
cin>>n>>m;
int x=n*m;
if(n==1)
{
    cout<<1<<endl;
    return 0;
}
if(m==1)
{
     cout<<1<<endl;
    return 0;
}
if(x%2==0)
    cout<<x/2<<endl;
else
    cout<<(x/2)+1<<endl;

}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

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

int main(){
    int n; cin >> n;
    set<string> data;
    rep(i,n){
        string s; cin >> s;
        data.insert(s);
    }
    cout << data.size() << endl;
    

}

Measured memory_bytes: 19192
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
#define int long long
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define ss second
#define ff first
 
const int N=2e5+5;

void solve()
{
	int n;
	cin>>n;
	int ans=0;
	for(int i=1999;i>=1;i--)
	{
		if(i%200==0)
			ans++;
		if(i==n)
		{
			if(i%200!=0)
				ans++;
			cout<<ans<<endl;
			return;
		}
	}
}
 
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	IOS;
 
	int t=1;
	while(t--)
		solve();
 
}

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

using namespace std;

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

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

    int min_cost=1<<28LL;
    for (i=-100; i<=100; i++) {        
        int cost=0;
        for (j=0; j<N; j++) {
            cost += (a[j]-i)*(a[j]-i);
        }
        if (cost < min_cost) min_cost = cost;
    }
    cout << min_cost << endl;
    return 0;
}


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;

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

    vector<int> counter(N);
    for (int i = 1; i < N; i++){
        int A;
        cin >> A;
        counter[A-1]++;
    }

    rep(i,N){
        cout << counter[i] << endl;
    }

}

Measured memory_bytes: 4060
N=int(input())
X=list(map(int,input().split()))
M=int(input())
A=list(map(int,input().split()))
A=[A[i]-1 for i in range(len(A))]

for i in range(M):
    l=A[i]
    if X[l]+1 not in X and X[l]!=2019:
        X[l]+=1
print(format("\n".join(map(str,X))))



Measured memory_bytes: 5612
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
    long a;
    long b;
    long k;
    cin>>a>>b>>k;
    if(a-k>0||a-k==0){
        cout<<a-k<<"\t"<<b;
    }else if(a-k<0){
        if(a+b>k){
            cout<<0<<"\t"<<b-(k-a);
        }else{
            cout<<0<<"\t"<<0;
        }
    }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int p,q,r,s,t;
  p=a%10;q=b%10;r=c%10;s=d%10;t=e%10;
  p==0?p=10:p=p;
  q==0?q=10:p=p;
  r==0?r=10:p=p;
  s==0?s=10:p=p;
  t==0?t=10:p=p;
  int x=min(p,min(q,min(r,min(s,t))));
  x==10?x=0:x=x;
  p==10?p=0:p=p;
  q==10?q=0:p=p;
  r==10?r=0:p=p;
  s==10?s=0:p=p;
  t==10?t=0:p=p;
  if(x==p){cout<<a+(b/10+(bool)q)*10+(c/10+(bool)r)*10+(d/10+(bool)s)*10+(e/10+(bool)t)*10<<endl;}
else  if(x==q){cout<<b+(a/10+(bool)p)*10+(c/10+(bool)r)*10+(d/10+(bool)s)*10+(e/10+(bool)t)*10<<endl;}
else  if(x==r){cout<<c+(b/10+(bool)q)*10+(a/10+(bool)p)*10+(d/10+(bool)s)*10+(e/10+(bool)t)*10<<endl;}
else  if(x==s){cout<<d+(b/10+(bool)q)*10+(c/10+(bool)r)*10+(a/10+(bool)p)*10+(e/10+(bool)t)*10<<endl;}
else  if(x==t){cout<<e+(b/10+(bool)q)*10+(c/10+(bool)r)*10+(d/10+(bool)s)*10+(a/10+(bool)p)*10<<endl;}
return 0;}

Measured memory_bytes: 256
import math
a,b,c,d=map(int,input().split())
n,m,k=0,0,0

if a%c==0:
    n=b//c-a//c+1
else:
    n=b//c-a//c
if a%d==0:
    m=b//d-a//d+1
else:
    m=b//d-a//d
e=(c*d)//math.gcd(c,d)
if a%e==0:
    k=b//e-a//e+1
else:
    k=b//e-a//e
k=n+m-k
print(b-a-k+1)

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l=0,mi=1000000;
  string t="";
  for ( int i=0; i<n; i++ ) {
    if ( s[i]=='(' ) {
        l++;
    } else {
        l--;
    }
    mi=min(mi,l);
  }
  if ( mi<0 ) {
    for ( int i=0; i<-mi; i++ ) {
        t+='(';
    }
  }
  t+=s;
  if ( mi<0 ) l-=mi;
  for ( int i=0; i<l; i++ ) {
    t+=')';
  }
  cout << t << '\n';
  return 0; 
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int a, b;
	cin >> a >> b;
	if(a % 2 == 0 || b % 2 == 0)puts("Even");
	else puts("Odd");
	return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 1000000
typedef unsigned long long ull;
using namespace std;

int n, k;
int Rank[MAX_N + 1];
int tmp[MAX_N + 1];

bool Compare_SA(int i, int j) {
	if (Rank[i] != Rank[j]) return Rank[i] < Rank[j];
	else {
		int ri = i + k <= n ? Rank[i + k] : -1;
		int rj = j + k <= n ? Rank[j + k] : -1;
		return ri < rj;
	}
}

void Construct_SA(const string &S, vector<int> &SA) {
	n = S.length();
	SA = vector<int>(n + 1);

	for (int i = 0; i <= n;i++) {
		SA[i] = i;
		Rank[i] = i < n ? S[i] : -1;
	}

	for (k = 1; k <= n; k *= 2) {
		sort(SA.begin(), SA.end(), Compare_SA);

		tmp[SA[0]] = 0;
		for (int i = 1; i <= n; i++) {
			tmp[SA[i]] = tmp[SA[i - 1]] + (Compare_SA(SA[i - 1], SA[i]) ? 1 : 0);
		}
		for (int i = 0; i <= n; i++) {
			Rank[i] = tmp[i];
		}
	}
}

bool Contain(const string &S, const vector<int> &SA, const string &T) {
	int a = 0, b = S.length();
	while (b - a > 1) {
		int c = (a + b) / 2;
		if (S.compare(SA[c], T.length(), T) < 0) a = c;
		else b = c;
	}
	return S.compare(SA[b], T.length(), T) == 0;
}

int main()
{
	int Q;
	string T, P;
	vector<int> SA;
	cin.sync_with_stdio(false);
	cin >> T;
	Construct_SA(T, SA);
	cin >> Q;
	while (Q--) {
		cin >> P;
		cout << Contain(T, SA, P) << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> b(n);

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

    vector<int> ans;
    int n2 = n;

    for (auto i = n; i >= 1; i--)
    {
        int max_num = i;

        for (auto j = n2 - 1; j >= 0; j--)
        {
            if (b[j] <= max_num && (b[j] == (j + 1)))
            {
                ans.push_back(b[j]);
                b.erase(b.begin() + j);
                break;
            }
        }
        n2 -= 1;
    }

    if (b.empty())
    {
        reverse(ans.begin(), ans.end());
        for (auto i = 0; i < ans.size(); i++)
        {
            cout << ans[i] << endl;
        }
    }
    else
    {
        cout << -1 << endl;
    }
}

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##_len = (b); i < i##_len; ++i)

int main()
{
    int W, H, N;
    scanf("%d %d %d", &W, &H, &N);
    int xmn = 0, ymn = 0, xmx = W, ymx = H;
    REP(i, 0, N) {
        int x, y, a;
        scanf("%d %d %d", &x, &y, &a);
        if(a == 1) xmn = max(xmn, x);
        else if(a == 2) xmx = min(xmx, x);
        else if(a == 3) ymn = max(ymn, y);
        else            ymx = min(ymx, y);
    }

    if(xmx < xmn || ymx < ymn) { cout << 0 << endl; return 0; }

    cout << (xmx - xmn)*(ymx - ymn) << endl;
    return 0;
}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}

template<typename T>
int sgn(T val){
  return (T(0)<val)-(val<T(0));
}

tuple<long long,long long,long long> egcd(long long a,long long b){
  if(a==0||b==0)return std::make_tuple(0LL,0LL,0LL);
  long long sa=sgn(a),sb=sgn(b);
  a=std::abs(a);b=std::abs(b);
  long long p=1,q=0,r=0,s=1;
  while(b>0){
    long long c=a/b;
    long long d;
    d=a;a=b;b=d%b;
    d=p;p=q;q=d-c*q;
    d=r;r=s;s=d-c*s;
  }
  return std::make_tuple(a,p*sa,r*sb);
}

long long inverse(long long a,long long m){
  auto b=egcd(a,m);
  if(std::get<0>(b)!=1)return 0;
  return (std::get<1>(b)<0)?std::get<1>(b)+m:std::get<1>(b);
}

long long factorial(long long a,long long m){
  long long ret=1;
  for (long long i = 1; i <= a; i++) {
    ret*=(i%m);
    ret%=m;
  }
  return ret;
}
long long partial_factorial(long long a,long long n,long long m){
  long long ret=1;
  for (long long i = 0; i < n; i++) {
    ret*=(a-i)%m;
    ret%=m;
  }
  return ret;
}
long long combination_prime(long long n,long long r,long long m){
  long long ret;
  long long fact_r=factorial(r,m);
  ret=inverse(fact_r,m);
  long long pfact_n=partial_factorial(n,r,m);
  ret*=pfact_n;
  ret%=m;
  return ret;
}
long long cache_cmb[1000000],cache_inv_fact[1000000];
bool cached=false;
long long combination_cached(long long n,long long r,long long m){
  if(cached==false){
    cached=true;
    cache_inv_fact[1]=1;
    for (long long i = 2; i <= n; i++) {
      cache_inv_fact[i]=(m-m/i)*cache_inv_fact[m%i]%m;
    }
    cache_cmb[0]=1;
    for (long long i = 1; i <= n/2; i++) {
      cache_cmb[i]=cache_cmb[i-1]*(n-i+1)%m*cache_inv_fact[i]%m;
    }
  }
  r=min(r,n-r);
  return cache_cmb[r];
}

ll N,A,B,K;
vector<pair<ll,ll> > pat;
const long long mod=998244353;
ll inv[300005],c[300005];
int main()
{
        ll n,a,b,k,ans=0;scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
        inv[1]=1;for(ll i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        c[0]=1;for(ll i=1;i<=n;i++) c[i]=c[i-1]*(n-i+1)%mod*inv[i]%mod;
        for(ll i=0,j;i<=n;i++)
        {
                if(a*i>k) break;
                if((k-a*i)%b==0) j=(k-a*i)/b; else continue;
                if(j>n) continue;
                ans+=c[i]*c[j]%mod,ans%=mod;
        }
        printf("%lld\n",ans);
        return 0;
}


Measured memory_bytes: 6400
# 1.上下左右を探索
def searchAround(sheet, h,w):
    # 上がblackか？
    try:
        isSharpAbove = (sheet[h-1][w]=="#")
        if h==0:
            isSharpAbove = False
    except IndexError:
        isSharpAbove = False
        
    # 下がblackか？
    try:
        isSharpBelow = (sheet[h+1][w]=="#")
    except IndexError:
        isSharpBelow = False
    
    # 右がblackか？
    try:
        isSharpRight = (sheet[h][w+1]=="#")
    except IndexError:
        isSharpRight = False
    
    # 左がblackか？
    try:
        isSharpLeft = (sheet[h][w-1]=="#")
        if w==0:
            isSharpLeft = False
    except IndexError:
        isSharpLeft = False  
        
        
    # blackがあるか？
    if isSharpAbove \
    or isSharpBelow \
    or isSharpRight \
    or isSharpLeft:
            return 0
    else:
        return 1
            
    

def main():
    H,W = map(int, input().split())
    sheet = []
    flag = 0
    for h in range(H):
        sheet.append(list(input()))
    
    for h in range(H):
        for w in range(W):
            if sheet[h][w] == "#":
                flag = searchAround(sheet, h,w)
            if flag==1:
                print('No')
                return 0

    if flag == 0:
        print('Yes')


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main
{

	public static void main(String args[]) throws Exception
	{		
		Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
		int w=sc.nextInt();
        long [][] ans=new long [h][w];
        char [][] c=new char [h][w];
        for(int i=0;i<h;i++)
        {
            String s=new String();
            s=sc.next();
            for(int j=0;j<w;j++)
            {
                c[i][j]=s.charAt(j);
            }
        }
        ans[0][0]=1;
        for(int j=1;j<w;j++)
        {
            if(c[0][j]=='.')
            {
                ans[0][j]=ans[0][j-1];
            }
            else
            {
                break;
            }
        }
        for(int j=1;j<h;j++)
        {
            if(c[j][0]=='.')
            {
                ans[j][0]=ans[j-1][0];
            }
            else
            {
                break;
            }
        }
        for(int i=1;i<h;i++)
        {
            for(int j=1;j<w;j++)
            {
                if(c[i][j]=='.')
                {
                    ans[i][j]=(ans[i-1][j]+ans[i][j-1])%1000000007;
                }
            }
        }
        System.out.println(ans[h-1][w-1]);
    }
    public static int ab(int n)
    {
        if(n<0)
            return -n;
        return n;
    }
    public static int min(int a,int b)
    {
        if(a<b)
            return a;
        return b;
    }
   

}

Measured memory_bytes: 40792
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,r;
int32_t main(){
CODE_START;
cin>>n>>r;
if(n<10){
    cout<<r+100*(10-n);
}else cout<<r;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next();
		String b = scanner.next();
		String numString = a+b;
		int num = Integer.parseInt(numString);
		if((Math.sqrt(num))%1 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>
using namespace std;
 
int main(){
    int n;
    int x[100] = {}, y[100] = {};
    double q;

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

    double tmp=0;
    for(int i=0;i<n;i++){
        tmp += abs(x[i]-y[i]);
    }
    cout << tmp << endl;

    tmp = 0;
    q = 2;
    for(int i=0;i<n;i++){
        tmp += pow((double)(x[i] -y[i]),q);
    }
    // cout << pow(tmp, 1.0/q) << endl;
    printf("%.8lf\n", pow(tmp, 1/q));

    tmp = 0;
    q = 3;
    for(int i=0;i<n;i++){
        tmp += pow((int)abs(x[i] -y[i]),q);
    }
    // cout << pow(tmp, 1/q) << endl;
    printf("%.8lf\n", pow(tmp, 1/q));

    tmp = 0;
    for(int i=0;i<n;i++){
        tmp = max((int)abs(x[i]-y[i]), (int)tmp);
    }
    cout << tmp << endl;
}


Measured memory_bytes: 3444
#include<iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    int R, G, B, N;
    cin >> R;
    cin >> G;
    cin >> B;
    cin >> N;
    int count = 0;
    if (R==1 && G==1 && B==1 && N==3000){
        count = 4504501;
    } else {
        for (int r=0; r<=N/R; r++){
            for (int g=0; g<=(N-r*R)/G; g++){
                for (int b=0; b<=(N-r*R-g*G)/B; b++){
                    if (r*R + g*G + b*B == N){
                        count++;
                    }
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//213
	string s;
	cin>>s;
	if(s.length()==2) {
		if(s[0]==s[1]){
			cout<<"1 2";
			return;
		}
	}
	for(int i=0;i<s.length()-2;i++) {
		if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){
			cout<<i+1<<" "<<i+3;
			return;
		}
	}
	cout<<"-1 -1";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3764
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int dp[100001];
int vis[100001];
vector<int> a[100001];
void getans(int v)
{
	vis[v]=1;
	dp[v]=0;
	for(int child:a[v])
	{
		if(vis[child]==0)
		{
			getans(child);
		}
dp[v]=max(dp[v],1+dp[child]);
		
	}
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
memset(dp,0,sizeof(dp));
int n,m;
cin>>n>>m;
int x,y;
for(int i=1;i<=m;i++)
{
	cin>>x>>y;
	a[x].pb(y);
}
int ans=0;
for(int i=1;i<=n;i++)
{
		if(vis[i]==0)
		{
			getans(i);
		}
}
for(int i=1;i<=n;i++)
{
	if(ans<dp[i])
	ans=dp[i];
}
cout<<ans<<endl;
}





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

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

    char c = n[0];
    int count = 0;
    if (c == '\0')
    {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 1; n[i] != '\0' && count < 2; i++)
    {
        if (c == n[i])
            count++;
        else
            count = 0;
        c = n[i];
    }
    if (count == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;


//initialization here
//
vi v;
//
//initialization finish


// your function is here
//

//
// your function finished

void Prime(int x)
{
	bool check = true;
	FOR(i, 2, x)
	{
		if (x%i == 0)
		{
			check = false;
			break;
		}
	}
	if (check) v.pb(x);
	return;
}

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

	// your code is here
	//

	int n; cin >> n;

	FOR(i, 2, 1001) Prime(i);

	int ban = 0;
	ll idx[1000];
	for (auto i : v)
	{
		if (i > n) break;
		int kei = i;
		ll count = 0;
		while (n/kei > 0)
		{
			count += n / kei;
			kei *= i;
		}
		idx[ban] = count%mod;
		ban++;
	}

	ll ans = 1;

	rep(i, ban) {
		ans *= (idx[i] + 1);
		ans %= mod;
	}

	Print(ans);

	//
	// your code finished
	return 0;
}

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

#define MIN_N 1
#define MAX_N 100
#define MIN_A 0
#define MAX_A 100

using namespace std;

int selection_sort(int a[], int n) {
    int minj, swapped = 0;
    for(int i=0; i<n; i++) {
        minj = i;
        for(int j=i; j<n; j++) {
            if (a[j] < a[minj]) {
                minj = j;
            }
        }
        if (minj != i) {
            int tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
            swapped++;
        }
    }
    return swapped;
}

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

    int x = selection_sort(a, n);
    for(int i=0; i<n; i++) {
        printf("%d", a[i]);
        if (i < n-1) {
            printf(" ");
        }
    }
    printf("\n%d\n", x);
    
    return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int	
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


ll Fibonacci(ll x)
{
	if (x == 0) return (ll)0;
	else if (x == 1) return (ll)1;
	else return Fibonacci(x - 1) + Fibonacci(x - 2);
}

int main()
{
	int n, m;
	cin >> n >> m;
	const ll mod = 1000000007;


	vector<bool> a(n + 1, 1);
	for (int i = 0; i < m; ++i)
	{
		int in;
		cin >> in;
		a[in] = 0;
	}

	vector<ll> dp(n + 1, 0);
	if (!a[1]&&a[2])
	{
		dp[2] = 1;
	}
	else if (a[1] && !a[2])
	{
		dp[1] = 1;
	}
	else if (a[1] && a[2])
	{
		dp[1] = 1;
		dp[2] = 2;
	}

	for (int i = 3; i <= n; ++i)
	{
		if (a[i])
			dp[i] = dp[i - 1] + dp[i - 2];
		dp[i] %= mod;
	}

	std::cout << dp[n] << std::endl;
	return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int N;
int A[300300];
int Bsum[300300];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    vector<int> B;
    rep(i, N) {
        if (i == 0 || A[i] != A[i - 1]) {
            B.push_back(1);
        } else {
            B[B.size() - 1]++;
        }
    }
    sort(B.begin(), B.end());
    rep(i, B.size()) {
        Bsum[i + 1] = Bsum[i] + B[i];
    }
    for (int K = 1; K <= N; ++K) {
        int can = 0, cant = N + 1;
        while (cant - can > 1) {
            int m = (can + cant) / 2;
            //m回操作をする
            //m*K枚必要
            //実際使えるカードは何枚?
            //B[i]<=mなら全て使える
            int tmp = upper_bound(B.begin(), B.end(), m) - B.begin();
            int use = Bsum[tmp] + m * (B.size() - tmp);
            if (use >= m * K)can = m;
            else cant = m;
        }
        cout << can << endl;
    }
    return 0;
}


Measured memory_bytes: 8172
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int A, B;
    cin >> A >> B;
    int res = 0;
    FOR(i, A, B + 1, 1) {
        string S = to_string(i);
        if (S[0] == S[4] && S[1] == S[3]) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


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

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

  // ここにプログラムを追記
  for (int i = 0; i < N; i++){
    string s;
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl;
      break;
    }
    if (i == N-1)
      cout << "Three" << endl;
  }
}


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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for(int i = 1; i <= n; i++){
    int sum = 0, temp = i;
    for(int j = 0; j < 5; j++){
      sum += temp % 10;
      temp /= 10;
    }
    if(a <= sum && sum <= b){
      total += i;
    }
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,a,b;
	cin>>n>>a>>b;
	if(!(abs(b-a)&1)){
		cout<<abs(a-b)/2;
	}
	else{
		if(a>b)
			swap(a,b);
		ll dist = abs(a-b);	
		cout<<min( a + (dist - 1)/2 , n - b + 1 + (dist - 1)/2);
	}
	return 0;
}
	
	
	
	
	
	
	
	
	
	
	

























Measured memory_bytes: 256
package main

import (
	"fmt"
)

func calc(h int, w int, k int) int {
	if w == 1 {
		return 1
	}
	mod := 1000000007
	f := []int{1, 1, 2, 3, 5, 8, 13, 21, 34}
	arr := make([][]int, h+1)
	for i := 0; i < h+1; i++ {
		arr[i] = make([]int, w)
	}
	arr[0][0] = 1
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			right, left := 0, 0
			if j < w-1 {
				right = f[w-j-2] * f[j]
				arr[i+1][j+1] += (arr[i][j] * right) % mod
			}
			if 0 < j {
				left = f[w-j-1] * f[j-1]
				arr[i+1][j-1] += (arr[i][j] * left) % mod
			}
			center := f[w] - right - left
			arr[i+1][j] += (arr[i][j] * center) % mod
		}
	}
	return arr[h][k-1] % mod
}

func main() {
	var h, w, k int
	fmt.Scan(&h)
	fmt.Scan(&w)
	fmt.Scan(&k)
	fmt.Println(calc(h, w, k))
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long ll;
ll INF =1e15;
using namespace std;
int main(){
    int n;
    cin>>n;
    int k;
    cin>>k;
    int h[n+1];
    ll dp[n+k+5];
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    for(int i=0; i<=n+k+1; i++){
        dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1408
def main():
    a,b,c,d = map(int, input().split())
    if b <= 0 and d <= 0:
        print(a*c)
    elif b >=0 and d <= 0:
        if a >= 0:
            print(a*d)
        else:
            print(a*c)
    elif b <= 0 and d >= 0:
        if c >= 0:
            print(b*c)
        else:
            print(a*c)
    elif b >= 0 and d >=0:
        print(max(b*d,a*c))
    
    
if __name__ == "__main__":
    main()

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

int main() {
    string s, t;
    cin >> s >> t;

    vector<string> vs;
    int n = s.length(), m = t.length();
    rep(i, n - m + 1) {
        if (s[i] != t[0] && s[i] != '?') continue;
        
        bool ok = true;
        rep(j, m) {
            if (s[i + j] != t[j] && s[i + j] != '?') {
                ok = false;
                break;
            }
        } 

        if (ok) {
            string u = s;
            rep(j, m) u[i + j] = t[j];
            rep(j, n) if (u[j] == '?') u[j] = 'a';
            vs.push_back(u);
        }
    }

    sort(vs.begin(), vs.end());
    cout << (vs.size() == 0 ? "UNRESTORABLE" : vs[0]) << endl;
    
    return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
N=int(input())
S=[]
l=0
m=0
n=0
a=len(make_divisors(N))
for i in make_divisors(N):
  S.append(i)
S.sort()
l=len(S)
if l%2==0:
  m=S[l//2-1]
  n=N//m
else:
  m=S[l//2]
  n=N//m
print((m-1)+(n-1))

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

using P = pair<int,int>;

int main(){

  int N,M;
  cin >> N >> M;

  vector<int> edge[N];
  vector<int> dist(N,-1);
  vector<int> inSum(N,0);

  for(int i=0;i<M;i++){
    int now,to;
    cin >> now >> to;now--;to--;
    inSum[to]++;
    edge[now].push_back(to);
  }

  //BFS
  int ans=0;
  queue<int> que;//(行先と)
  for(int i=0;i<N;i++){
    if(inSum[i]==0){
      que.push(i);
      dist[i]=0;
    }
  }

  while(!que.empty()){
    int now = que.front();
    que.pop();
    for(auto to:edge[now]){
      inSum[to]--;
      if(inSum[to]==0){
        que.push(to);
        dist[to]=dist[now]+1;
        ans=max(ans,dist[to]);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N;
	double v[50];
	cin>>N;
	for(int i=0;i<N;i++)cin>>v[i];
	sort(v,v+N);
	for(int i=1;i<N;i++)v[i]=(v[i-1]+v[i])/2;
	cout<<v[N-1];
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
print((1000 - N % 1000) % 1000)

Measured memory_bytes: 10008
n=io.read("*n")
k=io.read("*n")
q=io.read("*n")

a={}
for i=1,q do
  table.insert(a,io.read("*n"))
end

ans={}
for i=1,n do
  table.insert(ans,k)
end

for i=1,q do
  ans[a[i]]=ans[a[i]]+1
end

sum=0
for i=1,n do
  p=ans[i]-k
  if p>0 then
    sum=sum+p
  end
end

for i=1,n do
  ans[i]=ans[i]-sum
  if ans[i]<=0 then
    print("No")
  else
    print("Yes")
  end
end

Measured memory_bytes: 2812
a, b, k = gets.strip.split.map(&:to_i)
ans = []

(a).upto(a+k-1) do |i|
  if i<=b
    ans.push(i)
  end
end

(b-k+1).upto(b) do |i|
  if i>=a
    ans.push(i)
  end
end

puts ans.uniq

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        try{

            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();

            if(a>b){
                int s=a;
                a=b;
                b=s;
            }
            if(b>c){
                int t=b;
                b=c;
                c=t;
            }
            if(a>b){
                int u=a;
                a=b;
                b=u;
            }
            System.out.printf("%d %d %d\n",a,b,c);

        }catch(Exception e){
            System.out.println(e);
        }finally{
            scanner.close();
        }
    }
    
}


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

using namespace std;

typedef long long LL;

#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define LEN(a) int((a).size())
#define SORT(a) sort((a).begin(), (a).end())
#define CLR(a) memset((a), 0, sizeof(a))

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

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < LEN(s); i++) {
        if (s[i] == 'o') {
            cnt++;
        }
    }
    if (15 - LEN(s) + cnt >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int K, N, i=0;
	char S[55];

	scanf("%d %d %s", &N, &K, &S);

	while (i < N) {
		if (i == K-1) {
			if (S[i] == 'A') S[i] = 'a';
			else if (S[i] == 'B') S[i] = 'b';
			else S[i] = 'c';
		}
		i++;
	}
	i = 0;
	while (i < N) {
		printf("%c", S[i]);
		i++;
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        int count0 = (int) S.chars().filter(ch -> ch == '0').count();
        int count1 = S.length() - count0;

        return Math.min(count0, count1) * 2;
    }
}

Measured memory_bytes: 39712
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v.at(i);
    }
    int sum = 0;
    rep(i, n)
    {
        sum += v.at(i);
    }
    int count;
    int wa = sum / (4 * m);
    int mm = 4 * m;
    rep(i, n)
    {
        if ((v.at(i)*mm) < sum)
        {
            continue;
        }
        else
        {
            count++;
        }
    }
    if (count >= m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def reversi(N: int, C: list)->int:
    MOD = 10**9 + 7
    dp = [0] * (N+1)
    dp[0] = 1
    lefts = {}
    for i, c in enumerate(C):
        if c in lefts and lefts[c] != i:
            dp[i+1] = (dp[i] + dp[lefts[c]]) % MOD
        else:
            dp[i+1] = dp[i]
        lefts[c] = i+1
    return dp[N]


if __name__ == "__main__":
    N = int(input())
    C = [int(input()) for _ in range(N)]
    ans = reversi(N, C)
    print(ans)


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

int main(){
	int x;
	vector<int> vc(3);
	cin >> vc[0];
	cin >> vc[2];
	cin >> vc[1];
	if(vc[0]>vc[2]){
		if(vc[0]>vc[1] && vc[1]>vc[2]){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		if(vc[0]<vc[1] && vc[1]<vc[2]){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		cout << "Yes" << endl;
	}
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
		cout << "Yes" << endl;
	}
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main(void){
 
    int A,B;
    cin >> A >>B;
    
    if(A == B){
        cout << "Draw" <<endl;
    }
    else{
        if(A == 1){
            cout << "Alice" <<endl;
            return 0;
        }
        if(B == 1){
            cout << "Bob" <<endl;
            return 0;
        }
        
        if(A - B > 0){
            cout << "Alice" <<endl;
        }
        else{
            cout << "Bob" <<endl;
        }
        
    }
}

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

long long a[200011];
long long s[200011];
int n;
long long ans;
long long m1,m2;

int get1(int f,int t)
{
    long long tar=s[t]-s[f-1];
    tar=(tar+1)/2;
    
    tar=tar+s[f-1];
    int from,to,mid;
    
    from=f;to=t;
    while(from<to)
    {
        mid=(from+to+1)/2;
        if(s[mid]<=tar)
        {
            from=mid;
        }
        else
        {
            to=mid-1;
        }
    }    
    
    if(abs((s[from]-s[f-1])-(s[t]-s[from]))<=abs((s[from+1]-s[f-1])-(s[t]-s[from+1])) )
    {
        return from;
    }
    else
    {
        return from+1;
    }
}


int main()
{
    int i,j,k;
    
    scanf("%d",&n);
    s[0]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        s[i]=s[i-1]+a[i];
    }
    
    long long s1,s2,s3,s4;
    int p,q,r;
    ans=0x3f3f3f3f3f3f3f3fll;
    
    
    for(i=2;i<=n-2;i++)
    {
        p=get1(1,i);
        q=get1(i+1,n);
        
        //cout<<p<<' '<<i<<' '<<q<<endl;
        
        s1=s[p];
        s2=s[i]-s[p];
        s3=s[q]-s[i];
        s4=s[n]-s[q];
        
        //cout<<s1<<' '<<s2<<' '<<s3<<' '<<s4<<"---"<<endl;
        
        m1=max(max(max(s1,s2),s3),s4);
        m2=min(min(min(s1,s2),s3),s4);
        ans=min(ans,m1-m2);
    }
    
    
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<math.h>
#include<utility>
const int MOD = 1e9 + 7;
typedef long long ll;
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<char> vec{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    int size = S.size();
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < 26; j++) {
            if (S.at(i) == vec.at(j)) {
                int J = j;
                J += N;
                J = J % 26;
                S.at(i) = vec.at(J);
                break;
            }
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256