akhauriyash/Code-Regression huggingface dataset:
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 100005
#define mod 1000000007
#include <bits/stdc++.h>
using namespace std;

ll n, k, res, fact[maxn];
vector<ll> v;

ll modInverse(ll a, ll m){
  ll m0 = m;
  ll y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1){
    ll q, t;
    q = a / m;
    t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}

ll norm(ll x){
    if(x < 0) x += mod;
    return x;
}

ll mul(ll x, ll y){
    ll res = ((x%mod) * (y%mod)) % mod;
    return norm(res);
}

ll add(ll x, ll y){
    ll res = ((x%mod) + (y%mod)) % mod;
    return norm(res);
}

ll sub(ll x, ll y){
    ll res = ((x%mod) - (y%mod) + mod) % mod;
    return norm(res);
}

ll nCr(ll N, ll R){
    if(R > N) return 0;
    ll denom = mul(fact[R], fact[N-R]);
    ll res = mul(fact[N], modInverse(denom, mod));
    //cout << N << " "<< R << " " << res << endl;
    return res;
}

int main() {
    fact[0] = 1;
    for(int i=1;i<maxn;i++){
        fact[i] = mul(fact[i-1], i);
    }
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.rbegin(), v.rend());
    for(ll i=1;i<=n;i++){
        ll x = nCr(n-i, k-1);
        res = add(res, mul(x, v[i-1]));
    }
    //cout << res << endl;
    reverse(v.begin(), v.end());
    for(ll i=1;i<=n;i++){
        ll x = nCr(n-i, k-1);
        res = sub(res, mul(x, v[i-1]));
    }
    cout << res << endl;
    return 0;
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    set<int> s;
    for (int i = a; i < a + k && i <= b; i++) {
        s.insert(i);
    }
    for (int i = b; i > b - k && i >= a; i--) {
        s.insert(i);
    }
    for (const auto e : s) {
        cout << e << endl;
    }
}


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

