akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>//   28 March 2020
using namespace std;
int main()
{
    int n;
    long ans=0;
    cin>>n;
    if(n){
    ans=(n/500)*1000;
    n%=500;
    ans+=(n/5)*5;
    }
    cout<<ans<<endl;


    return 0;
}




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

int main(void){
  int CD,Buyer;
  int cnt100,cnt500,cnt1000;
  int change;

  while(1){

    cnt100 = cnt500 = cnt1000 = 0;
    change = 0;

    cin >> CD >> Buyer;

    if( CD == 0 && Buyer == 0 ) break;

    change = Buyer - CD;

    while( change != 0 ){

    if( change >= 1000 ){

      change -= 1000;
      cnt1000++;

    }

    else if( change >= 500 && change < 1000 ){

      change -= 500;
      cnt500++;

    }

    else if( change >= 100 && change < 500 ){

      change -= 100;
      cnt100++;

    }

    }

    cout << cnt100 <<" "<< cnt500 <<" "<< cnt1000 << endl;

  }

  return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i] >> c[i];
  }

  int dp[n][3];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for(int i=1; i<n; i++){
    dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
    dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
    dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1]);
  }

  cout << max(max(dp[n-1][0],dp[n-1][1]), dp[n-1][2]);

  return 0;
}


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

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

    vector<long long> a(n);
    for (long long& x : a) cin >> x;

    vector<long long> ac(n + 1, 0);
    map<long long, long long> mp;
    mp[0]++;

    for (long long i = 0; i < n; i++) {
        ac[i + 1] = ac[i] + a[i];
        mp[ac[i + 1]]++;
    }

    long long ans = 0;
    for (long long i = 0; i < n + 1; i++) {
        ans += max(0LL, --mp[ac[i]]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15872
#include <stdio.h>

// I/O
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
//


// Solve
void dfs(int G[100][100], int n, int *d, int *f, int u) {
    static int t = 0;
    d[u] = ++t;
    for(int i = 0; i < n; ++i) {
        if(!G[u][i] || d[i]) continue;
        dfs(G, n, d, f, i);
    }
    f[u] = ++t;
}

int main(int argc, char **argv) {
    int n = get_uint();
    int G[100][100] = {};
    for(int i = 0; i < n; ++i) {
        int u = get_uint() - 1;
        int k = get_uint();
        for(int j = 0; j < k; ++j) G[u][get_uint() - 1] = 1;
    }
    int d[100], f[100] = {};
    for(int i = 0; i < n; ++i)
        if(!f[i]) dfs(G, n, d, f, i);
    for(int i = 0; i < n; ++i) {
        put_uint(i + 1), putchar_unlocked(' ');
        put_uint(d[i]), putchar_unlocked(' ');
        put_uint(f[i]), putchar_unlocked('\n');
    }
    return 0;
}



Measured memory_bytes: 2112
//

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

vector<pair<ll, ll>> prime_factorize(ll n) {
	vector<pair<ll, ll> > result;
	for (ll p=2; p*p<=n; p++) {
		if (n % p != 0) continue;
		ll num = 0;
		while (n % p == 0) {
			num++;
			n /= p;
		}
		result.push_back(make_pair(p, num));
    }
    if (n != 1) {
    	result.push_back(make_pair(n, 1));
    }
    return result;
}

vector<ll> prime_factorize_straight(ll n) {
	vector<ll> result;
	vector<pair<ll, ll>> pair_result = prime_factorize(n);
	for (auto pair : pair_result) {
		for (ll i=0; i<pair.second; i++) {
			result.push_back(pair.first);
		}
	}

	return result;
}

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

	vector<pair<ll, ll>> pair_result = prime_factorize(N);
	int ans = 0;

	for (auto pair : pair_result) {
		ll n = pair.first;
		ll k = pair.second;

		for (int i=1; i<=k; i++) {
				ans++;
				k -= i;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3560
N = int(input())
def divisor_all(n): # 約数全列挙
    import math as ma
    l = [1,n]
    for i in range(2,int(ma.sqrt(n))+1):
        if n % i == 0:
            l.append(i)
            l.append(n//i)
    l.sort()
    return l # list
ll = divisor_all(N)
ans = 0
for i in range(len(ll)):
    r = ll[i]
    m = N//r-1
    if r<m:
        ans += m

print(ans)

Measured memory_bytes: 39152
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

ll comb(ll, ll);
ll comb(int, int);
vector<ll> factMemo{ 1,1 }, factInvMemo{ 1, 1 }, invMemo{ 0, 1 };
int curMax{ 1 };
void initTable(int);

int n, nb, nr;

void init()
{
	cin >> n >> nb; nr = n - nb;
}


int main()
{
	init();

	REP1C(i, nb)
	{
		if (nr < (i - 1))
		{
			cout << 0 << endl;
			continue;
		}

		ll blue = comb(nb - 1, i - 1);

		ll red = comb((nr - (i - 1) + 1) + (i) - 1, (i));

		ll ans = blue * red % MOD;
		cout << ans << endl;

	}
}

void initTable(int n) {

	factMemo.resize(n + 1);
	factInvMemo.resize(n + 1);
	invMemo.resize(n + 1);

	for (; curMax < n;)
	{
		curMax++;
		factMemo[curMax] = factMemo[curMax - 1] * curMax % MOD;
		invMemo[curMax] = MOD - invMemo[MOD % curMax] * (MOD / curMax) % MOD;
		factInvMemo[curMax] = factInvMemo[curMax - 1] * invMemo[curMax] % MOD;
	}
}


// calculate mod of combination
ll comb(ll n, ll k) { return comb((int)n, (int)k); }
ll comb(int n, int k) {
	if (n < k || n < 0 || k < 0)
		return 0;

	if (curMax < n)
		initTable(n);

	return factMemo[n] * (factInvMemo[k] * factInvMemo[n - k] % MOD) % MOD;
}


Measured memory_bytes: 256
S=input()
K=int(input())
ls = [str for str in S]
if len(set(ls))==1:
  cnt=len(S)*K//2
  print(cnt)
  exit()

if not ls[0]==ls[-1]:
  i=0
  cnt=0
  while i<len(S)-1:
    if ls[i+1]==ls[i]:
      ls[i+1]="0"
      cnt+=1
      i+=1
    else:
      i+=1
    ans=cnt*K
else:
  j=0
  atama=0
  while j<len(S):
    if ls[j+1]==ls[j]:
      j+=1
      atama+=1
    else:
      break
  k=0
  oshiri=0
  while k<len(S):
    if ls[-k-2]==ls[-k-1]:
      k+=1
      oshiri+=1
    else:
      break
  es=ls[atama+1:]+ls[:atama+1]
  i=0
  cnt=0
  while i<len(S)-1:
    if es[i+1]==es[i]:
      es[i+1]="0"
      cnt+=1
      i+=1
    else:
      i+=1
  ans=cnt*K
  if (atama+1)*(oshiri+1)%2==1:
    ans-=1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const long long Max = 5e17;

long long x, y;

int main()
{
	int ans = 1;
	scanf("%lld %lld", &x, &y);
	if(x > Max){
		printf("1\n");
		return 0;
	}
	while(x <= y){
		x = x << 1;
		ans++;
	}
	ans--;
	printf("%d\n", ans);
}



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

int main(){
    int N;
    cin >> N;
    int t[N+10], x[N+10], y[N+10];
    t[0] = x[0] = y[0] = 0;
    for(int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];
    
    bool can = true;
    for(int i = 0; i < N; ++i){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(dt < dist){
            can = false;
            break;
        }
        if(dist % 2 != dt % 2){
            can = false;
            break;
        }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	bool f=false;
	cin>>n>>m;
	vector<pair<int,int>>v(max(n,m));
	vector<bool>a(200001),b(200001);
	for(int i=0;i<m;i++) {
		cin>>v.at(i).first>>v.at(i).second;
		if(v.at(i).second==n){
			b.at(v.at(i).first)=true;
			if(v.at(i).first==1) true;
		}
		if(v.at(i).first==1){
			a.at(v.at(i).second)=true;
		}
	}
	if(f){
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	for(int i=0;i<200000;i++) {
		if(a.at(i)==b.at(i) && a.at(i)==true){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int a, b, x;

  cin >> a >> b >> x;

  if(a <= x && a + b >= x){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
def ncr(n,r):
    if n==r: return 1
    if n<=0 or n<r:return 0
    r=min(r,n-r)
    a=1
    b=1
    for i in range(r):
        a*=n-i
        b*=r-i
    return a//b

n,k=map(int,input().split())
b=k
a=n-k
for i in range(1,k+1):
    print(int((ncr(a+1,i)*ncr(b-1,i-1))%1000000007))


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

int main(){
    int N, K;
    cin >> N >> K;
    int sunuke[N] ={0};
    for(int i =0; i < K; i++){
        int d;
        cin >> d;
        for(int j =0; j < d; j++){
            int a;
            cin >> a;
            sunuke[a-1] = 1;
        }
    }
    int ans = N;
    for(int i =0; i < N; i++){
        ans -= sunuke[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (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 i = 0;i < (n);i++)cerr << v[i] << ' ';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()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

map<string,int> mp;

int main()
{
	int n;cin >>n;
	string str,t;
	REP(i,n)t += (i+'0');
	mp[t] = 0;
	
	queue< pair<string,int> > q;
	q.push(MP(t,0));
	
	while(!q.empty())
	{
		pair<string,int> tmp = q.front();q.pop();
		for(int i = 0;i < tmp.FI.size()-1;i++)
		{
			for(int j = i+1;j < tmp.FI.size();j++)
			{
				string tt = tmp.FI;
				reverse(tt.begin()+i,tt.begin()+j+1);
				if(mp.find(tt) == mp.end())
				{
					mp[tt] = tmp.SE+1;
					if(tmp.SE+1 < 4)
					{
						q.push(MP(tt,tmp.SE+1));
					}
				}
			}
		}
	}
	
	REP(i,n)
	{
		int c;cin >> c;
		str += c+'0'-1;
	}
	
	if(mp.find(str) != mp.end())
	{
		cout << mp[str] << endl;
		return 0;
	}
		
	q.push(MP(str,0));
	
	
	while(!q.empty())
	{
		pair<string,int> tmp = q.front();q.pop();
		for(int i = 0;i < tmp.FI.size()-1;i++)
		{
			for(int j = i+1;j < tmp.FI.size();j++)
			{
				string tt = tmp.FI;
				reverse(tt.begin()+i,tt.begin()+j+1);
				if(mp.find(tt) != mp.end())
				{
					if(mp[tt] != -1)
					{
						cout << mp[tt] + tmp.SE + 1<< endl;
						return 0;
					}
				}
				else
				{
					mp[tt] = -1;
					if(tmp.SE+1 < 4)
						q.push(MP(tt,tmp.SE+1));
				}
			}
		}
	}
	
	cout << n-1 << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  ll a, b, k;
  cin >> a >> b >> k;

  ll ra = a - min(a, k);
  ll rb = max(0LL, b - (k - min(a, k)));

  // ll x = min(a, k);
  // a -= x;
  // k -= x;
  // b -= min(b, k);

  cout << ra << " " << rb << endl;
  return 0;
}


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

char s[5001], t[6], c[5];
int k, n, l[6], i, j, iM;
int main() {
  scanf("%s", s);
  scanf("%d", &k);
  n = strlen(s);
  for (c[0] = 'a'; c[0] <= 'z'; ++c[0]) {
    t[0] = c[0];
    l[1 + 0] = -1;
    for (i = l[0], iM = n - 0; i < iM; ++i) {
      if (s[i + 0] != t[0]) continue;
      l[1 + 0] = i;
      break;
    }
    if (l[1] < 0) continue;
    if (k == 1) {
      printf("%s\n", t);
      return 0;
    }
    --k;
    for (c[1] = 'a'; c[1] <= 'z'; ++c[1]) {
      t[1] = c[1];
      l[1 + 1] = -1;
      for (i = l[1], iM = n - 1; i < iM; ++i) {
        if (s[i + 0] != t[0] || s[i + 1] != t[1]) continue;
        l[1 + 1] = i;
        break;
      }
      if (l[2] < 0) continue;
      if (k == 1) {
        printf("%s\n", t);
        return 0;
      }
      --k;
      for (c[2] = 'a'; c[2] <= 'z'; ++c[2]) {
        t[2] = c[2];
        l[1 + 2] = -1;
        for (i = l[2], iM = n - 2; i < iM; ++i) {
          if (s[i + 0] != t[0] || s[i + 1] != t[1] || s[i + 2] != t[2]) continue;
          l[1 + 2] = i;
          break;
        }
        if (l[3] < 0) continue;
        if (k == 1) {
          printf("%s\n", t);
          return 0;
        }
        --k;
        for (c[3] = 'a'; c[3] <= 'z'; ++c[3]) {
          t[3] = c[3];
          l[1 + 3] = -1;
          for (i = l[3], iM = n - 3; i < iM; ++i) {
            if (s[i + 0] != t[0] || s[i + 1] != t[1] || s[i + 2] != t[2] || s[i + 3] != t[3]) continue;
            l[1 + 3] = i;
            break;
          }
          if (l[4] < 0) continue;
          if (k == 1) {
            printf("%s\n", t);
            return 0;
          }
          --k;
          for (c[4] = 'a'; c[4] <= 'z'; ++c[4]) {
            t[4] = c[4];
            l[1 + 4] = -1;
            for (i = l[4], iM = n - 4; i < iM; ++i) {
              if (s[i + 0] != t[0] || s[i + 1] != t[1] || s[i + 2] != t[2] || s[i + 3] != t[3] || s[i + 4] != t[4]) continue;
              l[1 + 4] = i;
              break;
            }
            if (l[5] < 0) continue;
            if (k == 1) {
              printf("%s\n", t);
              return 0;
            }
            --k;
          }
          t[4] = 0;
        }
        t[3] = 0;
      }
      t[2] = 0;
    }
    t[1] = 0;
  }
}


Measured memory_bytes: 1636
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void)
{
	int x,y,i,flg,sum,k;
	scanf("%d %d",&x,&y);
	flg=0;
	for(i=0;i<x+1;i++){
		k=x-i;
		if(i*2+4*k==y){
			flg=1;
			break;
		}
	}
	if(flg==1)	printf("Yes\n");
	else	printf("No\n");
	return 0;
}


Measured memory_bytes: 1600
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;

	public static void main(String[] args) {
		N = sc.nextInt();
		long[] A = new long[N];
		long sum = 0;
		long min = Long.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
			sum += A[i];
			min = Math.min(min, A[i]);
		}
		if (N % 2 == 1) {
			System.out.println(sum % 2 == 1 ? "First" : "Second");
		} else {
			if (min % 2 == 1) {
				System.out.println("First");
			} else {
				System.out.println(sum % 2 == 1 ? "First" : "Second");
			}
		}
	}
}



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

static const int MAX = 1000;
deque<int> ary[MAX];
deque<pp> que;

void check(int u){
    if(ary[u].size() == 0) return;
    int v = ary[u].front();
    if(ary[v].front() == u){
        que.push_back(u < v ? pp(u, v) : pp(v, u));
    }
}

int main(){
    int n, op;
    cin >> n;
    rep(i, n) rep(j, n-1){
        scanf("%d", &op);
        op--;
        ary[i].push_back(op);
    }
    rep(i, n){
        check(i);
    }
    int day = 0;
    while(!que.empty()){
        day++;
        sort(que.begin(), que.end());
        que.erase(unique(que.begin(), que.end()), que.end());
        deque<pp> prevQ;
        swap(que, prevQ);
        for(pp x : prevQ){
            int i = x.first, j = x.second;
            ary[i].pop_front();
            ary[j].pop_front();
            check(i);
            check(j);
        }
    }
    rep(i, n){
        if(!ary[i].empty()){
            day = -1;
            break;
        }
    }
    cout << day << "\n";
}
            

Measured memory_bytes: 4736
A, B, C, X, Y = map(int, input().split())


if A + B >= 2 * C:
    if X >= Y:
        cnt = min((C * 2 * Y) + A * (X - Y), (C * 2 * X))
    else:
        cnt = min((C * 2 * X) + B * (Y - X), (C * 2 * Y))
    
else:
    cnt = (A * X) + (B * Y)
    
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

constexpr long long int mod = 998244353LL;
struct Factorial {
	std::vector<long long int> factorial, inversed_factorial;
	Factorial(const int max) : factorial(max + 1, 1), inversed_factorial(max + 1, 1) {
		std::vector<long long int> inv(max + 1, 1);
		for (auto i = 2; i <= max; ++i) {
			factorial[i] = (factorial[i - 1] * i) % mod;
			inv[i] = (mod - mod / i) * inv[mod % i] % mod;
			inversed_factorial[i] = inv[i] * inversed_factorial[i - 1] % mod;
		}
	}
	long long int fact(const int n) const {
		return factorial[n];
	}
	long long int comb(const int n, const int r) const {
		return factorial[n] * inversed_factorial[r] % mod * inversed_factorial[n - r] % mod;
	}

};

int main() {
	int n, m; std::cin >> n >> m;
	Factorial factorial(n + 3 * m);
	auto all = factorial.comb(n - 1 + 3 * m, 3 * m);
	auto over = factorial.comb(n + m - 2, m - 1) * n % mod;
	long long int odd = 0;
	for (auto i = m + 1; i <= n && i <= 3 * m; ++i) {
		if ((3 * m - i) % 2 == 0) {
			odd += factorial.comb(n - 1 + (3 * m - i) / 2, (3 * m - i) / 2) * factorial.comb(n, i) % mod;
			odd %= mod;
		}
	}
	std::cout << (all - over - odd + 2 * mod) % mod << std::endl;
}


Measured memory_bytes: 58880
def digitsum(n,b):
    if n < b:
        return n
    else:
        return digitsum(n//b,b) + n%b 

n = int(input())
s = int(input())
inf = float('inf')
ans = inf

for i in range(2,int(n**(1/2))+2):
    if digitsum(n,i) == s:
        ans = i
        break
if n == s:
    ans = n+1
else:
    for i in range(1,int(n**(1/2))):
        if i*i-i >= n-s:
            break
        if (n-s) % i == 0:
            if s-i >= (n-s)//i +1 or i > s:
                continue
            ans = min(ans,((n-s)//i)+1)
            
if ans == inf:
    print(-1)
else:
    print(int(ans))
    

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

class Main{
    public static void main(String[] a){
		int[] d = new int[10];
		Scanner sc = new Scanner(System.in);
		for(byte i=0;i<10;i++){
			d[i] = Integer.parseInt(sc.nextLine());
		}
		Arrays.sort(d);
		System.out.println(d[9]+"\n"+d[8]+"\n"+d[7]);
    }
}

Measured memory_bytes: 26256
import java.util.Scanner;

class Main {
    public static class UnionFind {

        private int[] parent;

        public UnionFind(int n) {
            // 親の番号を格納する。
            // 自分自身が親だった場合は-(その集合のサイズ)を格納する。
            this.parent = new int[n];

            for (int i = 0; i < n; i++) {
                // 最初の時点では親は自分自身
                // 集合のサイズは１
                this.parent[i] = -1;
            }
        }

        // aがどのグループに属しているか調べる。
        public int root(int a) {
            if (this.parent[a] < 0) {
                return a;
            } else {
                // 再帰的に親をたどる。
                return this.parent[a] = this.root(this.parent[a]);
            }
        }

        // aの集合のサイズを返す
        public int size(int a) {
            return -this.parent[this.root(a)];
        }

        // aとbをつなぐ。
        // 大きい方(a)に小さい方(b)をつなぐ感じ。
        public boolean connect(int a, int b) {
            // 親同士をつなぐ。
            a = this.root(a);
            b = this.root(b);

            // すでにくっついている場合
            if (a == b) {
                return false;
            }

            if (this.size(a) < this.size(b)) {
                int r = a;
                a = b;
                b = r;
            }

            this.parent[a] += this.parent[b];
            this.parent[b] = a;

            return true;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] X = new int[M];
        int[] Y = new int[M];
        int[] Z = new int[M];
        for (int i = 0; i < M; i++) {
            X[i] = scanner.nextInt() - 1;
            Y[i] = scanner.nextInt() - 1;
            Z[i] = scanner.nextInt() - 1;
        }
        UnionFind find = new UnionFind(N);
        for (int i = 0; i < M; i++) {
            find.connect(X[i], Y[i]);
        }
        boolean[] ans = new boolean[N];
        for (int i = 0; i < N; i++) {
            ans[find.root(i)] = true;
        }
        int cnt = 0;
        for (boolean b : ans) {
            if (b) {
                cnt++;
            }
        }
        System.out.println(cnt);

    }
}


Measured memory_bytes: 92732
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vll A(N);

    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    ll ans = 0;
    rep(i, K) ans += A[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

S = input()
res1 = S[::2].count('1')+S[1::2].count('0')
res2 = S[1::2].count('1')+S[::2].count('0')
print(min(res1,res2))

Measured memory_bytes: 3188
def selectionSort(A, n):
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    print(*A)
    print(cnt)


n = int(input())
A = list(map(int, input().split()))
selectionSort(A, n)



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int dx = c - a;
  int dy = d - b;
  cout << c - dy << ' ' << d + dx << ' ' << a - dy << ' ' << b + dx << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>

int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld %ld", &n, &k);

    long h[100000];

    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &(h[i]));
    }
    std::sort(h, h+n);

    long min = 1000000000;
    for(i=k-1; i<n; i++) {
        long value = h[i]-h[i-(k-1)];
        if(min > value) {
            min = value;
        }
    }

    printf("%d\n", min);

    return 0;
}

Measured memory_bytes: 896
# coding: utf-8
h,w=map(int,input().split())
A=[]
for i in range(h):
    a=input()
    a='#'+a+'#'
    A.append(a)
s='#'*(w+2)
A.insert(0,s)
A.append(s)

for i in range(h+2):
    print(A[i])

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,y;
	cin>>n>>y;
	for (int i=0;i<=y/10000;i++)
	{
		for (int j=0;j<=y/5000;j++)
		{
			int k=n-i-j;
			if (k>=0 && i*10000+j*5000+k*1000==y)
			{
				cout<<i<<' '<<j<<' '<<k;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        for(;;){
            int H = scan.nextInt();
            int W = scan.nextInt();
            if(H != 0 && W != 0){
                for(int i = 1; i <= H; i++){
                    if(i % 2 != 0){
                        System.out.print("#");
                        for(int j = 1; j < W; j++){
                            if(j % 2 == 0){
                                System.out.print("#");
                            }else{
                                System.out.print(".");
                            }
                        }
                    }else{
                        System.out.print(".");
                        for(int j = 1; j < W; j++){
                            if(j % 2 != 0){
                                System.out.print("#");
                            }else{
                                System.out.print(".");
                            }
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }else{
                break;
            }
        }
    }
}

Measured memory_bytes: 34892
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const n = Number(stdin.split('\n')[0])

const s = stdin.split('\n')[1].split('')

const getSumListL = val => {
  let sum = 0
  let list = []
  for (let i = 0; i < s.length; i++) {
    if (s[i - 1] === val) sum++
    list.push(sum)
  }
  return list
}

const getSumListR = val => {
  let sum = 0
  let list = []
  const rvs = [...s].reverse()
  for (let i = 0; i < rvs.length; i++) {
    if (rvs[i - 1] === val) sum++
    list.push(sum)
  }
  return list.reverse()
}

const lw = getSumListL('W')
const re = getSumListR('E')

const res = _ => {
  let min = Infinity
  for (let i = 0; i < lw.length; i++) {
    const cost = lw[i] + re[i]
    min = min > cost ? cost : min
  }
  return min
}

console.log(res())


Measured memory_bytes: 31492
from numpy import*
M=10**9+7
m=lambda:map(int,input().split())
n,k=m()
a=matrix([list(m())for i in[0]*n],'O')
b=eye(n,n,0,'O')
while k:b=[b,b*a%M][k&1];a=a*a%M;k>>=1
print(sum(b)%M)

Measured memory_bytes: 12508
n = int(input())
lis = [0 for i in range(10 ** 5 + 2)]
li = list(map(int,input().split()))
for i in range(n):
  lis[li[i]-1] += 1
  lis[li[i]] += 1
  lis[li[i]+1] += 1
print(max(lis))

Measured memory_bytes: 14792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)
typedef vector<int> vec;
int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(){
  int k,ans=0; cin>>k;
  rep(a,k)rep(b,k)rep(c,k)ans+=gcd(gcd(a,b),c);
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, b[1000];
string str;

int main(){
	cin >> n;
	for(ll i = 1; i <= n-1; i++){
		cin >> b[i];
	}
	
	ll ans = 0;
	ans += b[1];
	for(ll i = 2; i <= n-1; i++){
		ans += min(b[i-1], b[i]);
	}
	ans += b[n-1];
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  n*=2;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll re=0;
  rep(i,n/2) re+=a[i*2];
  cout<<re<<endl;
  return 0;
}


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

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

  long long A[N] = {};
  long long S[N] = {};
  cin >> A[0];
  S[0] = A[0];
  //cout << S[0] << endl;
  for(int i=1;i<N;i++){
    cin >> A[i];
    S[i] = S[i-1] + A[i];
    //cout << S[i] << endl;
  }


  long long P[4] = {};
  int Q[4] = {0,1,2,N-1};

  //cout << Q[0] << " " << Q[1] << " " << Q[2] << " " << Q[3] <<endl;

  long long result = pow(10,15);

  for(int i=1;i<N-2;i++){ //中央の区切り
    Q[1] = i;

    long long tmp_left = abs( ( S[Q[1]] - S[Q[0]] ) - S[Q[0]] );
    for(int j=Q[0] + 1; j<i; j++){ //左の区間の区切り
      long long tmp = abs( ( S[Q[1]] - S[j] ) - S[j] );
      if(tmp < tmp_left){
        tmp_left = tmp;
        Q[0] = j;
      }else{ // 左の区間の差が開いたらやめる
        break;
      }
    }

    //cout << Q[0] << " " << Q[1] << " " << Q[2] << " " << Q[3] <<endl;

    long long tmp_right = abs( ( S[N-1] - S[Q[2]] ) - (S[Q[2]] - S[Q[1]]) );
    for(int j=Q[2] + 1; j < N-1; j++){ //右の区間の区切り
      long long tmp = abs( ( S[N-1] - S[j] ) - (S[j] - S[Q[1]]) );
      if(tmp < tmp_right){
        tmp_right = tmp;
        Q[2] = j;
      }else{ // 左の区間の差が開いたらやめる
        break;
      }
    }

    //cout << Q[0] << " " << Q[1] << " " << Q[2] << " " << Q[3] <<endl;

    P[0] = S[Q[0]];
    P[1] = S[Q[1]] - S[Q[0]];
    P[2] = S[Q[2]] - S[Q[1]];
    P[3] = S[Q[3]] - S[Q[2]];
    long long R[6] = {};
    int count = 0;
    for(int i=0;i<4;i++){
      for(int j=i+1;j<4;j++){
        R[count] = abs(P[i] - P[j]);
        count++;
      }
    }

    long long tmp_result = max(R[0],max(R[1],max(R[2],max(R[3],max(R[4],R[5])))));
    if(tmp_result < result) result = tmp_result;

    //cout << Q[0] << " " << Q[1] << " " << Q[2] << " " << Q[3] <<endl;
  }

  cout << result << endl;
  return 0;
}


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

int main(){

  int a,b,c;
  cin >> a >> b >>c;
  if(a+b>=c) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

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

  long long ans=0;

  for(int bit=(1<<s.size()-1);bit<(1<<(s.size()));++bit){

    long long a=0,c=1;

    for(int i=0;i<s.size();++i){

      if(bit&(1<<i)){
	string ss = s.substr(s.size()-1-i,c); 
	a+=stoll(ss);
	c=1;
      }else{
	c++;
      }

    }

    ans+=a;

  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

typedef struct tuple{int x,y;}T;
 
int xcmp(const void*p,const void*q){
	T *pp=(T*)p,*qq=(T*)q;
	if(pp->x<qq->x)return-1;
	if(pp->x>qq->x)return 1;
	if(pp->y<qq->y)return-1;
	if(pp->y>qq->y)return 1;
	return 0;
}


int ans=1e9;

int cnt1,cnt2;
T temp1[400010],temp2[400010];
void solve(){
	qsort(temp1,cnt1,sizeof(T),xcmp);
	qsort(temp2,cnt2,sizeof(T),xcmp);
	int l=0;
	rep(i,0,cnt1){
		while(l<cnt2&&xcmp(temp1+i,temp2+l)!=-1)l++;
		if(l<cnt2&&temp1[i].x==temp2[l].x)ans=min(ans,abs(temp1[i].y-temp2[l].y)*5);
	}
}

T data[4][200010];
int main(){
	int n;
	scanf("%d",&n);
	int cnt[4]={};
	rep(i,0,n){
		int x,y;
		char c;
		scanf("%d%d %c",&x,&y,&c);
		T*t;
		if(c=='U')t=data[0]+cnt[0]++;
		if(c=='D')t=data[1]+cnt[1]++;
		if(c=='R')t=data[2]+cnt[2]++;
		if(c=='L')t=data[3]+cnt[3]++;
		t->x=x;
		t->y=y;
	}

	//正面衝突UD
	cnt1=cnt[0];
	rep(i,0,cnt[0])temp1[i]=data[0][i];
	cnt2=cnt[1];
	rep(i,0,cnt[1])temp2[i]=data[1][i];
	solve();

	//正面衝突LR
	cnt1=cnt[2];
	rep(i,0,cnt[2]){
		temp1[i].x=data[2][i].y;
		temp1[i].y=data[2][i].x;
	}
	cnt2=cnt[3];
	rep(i,0,cnt[3]){
		temp2[i].x=data[3][i].y;
		temp2[i].y=data[3][i].x;
	}
	solve();

	//DL
	cnt1=cnt[1];
	rep(i,0,cnt[1]){
		temp1[i].x=data[1][i].x+data[1][i].y;
		temp1[i].y=data[1][i].x-data[1][i].y;
	}
	cnt2=cnt[3];
	rep(i,0,cnt[3]){
		temp2[i].x=data[3][i].x+data[3][i].y;
		temp2[i].y=data[3][i].x-data[3][i].y;
	}
	solve();

	//RU
	cnt1=cnt[2];
	rep(i,0,cnt[2]){
		temp1[i].x=data[2][i].x+data[2][i].y;
		temp1[i].y=data[2][i].x-data[2][i].y;
	}
	cnt2=cnt[0];
	rep(i,0,cnt[0]){
		temp2[i].x=data[0][i].x+data[0][i].y;
		temp2[i].y=data[0][i].x-data[0][i].y;
	}
	solve();
	
	//RD
	cnt1=cnt[2];
	rep(i,0,cnt[2]){
		temp1[i].x=data[2][i].x-data[2][i].y;
		temp1[i].y=data[2][i].x+data[2][i].y;
	}
	cnt2=cnt[1];
	rep(i,0,cnt[1]){
		temp2[i].x=data[1][i].x-data[1][i].y;
		temp2[i].y=data[1][i].x+data[1][i].y;
	}
	solve();
	//UL
	cnt1=cnt[0];
	rep(i,0,cnt[0]){
		temp1[i].x=data[0][i].x-data[0][i].y;
		temp1[i].y=data[0][i].x+data[0][i].y;
	}
	cnt2=cnt[3];
	rep(i,0,cnt[3]){
		temp2[i].x=data[3][i].x-data[3][i].y;
		temp2[i].y=data[3][i].x+data[3][i].y;
	}
	solve();
	
	if(ans==1e9)puts("SAFE");
	else printf("%d",ans);
}

Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
int main(void){

  int N, capacity, K;  cin >> N >> capacity >> K;
  vector<int> T(N);  for(int i = 0 ; i < N ; i++)  cin >> T[i];

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

  int ans = 1,  passenger = 1, bus_limit = T[0] + K;
  for(int i = 1 ; i < N ; i++){
    if(bus_limit < T[i] || capacity <= passenger){
      ans += 1;
      passenger = 1;
      bus_limit = T[i] + K;
    }else
      passenger += 1;
  }

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


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

#define ll long long int

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define trace3(x,y,z) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;
#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(),(v).end()

using namespace std;
///////////////////////////////////////////////////////

int q,h,s,d,n;

int main()
{
	fast_io;
	cin>>q>>h>>s>>d>>n;

	int two_litre = min(8*q, min(4*h, min(	2*s, d)));
	int one_litre = min(4*q, min(2*h,s));

	ll ans = 1LL*(n/2)*two_litre + 1LL*(n%2)*one_litre;


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


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<bits/stdc++.h>
#include<limits>

#define lp2(i,n) for(int i=0;i<n;i++)
#define lp3(i,a,b) for(int i=a;i<b;i++)

using namespace std;
int main(){
  int n;
  cin>>n;
  if(n<=999)cout<<"ABC"<<endl;
  else cout<<"ABD"<<endl;
  return 0;
  
}


Measured memory_bytes: 256
# 入力（数字として使うやつ）
a,b = gets.chomp.split.map(&:to_i)

# 文字を作る
c = a.to_s * b
d = b.to_s * a

# 普通の時のこたえ
s = [c,d]
n = s.sort

#もじが同じだった時の処理
if a != b
  puts n.min
else
  puts c
end

Measured memory_bytes: 1788
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 200005
#define MOD 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, m, a[maxN];
ll sum, f[maxN], d[maxN], b[maxN];

void update(int x, int y) {
    d[x] += 1; d[y+1] -= 1;
    b[y+1] -= y-x+1;
}

int main () {
    scanf("%d%d", &n, &m);
    fto(i, 1, n) scanf("%d", &a[i]), --a[i];

    fto(i, 1, n-1)
        sum += (a[i] < a[i+1]) ? (a[i+1]-a[i]) : (a[i+1]+m-a[i]);

//    debug(sum);

    fto(i, 1, n-1) {
        if (a[i] < a[i+1]) update(a[i]+2, a[i+1]);
        else update(a[i]+2, a[i+1]+m);
    }

//    fto(i, 0, 2*m-1) printf("%lld ", d[i]);
//    puts("");
//    fto(i, 0, 2*m-1) printf("%lld ", b[i]);
//    puts("");

    ll curD = 0, curF = 0;
    fto(i, 0, 2*m-1) {
        curD += d[i];
        curF += curD+b[i];
        f[i%m] += curF;
//        fto(i, 0, m-1) printf("%lld ", f[i]);
//        puts("");
    }
    fto(i, 0, m-1) f[i] = sum - f[i];

    printf("%lld", *min_element(f, f+m));

    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<int, int> P;
ll modnum = 1e9+7;

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

const int MAX = 1e5+5;

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % modnum;
        inv[i] = modnum - inv[modnum%i] * (modnum / i) % modnum;
        finv[i] = finv[i - 1] * inv[i] % modnum;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % modnum) % modnum;
}

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    // 二項係数テーブルを作成しておく
    COMinit();

    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, n) {
        if(i >= k-1) {
            ans += COM(i, k-1) * a[i];
            ans %= modnum;
        }
        if(n-i-1 >= k-1) {
            ans -= COM(n-i-1, k-1) * a[i];
            ans %= modnum;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
n = int(input())

if n == 1:
    print(0)
else:
    # 試し割り
    data = []
    t = n
    for i in range(2, int(n**0.5)+1):
        while t % i == 0:
            t //= i
            if i not in data:
                data.append(i)
    # √n より大きな素数があった場合
    if t > 1:
        data.append(t)
        t //= t

    # print(data)

    # 処理系
    ans = 0
    for j in range(len(data)):
        for k in range(1, 41):
            p_e = data[j] ** k
            if n % p_e == 0:
                n //= p_e
                ans += 1
            else:
                break

    print(ans)


Measured memory_bytes: 9372
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 1000001;
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n];
    ll ans = 0;
    map<int, int> d;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += d[i - a[i]];
        ++d[i + a[i]];
    }

    cout << ans;

}

Measured memory_bytes: 21424
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = new int[3];
            string[] vals = Console.ReadLine().Split(' ');

            for (int i = 0; i < 3; i++)
                x[i] = int.Parse(vals[i]);

            Array.Sort(x);

            Console.WriteLine(x[0] + x[1]);

        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  string a;
  cin>>a;
  ll b=a.size();
  if(a.at(b-1)=='s'){
    a+="e";
  }
  cout<<a<<"s"<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int A[200200];
int mp[200200];

int main(void)
{
    int N, K, cnt=0;
    cin >> N >> K;
    REP1(i, N) cin >> A[i];
    REP1(i, N) mp[i] = 0;
    REP1(i, N) mp[A[i]] ++;
    REP1(i, N) cnt += mp[i]!=0?1:0;
//    REP1(i, N) cout << i << " " << mp[i] << endl;
//    cout << cnt << endl;
    sort(mp+1,mp+N+1);
//    REP1(i, N) cout << i << " " << mp[i] << endl;
    int res = 0;
    for(int i = N - cnt + 1; i < N - K + 1; i++) res += mp[i];
    cout << res << endl;    
}


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

 
const int INF = (int) 1e9;

struct point {
	int x;
    int y;
	point() : x(0), y(0) {}
};
 
struct fenwick_tree {
	int n;
	unordered_map<int, int> F;
 
    fenwick_tree() : n(INF) {
        F.rehash((int) 200000 * 17);
    }
	void upd(int i, int x) {
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	} 
	int get(int i) {
		int res = 0;
		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);
		return res;
	}
};
 
 
bool cmp(point a, point b) {
    return make_pair(a.x, a.y) < make_pair(b.x, b.y); 
}
 
 
int main() {
#ifdef NICK
	freopen("input.txt", "r", stdin);
#else

#endif
    point start, finish;
    int n;
    cin >> start.x >> start.y;
    cin >> finish.x >> finish.y;
    cin >> n;
    point p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    if (start.x > finish.x)
        swap(start, finish);
    if (start.y > finish.y) {
        finish.y = 2 * start.y - finish.y;
        for (int i = 0; i < n; i++) {
            p[i].y = 2 * start.y - p[i].y;
        }
    }
    vector<point> a;
    for (int i = 0; i < n; i++) {
        if (start.x <= p[i].x && p[i].x <= finish.x && start.y <= p[i].y && p[i].y <= finish.y)
            a.emplace_back(p[i]);
    }
    fenwick_tree dp;
    sort(a.begin(), a.end(), cmp);
    for (int i = 0; i < (int)a.size(); ++i)
        dp.upd(a[i].y, dp.get(a[i].y) + 1);
    int cur = dp.get(INF);
    long double ans = 0;
    if (cur != min(finish.y - start.y, finish.x - start.x) + 1)
        ans = 100.0 * (finish.y + finish.x - start.y - start.x) - 20.0 * cur + 5 * M_PI * cur;
    else
        ans = 100.0 * (finish.y + finish.x - start.x - start.y) - 20.0 * cur + 5 * M_PI * (cur - 1) + 10 * M_PI;
    cout << fixed << setprecision(13) << ans << "\n";
	return 0;
}

Measured memory_bytes: 80880
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

// 特定の文字列を数える関数
size_t count(const string& str, const string& sub, const size_t ini = 0, const size_t fin = string::npos) {
	size_t pos = str.find(sub, ini);
	size_t cnt = 0;
	while (pos < fin) {
		cnt += 1;
		pos = str.find(sub, pos + sub.length());
	}
	return cnt;
}

int main() {

	string S;
	cin >> S;

	size_t num0 = count(S, "0");
	size_t num1 = count(S, "1");

	cout << 2 * min(num0, num1) << endl;

	return 0;
}



Measured memory_bytes: 512
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    x = str(i).zfill(3)
    a = s.find(x[0])
    b = s[a+1:].find(x[1])
    c = s[a+b+2:].find(x[2])
    if -1 not in (a,b,c):
        cnt += 1
print(cnt)

Measured memory_bytes: 9276