std::vector<int> find_all(const std::string str, const std::string subStr) {
    std::vector<int> result;

    int subStrSize = subStr.size();
    int pos = str.find(subStr);

    while (pos != std::string::npos) {
        result.push_back(pos);
        pos = str.find(subStr, pos + subStrSize);
    }

    return result;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  std::vector<int> findVec = find_all(s, "ABC");
  int total = 0;
  for (auto i : findVec) total++;
  cout << total << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int nsinn(int x,int y) {
 if (x < y) {
    return 1;
  }
    int s = nsinn (x / y , y);
    return s + 1;

}

int main() {
  int N,K;
  cin >> N >> K;
  cout << nsinn (N, K) << endl;
  
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll knapscak(ll a[], ll b[], ll n, ll w ){
    ll t[n+2][w+2];
    for(ll i=0; i<=n; i++){
        for(ll j=0; j<=w; j++){
            if(i==0||j==0)
                t[i][j]=0;
            }
        }
        for(ll i=1; i<=n; i++){
            for(ll j=1; j<=w; j++){
                if(a[i-1]<=j){
                    t[i][j]=max(b[i-1]+t[i-1][j-a[i-1]], t[i-1][j]);
                }
                else
                t[i][j]=t[i-1][j];
            }
        }
        return t[n][w];
    }
int main(){
    ll n,w;
    cin>>n>>w;
  ll  a[n+1],b[n+1];
    for(ll i=0; i<n; i++){
        cin>>a[i]>>b[i];
    }
    ll k;
    k=knapscak(a,b,n,w);
    cout<<k<<endl;
    return 0;
    
}

Measured memory_bytes: 82496
import Control.Applicative
import Control.Monad
import Text.Printf

type Point = (Double, Double)

main :: IO ()
main = do
  n <- readLn
  ls <- replicateM n $ map read . words <$> getLine
  forM_ ls $ \[x1,y1,x2,y2,x3,y3] -> do
    let a = (x1,y1)
        b = (x2,y2)
        c = (x3,y3)
        sin2A = sinT2 a b c
        sin2B = sinT2 b c a
        sin2C = sinT2 c a b
        sinA = sinT a b c
        r = sqrt (distSq b c) / (2*sinA)
        (px, py) = (a`ptProd`sin2A `ptAdd` b`ptProd`sin2B `ptAdd` c`ptProd`sin2C) `ptProd` (recip (sin2A+sin2B+sin2C))
    printf "%.3f %.3f %.3f\n" px py r

distSq :: Point -> Point -> Double
distSq (x1,y1) (x2,y2) = (x2-x1)**2 + (y2-y1)**2

sinT :: Point -> Point -> Point -> Double
sinT p1 p2 p3 = sqrt (1-cosT**2)
  where
    e1 = distSq p2 p3
    e2 = distSq p3 p1
    e3 = distSq p1 p2
    cosT = (e2+e3-e1)/(2*sqrt e2*sqrt e3)

sinT2 :: Point -> Point -> Point -> Double
sinT2 p1 p2 p3 = 2*sqrt (1-cosT**2)*cosT
  where
    e1 = distSq p2 p3
    e2 = distSq p3 p1
    e3 = distSq p1 p2
    cosT = (e2+e3-e1)/(2*sqrt e2*sqrt e3)

infixl 6 `ptAdd`
ptAdd :: Point -> Point -> Point
ptAdd (x1,y1) (x2,y2) = (x1+x2, y1+y2)

infixl 7 `ptProd`
ptProd :: Point -> Double -> Point
ptProd (x,y) k = (k*x, k*y)

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


int main()
{
	double x1;
	double x2;
	double y1;
	double y2;
	
	cin >> x1 >> y1 >> x2>> y2;
	double d = sqrt((x1 - x2)*(x1 - x2) +(y1 - y2)*(y1 - y2));
	printf("%lf\n", d);


    return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll x;
  cin >> x;

  cout << 8 - (x - 400) / 200 << endl;

  return 0;
}


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

int main(){
  int n,i,j;
  string s;
  int ans=0;
  cin >> n;
  cin >> s;
  for(i=0;i<1000;++i){
    int c[3];
    int f=0;
    if(i<=9){
      c[0]=0;
      c[1]=0;
      c[2]=i;
    }else if(i>=10 && i<=99){
      c[0]=0;
      c[1]=i/10;
      c[2]=i%10;
    }else{
      c[0]=i/100;
      c[1]=(i/10)%10;
      c[2]=i%10;
    }
    for(j=0;j<n;++j){
      if(s[j]==('0'+c[f])){
        f++;
      }
      if(f==3) break;
    }
    if(f==3) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int n, k; cin >> n >> k;
	cout << (n - k + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a, b, c;
	while(~scanf(" %d %d %d", &a, &b, &c)){
		if(a == 5 && b == 5 && c ==7) printf("YES\n");
		else if(a == 5 && b == 7 && c == 5) printf("YES\n");
		else if(a == 7 && b == 5 && c == 5) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
// AtCoder ABC136: D - Gathering Children
// 2019.8.26 bal4u

#include <stdio.h>

//// 高速入力
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

char S[100005]; int w;
int  L[100005], R[100005];
int  ans[100005];

int main()
{
	int i, x;
	
	w = ins(S);
	for (i = 0; i < w; i++) {
		if (S[i] == 'R') x = i;
		else R[i] = x;
	}
	for (i = w-1; i >= 0; i--) {
		if (S[i] == 'L') x = i;
		else L[i] = x;
	}
	for (i = 0; i < w; i++) {
		if (S[i] == 'R') ans[L[i]-((L[i]-i) & 1)]++;
		else             ans[R[i]+((i-R[i]) & 1)]++;
	}
	out(ans[0]); for (i = 1; i < w; i++) pc(' '), out(ans[i]);
	pc('\n');
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

    int a, b;

    cin >> a >> b;

    if (b % a == 0) {
        cout << a + b << endl;
    }
    else {
        cout << b - a << endl;
    }
}


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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<ll> p(a), q(b), r(c);
  for (int i = 0; i < a; ++i)
    cin >> p[i];
  for (int i = 0; i < b; ++i)
    cin >> q[i];
  for (int i = 0; i < c; ++i)
    cin >> r[i];

  sort(p.rbegin(), p.rend());
  for (int i = 0; i < x; ++i)
    r.push_back(p[i]);
  sort(q.rbegin(), q.rend());
  for (int i = 0; i < y; ++i)
    r.push_back(q[i]);

  sort(r.rbegin(), r.rend());
  ll ans = 0;
  for (int i = 0; i < x + y; ++i)
    ans += r[i];
  cout << ans << endl;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
	int A[3][3];
	map<int,pii> mp;
	for( int i=0;i<3;i++)
		for( int j=0; j<3; j++ )
		{
			cin>>A[i][j];
			mp[A[i][j]] = pii(i,j);
		}
	int N;
	cin>>N;
	int b[10];
	int marks[3] = {0};	
	for( int i=0; i<N; i++ )
	{
		cin >> b[i];
		if( mp.count(b[i]) )
		{
			marks[mp[b[i]].first] |= 1<<mp[b[i]].second;
		}
	}
	if( marks[0] == 7 || marks[1]==7 || marks[2] == 7 )
		cout << "Yes" << endl;
	else if(marks[0]&4 && marks[1]&2 && marks[2]&1 )
		cout << "Yes" << endl;
	else if(marks[0]&1 && marks[1]&2 && marks[2]&4 )
		cout << "Yes" << endl;
	else if(marks[0]&4 && marks[1]&4 && marks[2]&4 )
		cout << "Yes" << endl;
	else if(marks[0]&2 && marks[1]&2 && marks[2]&2 )
		cout << "Yes" << endl;
	else if(marks[0]&1 && marks[1]&1 && marks[2]&1 )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
def counting_sort(inArr, outArr, k):
    cntArr = [0] * (k + 1)
    for i in range(len(inArr)):
        cntArr[inArr[i]] += 1

    cntArr[0] -= 1
    for i in range(1, k+1):
        cntArr[i] += cntArr[i - 1]

    for i in range(len(inArr) - 1, -1, -1):
        outArr[cntArr[inArr[i]]] = inArr[i]
        cntArr[inArr[i]] -= 1

n = int(input())
num_list = [int(s) for s in input().split()]

sorted_list = [0] * n
counting_sort(num_list, sorted_list, 10000)

print(*sorted_list)


Measured memory_bytes: 224144
#include <bits/stdc++.h>
using namespace std;
#define F first 
#define S second 
#define MAX 10000003
typedef long long ll; 
const int mod = 1000000007; 
  
ll prime[MAX]; 
unordered_map<ll, ll> max_map; 
  
// Function to return a^n 
ll power(ll a, ll n) 
{ 
    if (n == 0) 
        return 1; 
    ll p = power(a, n / 2) % mod; 
    p = (p * p) % mod; 
    if (n & 1) 
        p = (p * a) % mod; 
    return p; 
} 
  
// Function to find the smallest prime factors 
// of numbers upto MAX 
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (ll j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
  
// Function to return the LCM modulo M 
ll lcmModuloM(const ll* ar, ll n) 
{ 
  
    for (ll i = 0; i < n; i++) { 
        ll num = ar[i]; 
        unordered_map<ll, ll> temp; 
  
        // Temp stores mapping of prime factor to 
        // its power for the current element 
        while (num > 1) { 
  
            // Factor is the smallest prime factor of num 
            ll factor = prime[num]; 
  
            // Increase count of factor in temp 
            temp[factor]++; 
  
            // Reduce num by its prime factor 
            num /= factor; 
        } 
  
        for (auto it : temp) { 
  
            // Store the highest power of every prime 
            // found till now in a new map max_map 
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 
    } 
  
    ll ans = 1; 
  
    for (auto it : max_map) { 
  
        // LCM is product of primes to their highest powers modulo M 
        ans = (ans * power(it.F, it.S)) % mod; 
    } 
  
    return ans; 
} 
int main() {
     sieve();
	ll n,i,j,sum=0,count=0,m;
	cin>>n;
	ll a[n],b[n];
	for(i=0;i<n;i++)
	{
	   cin>>a[i];
	}
    if(n==1)
    {
        cout<<1; return 0;
    }
    long long k,ans,r;
    k=lcmModuloM(a,n);
 
    ans=0;
    for(i=0;i<n;i++)
    {
        ans=((ans%mod)+((k%mod)*(power(a[i],mod-2)))%mod)%mod;
    }
    cout<<ans;
	return 0;
}

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

int main()
{
	int n,m; cin>>n>>m;
	vector <int> G[n+1]; int indegree[n+1]={0}; int LP[n+1]={0};

	for (int i=0; i<m; i++)
	{
		int x,y; cin>>x>>y;
		G[x].push_back(y);
		indegree[y]++;
	}
	queue <int> q;
	for (int i=1; i<=n; i++)
	{
		LP[i] = INT_MIN;
		if (indegree[i]==0)
			q.push(i),LP[i]=0;
	}

	while(q.size()!=0)
	{
		int cur = q.front(); q.pop();
		for (int nxt : G[cur])
		{
			indegree[nxt]--;
			LP[nxt] = max(LP[nxt],1 + LP[cur]);
			if (indegree[nxt]==0)
				q.push(nxt);
		}
		
	}
	int ans = 0;
	for (int i=1; i<=n; i++)
		ans = max(ans,LP[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
   int n,a,x,y,t;
   ll s=0;
  
   map<int,int>c;
   cin>>n;
   fn(i,n){
     cin>>a;
     s+=a;
     c[a]++;
   }
   cin>>t;
   
   while(t--){
     cin>>x>>y;
     s+=(c[x]*(y-x));
     c[y]+=c[x];
     c[x]=0;
     cout<<s<<endl;
   }
   return 0;
}
    

Measured memory_bytes: 8068
def getlist():
	return list(map(int, input().split()))

N = int(input())
A = getlist()

L = []
for i in range(N):
	L.append([A[i], i + 1])
L = sorted(L)
ans = []
for i in range(N):
	ans.append(str(L[i][1]))

print(" ".join(ans))

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll a[MAX_N];

multiset<ll> mst;

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

  // mst.insert(INF);

  for (int i = 0; i < n; ++i) {
    auto ptr = mst.upper_bound(a[i] - 1);
    // auto ptr = mst.lower_bound(a[i]);

    if (mst.empty() || ptr == mst.begin()) {
      mst.insert(a[i]);
      continue;
    }

    auto prv = prev(ptr);
    mst.erase(prv);
    mst.insert(a[i]);
  }

  printf("%d\n", mst.size());

  return 0;
}


Measured memory_bytes: 5760
import java.util.Scanner;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a < b){
      if(b < c){
            System.out.printf("%d %d %d\n", a,b,c);
      }else if(a < c){
            System.out.printf("%d %d %d\n", a,c,b);
      }else{
            System.out.printf("%d %d %d\n", c,a,b);
      }
    }else{
      if(b > c){
            System.out.printf("%d %d %d\n", c,b,a);
      }else if(a < c){
            System.out.printf("%d %d %d\n", b,a,c);
      }else{
            System.out.printf("%d %d %d\n", b,c,a);
      }
    }
  }
}



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

int main() {
    int n;
    scanf("%d", &n);
    int a[1001];
    int nSum = 0;
    for(int i=1; i<=n; i++) {
        scanf("%d", &a[i]);
        if(i % 2 != 0 && a[i] % 2 != 0) {
            nSum++;
        }
    }
    printf("%d\n", nSum);
    return 0;
}

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

const long long INF = (1LL << 63) - 1;

using namespace std;

int main(){
	long long n, x, ans = INF;
	cin >> n >> x;
	vector<long long> a(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for(int i = 1; i <= n; i++){
		long long cost= 0;
		int p = n;
		cost += (n + i) * x;
		cost += 5 * a[p];
		p -= 2 * i;
		while(p > 0){
			cost += 2 * a[p];
			p -= i;
			if(cost <= 0){
				cost = INF;
				break;
			}
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

const int P = 1e9 + 7;

typedef long long ll;
typedef long double ld;
mt19937 rr(random_device{}());

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> x(n);
	for (int i = 0; i < n; ++i) 
		cin >> x[i];
	
	int m = 0;
	vector<int> p;
	vector<int> used(n);
	ll ans = 1;
	for (int i = 0; i < n; ++i) {
		++m;
		if (m > (x[i] + 1) / 2) {
			ans *= m;
			ans %= P;
			--m;
			used[i] = 1;
			p.push_back(i);
		}
	}

	for (int i = 1; i <= m; ++i) {
		ans *= i;
		ans %= P;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    R, G, B, n = LI()
    ans = 0
    for r in range(n // R + 1):
        for g in range((n - r * R) // G + 1):
            b = (n - r * R - g * G) // B
            if r * R + g * G + b * B == n:
                
                ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39920
from sys import stdin

def main():
    for l in stdin:
        m ,f, r = map(int, l.split(' '))

        if -1 == m == f == r:
            break

        print(judge(m, f, r))

def judge(m, f, r):
    if -1 == m or -1 == f:
        return 'F'

    if 80 <= m+f:
        return 'A'

    if 65 <= m+f < 80:
        return 'B'

    if 50 <= m+f < 65:
        return 'C'

    if 30 <= m+f < 50:
        return 'C' if 50 <= r else 'D'

    return 'F'

if __name__ == '__main__': main()

Measured memory_bytes: 7640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bitset<4>bs;
    bs.set();
    int c,d,i;
    scanf("%d %d",&c,&d);
    bs[c]=bs[d]=0;
    for(i=1;i<=3;i++)
    {
        if(bs[i]==1)
        {
            printf("%d\n",i);
            return 0;
        }
    }
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m = map(int, input().split())
xyz=[]
for i in range(m):
    tmp = list(map(int,input().split()))
    xyz.append(tmp)

link = [[] for _ in range(n)]
for tmp in xyz:
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)

from collections import deque
Q = deque()

from collections import defaultdict
visited = defaultdict(int)
num=0
for i in range(n):
    if visited[i] != 0:
        continue
    num+=1

    Q.append(i)
    visited[i] = num

    while Q:
        now=Q.popleft()
        for nxt in link[now]:
            if visited[nxt] != 0:
                continue
            Q.append(nxt)
            visited[nxt]=num

ans=set()
for v in visited.values():
    ans.add(v)
print(len(ans))

Measured memory_bytes: 84572
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var mod [2020]int
	var input string
	tmp := 0
	ans := 0
	c := 1
	fmt.Scanf("%s", &input)
	s := make([]int, len(input))

	for i := 0; i < len(input); i++ {
		s[i], _ = strconv.Atoi(string(input[i]))
	}

	mod[0]++

	for i := len(s) - 1; i >= 0; i-- {
		tmp += s[i] * c
		// fmt.Println(tmp)
		mod[tmp%2019]++
		c *= 10
		c %= 2019
	}

	for i := 0; i < 2019; i++ {
		// fmt.Print(mod[i])
		if mod[i] > 1 {
			ans += mod[i] * (mod[i] - 1) / 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4916
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long int a,b;
  cin>>a>>b;
  if(a>0){
    cout<<"Positive"<<endl;
  }else if(a<=0&&b>=0){
    cout<<"Zero"<<endl;
  }else{
    long long int diff=abs(b-a)+1;
    if(diff%2==0){
      cout<<"Positive"<<endl;
    }else{
      cout<<"Negative"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())

count=0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                count+=1

print(count)

Measured memory_bytes: 9192
#include<algorithm>
#include<vector>
#include<iostream>
int main(void){
    int n=0;
    std::cin>>n;
    std::vector<int> a(n);
    std::vector<int> ap(n);
    for(int i=0;i<n;i++){
        std::cin>>a[i];
    }
    ap=a;
    std::sort(ap.begin(),ap.end(),std::greater<int>());
    for(int i=0; i<n; i++){
        if(a[i]<ap[0]){
            std::cout<<ap[0]<<std::endl;
            
        }else{
            std::cout<<ap[1]<<std::endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3200
(r,c) = [int(i) for i in input().split()]

table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])

table.append([0 for _ in range(c + 1)])

for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
    print(' '.join([str(column) for column in row]))

Measured memory_bytes: 6728
#include<iostream>
#include<string>
//#include<cstdio>
using namespace std;
int main(){
    int K;
    int X;
    cin >> K;
    cin >> X;
    int i;
    for(i=0;i<2*K-1;i++){
        printf("%d ", X-K+1+i);
    }
    //cout << x  << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  string s;
  int n,a[30]={};
  ll ans=1;
  std::cin >> n >> s;
  rep(i,n){
    a[s[i]-'a']++;
  }

  rep(i,26){
    int m=a[i]+1;
    ans*=m;
    ans%=MOD;
  }
  std::cout << ans-1 << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

struct Sweets{
	Sweets(){id = protein = lipid = carbo = 0;}
	Sweets(int arg_id,int arg_protein,int arg_lipid,int arg_carbo){
		id = arg_id;
		protein = arg_protein;
		lipid = arg_lipid;
		carbo = arg_carbo;
	}

	int id,protein,lipid,carbo;
};

int main(){

	int n,P,Q,R,C,count;
	Sweets sweets[1000];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < n; i++){
			scanf("%d %d %d %d",&sweets[i].id,&sweets[i].protein,&sweets[i].lipid,&sweets[i].carbo);
		}
		scanf("%d %d %d %d",&P,&Q,&R,&C);

		count = 0;

		for(int i = 0; i < n; i++){
			if(sweets[i].protein <= P && sweets[i].lipid <= Q && sweets[i].carbo <= R &&
					4*(sweets[i].protein+sweets[i].carbo)+9*sweets[i].lipid <= C){
				printf("%d\n",sweets[i].id);
				count++;
			}
		}
		if(count == 0)printf("NA\n");

	}
    return 0;
}



Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
#define int long long
signed  main() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    if (i+2 < n) {
      if (ar[i] < 0 && ar[i+1] > 0 && ar[i] < 0) {
        ar[i] = -ar[i];
        ar[i+2] = -ar[i+2];
      } else if (ar[i] < 0 && ar[i+1] < 0) {
        ar[i] = -ar[i];
        ar[i+1] = -ar[i+1];
      }
    }
  } 
  int cnt = 0;
  int sum = 0, buang = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (ar[i] < 0) {
      cnt++;
    }
    sum += abs(ar[i]);
  }
  if (cnt%2) {
    for (int i = 0; i < n; i++) {
      buang = min(buang ,abs(ar[i]));
    }
    sum -= 2*buang;
  }
  cout << sum << el;
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int X[110];

int f(int p){
    int sum = 0;

    for(int i=0;i<N;++i){
        int d = X[i] - p;
        sum += d * d;
    }

    return sum;
}

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> X[i];
  }

  int mn = 1001001001;

  for(int p=1;p<=100;++p){
      mn = std::min(mn, f(p));
  }

  std::cout << mn << std::endl;
}


Measured memory_bytes: 256
import heapq
n = int(input())
a = list(map(int, input().split()))

inf = 10**9 + 1
a.sort()
first = a.pop()
heap = [[-first, first, inf]]
ans = 0
while a:
    x, left, right = heapq.heappop(heap)
    ans += x
    t = a.pop()
    heapq.heappush(heap, [-min(t, left), left, t])
    heapq.heappush(heap, [-min(t, right), t, right])

print(-ans)

Measured memory_bytes: 44440
from sys import stdin
import sys
import math
import random
from decimal import Decimal
 
 
X, N = [int(x) for x in stdin.readline().rstrip().split()]
 
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))
 
ans = 10**9
ans1 = [X, 10**9]
for i in range(-100, 105):
    if i not in p:
        if ans > abs(X-i):
            ans = abs(X-i)
            # print(i, abs(X-i))
            if ans1[1] == abs(X-i):
                pass
            else:
                ans1[1] = abs(X-i)
                ans1[0] = i
            # ans1[1] = abs(X-i)
            # if ans1 > i:
            #     ans1 = i
                # print(i)
print(ans1[0])

Measured memory_bytes: 10196
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

ll n;
int x, m;
vector<int> ps;
int l, r;
int lgl[1 << 17];

int main() {
	cin >> n >> x >> m;
	memset(lgl, -1, sizeof(lgl));
	int now = x; ps.pub(x);
	while(1) {
		now = 1ll * now * now % m;
		if(~lgl[now]) {
			l = lgl[now];
			r = SZ(ps);
			break;
		}
		lgl[now] = SZ(ps);
		ps.pub(now);
	}
	if(n < r) {
		ll ans = 0;
		loop(i, n) ans += ps[i];
		cout << ans << endl;
		return 0;
	}
	ll lh = 0, rh = 0;
	loop(i, l) lh += ps[i];
	loop(i, r) rh += ps[i];
	rh -= lh;
	ll ans = lh + rh * ((n - l) / (r - l));
	int rm = (n - l) % (r - l);
	loop(i, rm) ans += ps[i + l];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4256
var s:string;
    i,len,x,y,ans:longint;
begin
    readln(s);
    len:=length(s);
    for i:=1 to len do
    begin
        if (x>=y+1) then 
        begin
            inc(y); 
            if (s[i]='g') then inc(ans); 
        end
        else begin inc(x); if (s[i]='p') then dec(ans); end;
    end;
    writeln(ans);
end.

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

lli n, m;

lli solver1(lli n, lli m){
	if(n == 1 && m == 1) return 1;
	if(n == 1) return m-2;
	if(m == 1) return n-2;
	return (n-2)*(m-2);
}
// lli solver2(lli n, lli m){
// 	vector<vector<lli>> a(n+2, vector<lli>(m+2));
// 	for(int i = 1; i <= n; i++){
// 		for(int j = 1; j <= m; j++){
// 			for(int s = -1; s <= 1; s++){
// 				for(int t = -1; t <= 1; t++){
// 					a[i+s][j+t]++;
// 				}
// 			}
// 		}
// 	}
// 	lli ans = 0;
// 	for(int i = 1; i <= n; i++){
// 		for(int j = 1; j <= m; j++){
// 			if(a[i][j]%2 == 1) ans++;
// 		}
// 	}
// 	return ans;
// }

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


Measured memory_bytes: 3560
def gcd(x, y):
  n = min(x, y)
  for i in range(n, 0, -1):
    if x % i == 0 and y % i == 0:
      return i

def lcm(x, y):
  return (x * y) // gcd(x,y)


N, M = list(map(int, input().split()))
S = list(input())
T = list(input())

L = lcm(N, M)

x = L // N
y = L // M
for i in range(N):
  if (i * x) % y == 0:
    if S[i] != T[(i * x) // y]:
      L = -1
      break

print(L)


Measured memory_bytes: 4496
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
using namespace std;

int f(int n) {
    if (n % 2 == 0)return n / 2;
    else return 3 * n + 1;
}

int main() {
    int s,ans;
    cin >> s;
    vector<int>a;

    a.push_back(s);
    for (int i = 1;; i++) {
        a.push_back(f(a[i - 1]));
        if (i > 2) {
            if (a[i] == a[i - 3]) {
                ans = i+1;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cstdint>

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;

using namespace std;

vector<int> create_primes(){
  char is_prime[1001] = {0};
  for(int i = 2; i < 1001; i++){
    is_prime[i] = 1;
  }
  for(int i = 2; i < 1001; i++){
    if (is_prime[i]){
      for (int j = 2; j * i < 1001; j++){
        is_prime[i*j] = 0;
      }
    }
  }
  vector<int> primes;
  for(int i = 2; i < 1001; i++){
    if(is_prime[i]){
      primes.push_back(i);
    }
  }
  return primes;
}
vector<int> primes = create_primes();
vector<int> factorize(int a){
 vector<int> f;
 for(auto p: primes){
   //cout<<p<<endl;
  if (a % p == 0){
    f.push_back(p);
    while( a % p == 0) a /= p;
  }
  if(p*p > a){
    if(a>1) f.push_back(a);
    //cout << a <<'a'<<endl;
    break;
  }
 }
 return f;
}

int main()
{
  int n;
  cin >> n;
  vector<int> A(n);
  for(int i = 0 ; i< n; i++){
    cin >> A[i];
  }
  bool pw = true;
  set<int> common;
  set<int> all;
  bool first = true;
  for(auto a: A){
    auto f = factorize(a);
    auto fs = set(f.begin(), f.end());
    int pre_size = all.size();
    vector<int> tmp;
    set_intersection(
      common.begin(), common.end(),
      fs.begin(), fs.end(), 
      std::back_inserter(tmp));
    common = set(tmp.begin(), tmp.end());
    all.insert(f.begin(), f.end());
    if(!first && all.size() < pre_size + f.size()){
      pw = false;
    }
    if (first){
      common = set(f.begin(), f.end());
    }
    first=false;
    /*cout << a<<':';
    for(auto c:f) cout <<c << ',';
    cout<<':';
    for(auto c:common) cout <<c << ',';
    cout<<':';
    for(auto c:all) cout <<c << ',';
    cout<<endl;*/
  }
  if (pw){
    cout << "pairwise coprime";
  }else if(common.size()==0){
    cout << "setwise coprime";
  }else{
    cout << "not coprime";
  }
}


Measured memory_bytes: 10856
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;




int main(){FIN
    
    ll x,n;cin>>x>>n;
    vll p(n); REP(i,n) cin>>p[i];
    VSORT(p);
    ll mn=x; ll mx=x;
    while(1){
        if (!count(ALL(p), mn)){
            cout<<mn<<endl;
            return 0;
        }
        else if (!count(ALL(p), mx)){
            cout<<mx<<endl;
            return 0;
        }
        mn--;
        mx++;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <queue>

using namespace std;
typedef long long ll;

queue<int> que;

int Search(const int c, int n, vector<vector<int>> &d, int l, int r) {
	if (l == r)
		return d[c][l];
	int p = (l + r) >> 1;
	if (d[c][p] <= n)
		return Search(c, n, d, p + 1, r);
	else
		return Search(c, n, d, l, p);
}

int main(void) {
	int num, q, i, a = 0, b;
	ll ans = 0;
	string s, t;
	cin >> s >> t;
	vector<vector<int>> d(26, vector<int>(s.size(), 0));
	vector<int> len(26, -1);
	for (i = 0; i < s.size(); i++) {
		len[s[i] - 'a']++;
		d[s[i] - 'a'][len[s[i] - 'a']] = i + 1;
	}
	for (i = 0; i < t.size(); i++) {
		if (len[t[i] - 'a'] < 0) {
			printf("-1\n");
			return 0;
		}
		b = Search(t[i] - 'a', a, d, 0, len[t[i] - 'a']);
		if (b <= a) {
			ans += s.size() - a + d[t[i] - 'a'][0];
			a = d[t[i] - 'a'][0];
		}
		else {
			ans += b - a;
			a = b;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 11136
import numpy as np
H, W, K = map(int, input().split())
p = 10**9 + 7
r = [1, 1, 2, 3, 5, 8, 13, 21, 34]
dp = np.zeros([H + 1, W], dtype=int)
dp[0, 0] = 1
for h in range(H):
    for w in range(W):
        if w == 0:
            a = 0
        else:
            a = ((dp[h, w-1] * r[w-1])%p * r[W-1-w])%p
        b = ((dp[h, w] * r[w])%p * r[W-1-w])%p
        if w == W-1:
            c = 0
        else:
            c = ((dp[h, w+1] * r[w])%p * r[W-2-w])%p
        dp[h+1, w] = (a+b+c)%p
print(dp[H, K-1])

Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
ll dp[100010][13];
int main()
{
   string S;
   cin >> S;
   int L = S.size();
   dp[0][0]=1;
   rep(i,L){
       rep(r,13){
           if(S[i]=='?'){
               rep(d,10){
                   dp[i+1][(10*r+d)%13]+=dp[i][r];
                   dp[i+1][(10*r+d)%13]%=MOD;
               }
           }
           else{
               int nx=S[i]-'0';
               dp[i+1][(10*r+nx)%13]+=dp[i][r];
               dp[i+1][(10*r+nx)%13]%=MOD;
           }
       }
   }

   cout << dp[L][5] << endl;
}



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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll comb[53][53];
ll combsum[53][53];
void make_table(){
  for(ll i=0;i<=51;i++){
    comb[i][0]=1;
    comb[i][i]=1;
  }
  for(ll i=1;i<=51;i++)for(ll j=1;j<i;j++){
    comb[i][j]=(comb[i-1][j-1]+comb[i-1][j]);
  }
}

ll cnt0[(1<<18)];
ll cnt1[(1<<18)];
ll pcnt[(1<<18)],sgn[(1<<18)];

inline ll bitv(ll a, ll n){
  return (a>>n)&1LL;
}

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

  make_table();
  rep(i,52){
    combsum[i][0]=comb[i][0];
    rep(j,51){
      combsum[i][j+1]=combsum[i][j]+comb[i][j+1];
    }
  }

  const ll B=18;
  rep(i,1<<B){
    pcnt[i]=bcnt(i);
    if(pcnt[i]%2==1) sgn[i]=-1;
    else sgn[i]=+1;
  }

  ll N,K,S,T;
  cin>>N>>K>>S>>T;
  vector<ll> A(N);
  rep(i,N)cin>>A[i];
  vector<ll> tmp;
  ll mask=(1<<B)-1;
  rep(j,B){
    if(bitv(S,j)==1&&bitv(T,j)==0){
      cout<<0<<endl;
      return 0;
    }
  }
  rep(j,B){
    if(bitv(S,j)==1||bitv(T,j)==0){
      mask^=(1LL<<j);
    }
  }
  //dbg(mask);
  rep(i,N){
    bool ok=true;
    rep(j,B){
      if(bitv(S,j)==1&&bitv(A[i],j)==0){
        ok=false;
      }
      if(bitv(T,j)==0&&bitv(A[i],j)==1){
        ok=false;
      }
    }
    if(ok){
      tmp.push_back(A[i]);
    }
  }
  A=tmp;
  N=A.size();
  //dbg(N);

  rep(i,N)A[i]=(A[i]&mask);

  rep(S0,1<<B){
    if((S0|mask)!=mask)continue;
    rep(i,N){
      ll ax=A[i]^mask;
      if((S0|ax)==ax)cnt0[S0]|=(1LL<<i);
    }
  }

  rep(S1,1<<B){
    if((S1|mask)!=mask)continue;
    rep(i,N){
      if((S1|A[i])==A[i])cnt1[S1]|=(1LL<<i);
    }
  }

  ll res=0;
  rep(U,1<<B){
    if((U|mask)!=mask)continue;
    for(ll U1=U;U1>=0;U1--){
      U1&=U;

      //dbg(U);
      ll U2=U^U1;
      //dbg(U1); dbg(U2);
      //ll cpcnt=pcnt[cnt0[U1]&cnt1[U2]];
      ll cpcnt=bcnt(cnt0[U1]&cnt1[U2]);
      //dbg(cnt0[U1]); dbg(cnt1[U2]);
      ll add=combsum[cpcnt][K]-1;
      //dbg(cpcnt);
      //dbg(add);
      res+=add*sgn[U];
    }
  }
  cout<<res<<endl;

  return 0;
}


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}
double mini=0.00000000000001;
double memo[1000000];
double n;

double j2(ll i){
    if(abs(memo[i])>mini) return memo[i];
    if(i==0) return 1;
    return j2(i-1)/2;
}

int main(){
    ll k;
    cin>>n>>k;
    double a=1/n;
    double ans=0;
    ll count;
    ll j;
    for(ll i=1;i<=n;i++){
        count=0;
        j=i;
        while(j<k){
            count++;
            j*=2;
        }
        ans+=a*j2(count);
    }
    cout<<setprecision(15)<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll f(ll b,ll n)
{
    if(n<b)
    {
        return n;
    }else
    {
        return f(b,n/b)+(n%b);
    }
}
ll CEIL(ll x,ll y)
{
    ll res=x/y;
    if(x%y!=0)
    {
        res++;
    }
    return res;
}
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    ll n,s;
    cin>>n>>s;
    ll m=sqrt(n)+1;
    if(s>n)
    {
        puts("-1");

    }else if(s==n)
    {
        printf("%lld\n",s+1 );
    }else
    {
        for(ll i=2ll;i<=m;++i)
        {
            if(f(i,n)==s)
            {
                printf("%lld\n",i );
                return 0;
            }
        }
        ll b,q,res=1e11;
        n-=s;
        for(ll p=1ll;p*p<=n;++p)
        {
            if(n%p==0)
            {
                b=n/p+1;
                q=s-p;
                if(q>=0&&b>=2&&q<b&&p<b)
                {
                    res=min(res,b);
                }
            }
        }
        printf("%lld\n",res==1e11?-1:res );
    }
    
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



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

int main(){
    string s;
    cin>>s;
    int q;
    string endd="", big="";
    bool rev=false;
    cin>>q;
    int t, f;
    char ch;
    while(q--){
        cin>>t;
        if(t==1){
            rev = !rev;
        }else{
            cin>>f>>ch;
            if(rev==false){
                if(f==1){
                    big.push_back(ch);
                }else{
                    endd.push_back(ch);
                }
            }else{
                if(f==1){
                    endd.push_back(ch);
                }else{
                    big.push_back(ch);
                }
            }
        }
    }
    reverse(big.begin(), big.end());
//    cout<<big<<" : "<<s<<" : "<<endd<<endl;
    s = big+s+endd;
    if(rev){
        reverse(s.begin(), s.end());
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 1348
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define mpp make_pair
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 100007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
const int MAXN = 1e6+1;
#define MAXI 2e18+3
#define all(v) v.begin(), v.end()
#define endl "\n"
# define PI 3.14159265358979323846


std::map<int, int> mp1, mp2;

signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n, i;
    cin>>n;
    for(i=1;i<=n;i++){
    	int a;
    	cin>>a;
    	mp1[a+i]++;
    	mp2[i-a]++;
    }
    int sum=0;
    for(auto it=mp1.begin();it!=mp1.end();it++){
    	int x = it->first;
    	int y = it->second;
    	sum+=(y)*mp2[x];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 37808
n=int(input())
a=int(input())
f,v,w=0,a,a
a=int(input())
if a>=v:
    w,v,f=v,a,1
else:
    w=a
for i in range(2,n):
    a=int(input())
    if a>=v:
        w,v,f=v,a,i
    elif a>=w:
        w=a
for i in range(n):
    if i==f:
        print(w)
    else:
        print(v)

Measured memory_bytes: 4540
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}

ll sosuu(ll x){
    for(int i = 2; i < x; i++){
        if(x % i == 0) return false;
    }

    return true;
}


//入力

int main(){


    int x, y;
    cin >> x >> y;

    cout << x * y << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll 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 % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll 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] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll k;
    cin >> k;
    ll a = 7 % k;
    ll cnt = 1;
    rep1(i,k){
        if(a == 0){
            cout << cnt << endl;
            return 0;
        }else{
            a = (a*10 + 7) % k;
            cnt++;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin >> n;

    long long ans = 1e12;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ans = min(ans, i + n / i - 2);
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    string s;
    bool odd = false;
    cin >> s;
    int count01 = 0;
    int count10 = 0;
    int length = s.size();
    if (length % 2 == 1) {
        odd = true;
    }
    for (int i = 0; i < (int)(length / 2); i++) {
        if (s.at(2 * i) == '1') count01++;
        else if (s.at(2 * i) == '0') count10++;
        if (s.at(2 * i + 1) == '0') count01++;
        else if (s.at(2 * i + 1) == '1') count10++;
    }
    if (odd) {
        if (s.at(length - 1) == '1') count01++;
        else count10++;
    }
    int ans = min(count01, count10);
    cout << ans << endl;
}


Measured memory_bytes: 512