akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
MOD = 10**9+7

def factorize(N):
    res = []
    for i in range(2, N):
        if i**2 > N: break
        if N % i != 0: continue
        num = 0
        while N % i == 0:
            N = int(N/i)
            num += 1
        res.append(num)
    if N>1: res.append(1)
    return res

res = factorize(M) if M>1 else [0]

n = max(res) + N 

fac = [1]*n
inv = [1]*n
finv = [1]*n

for i in range(2, n):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * int(MOD / i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

ans = 1
for m in res:
    a = fac[m+N-1] * (finv[m] * finv[N-1] % MOD) % MOD
    ans = ans*a%MOD

print(ans)

Measured memory_bytes: 66864
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
string s;
int ans,minn=123456789;
int getint(string s)
{
	return (s[0]-'0')*100+(s[1]-'0')*10+(s[2]-'0');
}
int main()
{
	cin>>s;
	for (int i=0;i<s.size()-2;i++)
	{
		string s1=s.substr(i,3);
		int a=getint(s1);
		if (abs(a-753)<minn) minn=abs(a-753),ans=minn;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void){
    int a;


    std::cin >> a;

    for(int i = 1; i <= 9; i++){
        if(a % i == 0 && (float)a/i <= 9.0f ){
            std::cout << "Yes";
            exit(0);
        }
    }
    std::cout << "No";

}


Measured memory_bytes: 256
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

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

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         input(a)       for(auto &it : a) cin>>it
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         vcl            vector<ll>
#define         vpl            vector<pair<ll,ll>>
#define         pb             push_back
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         ikarus_101     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){ikarus_101

    ll tc,n,m,a,b,c,d,x,y,i,j,l,r,k,ans,sum,tot,cnt,mx,mn,idx,tmp;

    string s="ABC",t;
    cin>>t;
    if(t == s)
    {
        cout<<"ARC"<<nn;
    }
    else
        cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n, k; cin >> n >> k;
    int d = 0;
    while (n > 0) {
        ++d;
        n /= k;
    }
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

class Data
{
public:
    int y, x;
    bitset<8> bs;
    Data(int y0, int x0, bitset<8> bs0){
        y = y0;
        x = x0;
        bs = bs0;
    }
};

int h, w;
vector<string> s;
int sy, sx;
int n;
vector<int> index;

int solve()
{
    vector<vector<vector<bool> > > check(h, vector<vector<bool> >(w, vector<bool>(1<<n, false)));
    check[sy][sx][0] = true;
    queue<Data> q;
    q.push(Data(sy, sx, 0));

    int ret = 0;
    while(!q.empty()){
        ++ ret;
        int qNum = q.size();
        while(--qNum >= 0){
            int y0 = q.front().y;
            int x0 = q.front().x;
            bitset<8> bs0 = q.front().bs;
            q.pop();

            for(int i=0; i<4; ++i){
                int y = y0 + dy[i];
                int x = x0 + dx[i];
                bitset<8> bs = bs0;

                if(s[y][x] == '<'){
                    return ret;
                }else if(s[y][x] == '#'){
                    continue;
                }else if(islower(s[y][x])){
                    bs[index[s[y][x]]] = !bs[index[s[y][x]]];
                }else if(isupper(s[y][x])){
                    if(index[s[y][x]] == -1)
                        continue;
                    if(!bs[index[s[y][x]]])
                        continue;
                }

                if(!check[y][x][bs.to_ulong()]){
                    check[y][x][bs.to_ulong()] = true;
                    q.push(Data(y, x, bs));
                }
            }
        }
    }

    return -1;
}

int main()
{
    for(;;){
        cin >> w >> h;
        if(h == 0)
            return 0;

        s.assign(h, string(w, ' '));
        n = 0;
        index.assign(128, -1);
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cin >> s[i][j];
                if(s[i][j] == '@'){
                    sy = i;
                    sx = j;
                    s[i][j] = '.';
                }else if(islower(s[i][j]) && index[s[i][j]] == -1){
                    index[s[i][j]] = n;
                    index[s[i][j] - 'a' + 'A'] = n;
                    ++ n;
                }
            }
        }

        cout << solve() << endl;
    }
}

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

int main(){
    int count[4][3][10];
    int n;
    int b, f, r, v;

    for(int i = 0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                count[i][j][k] = 0;
            }
        }
    }

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        b--;f--;r--;
        count[b][f][r] += v;
    }

    for(int i=0;i<4;i++){
        if(i){cout << "####################" << endl;}
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout << " " << count[i][j][k];
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val charSet = ('a' to 'z').toArray
    val keyword = Set("the", "this", "that")
    val sc = new Scanner(System.in)
    var line = ""

    (1 to 20).foreach { _ =>
      if (!sc.hasNext) return

      line = sc.nextLine
//      line = "xlmw mw xli tmgxyvi xlex m xsso mr xli xvmt."

      (0 to 25).foreach { diff =>
        val result = line.map { ch =>
          val idx = charSet.indexOf(ch)

          if (idx < 0) {
            ch
          } else {
            if (idx - diff < 0) {
              (ch - diff + charSet.length).toChar
            } else {
              (ch - diff).toChar
            }
          }
        }.toString

        if (result.split(" ").exists(keyword.contains)) {
          println(result)
        }
      }
    }
  }
}

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

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

    ll maxv = 0;
    ll minv = a[0];

    for (int i=1; i<n; ++i) {
        maxv = max(maxv, a[i] - minv);
        minv = min(minv, a[i]);
    }

    ll ans = 0;
    ll maxv2 = 0;
    minv = a[0];
    for (int i=1; i<n; ++i) {
        if (maxv2 < a[i] - minv) {
            if (a[i] - minv == maxv) { ans++; }
            else maxv2 = max(maxv2, a[i] - minv);
        }
        minv = min(minv, a[i]);
    }

    cout << ans << endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li d;
li c[111];
li s[444][33];

li last[33];

int main() {
    cin >> d;
    rep(i, 26) {
        cin >> c[i];
        last[i] = -1;
    }
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }

    rep(i, d) {
        cout<<i%26+1<<endl;
    }


    return 0;
}

Measured memory_bytes: 3728
from math import ceil
N = int(input())
T, A = 1, 1
for k in range(N):
    t, a = map(int,input().split())
    b = max(T//t,A//a)
    if t*b < T or a*b < A:
        b += 1
    T, A = t*b, a*b
print(T+A)


Measured memory_bytes: 40176
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc,char** argv){
  int n,x;
  cin >> n >> x;
  vector<int> a(n);
  int s = 0;
  for(int i = 0 ; i<n;i++){
    cin >> a[i];
    s += a[i];
  }
  sort(a.begin(),a.end());
  long sum = 0;
  int ret = 0;
  for(int i = 0; i < n-1; i++){
    sum += a[i];
    if(sum > x){
      break;
    }else{
      ret++;
    }
  }
  if(sum+a[n-1] == x){
    ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
lines = []

for i in range(N-1):
    lines.append(input())

C = []
S = []
F = []

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
		n = F[j] - n if a > S[j] and n != 0 else n
		# n = S[j] - a if a <= S[j] else a % F[j]
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
print(0)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long dp[20010];
  
int main()
{
  ll H,N;
  cin >> H >> N;
  vector<P> A(N);
  REP(i,N) cin >> A[i].first >> A[i].second;

  REP(i,20010){
    dp[i]=INF;
  }

  dp[0]=0;
  REP(i,H+1){
    REP(j,N){
      chmin(dp[i+A[j].first],dp[i]+A[j].second);
    }
  }

  ll cnt = dp[20000];
  REPR(i,20000){
    if(dp[i]>1000000000){
      dp[i]=cnt;
    }else if(cnt>dp[i]){
      cnt=dp[i];
    }else{
      dp[i]=cnt;
    }
  }

  cout << dp[H] << endl;
}

Measured memory_bytes: 384
using System;

namespace ABC130A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            if (b <= a)
                Console.WriteLine(10);
            else if (a < b)
                Console.WriteLine(0);
            Console.ReadKey();

        }
    }
}

Measured memory_bytes: 13140
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        X, Y = map(int, input().split())

        cnt = 0
        for n in range(X + 1):
            if (X - n) % 2 != 0:
                continue
            else:
                m = (X - n) // 2
                if 2 * n + m == Y:
                    cnt += self.cmb(n+m,n)

        print(cnt % (10 ** 9 + 7))

    def cmb(self,  n, r):
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2, r + 1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p - 1, r, p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result

# Run main
if __name__ == '__main__':
    AtCoder().main()



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

int main(){
    int N, A;
    cin >> N >> A;
    vector<int> xs(N, 0);
    for (auto &x : xs) cin >> x;
    vector<vector<long long>> dp(N + 1, vector<long long>(N * A + 1, 0LL));
    dp[0][0] = 1LL;
    for (auto x : xs){
        for (int n = N; n != 0; --n){
            for (int i = 0; i <= N * A - x; ++i){
                dp[n][i + x] += dp[n - 1][i];
            }
        }
    }
    long long ans = 0LL;
    for (int i = 1; i <= N; ++i){
        ans += dp[i][i * A];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


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

    cout << ((a >= 3200) ? s : "red") << endl;
}

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

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<long long> a;

    long long ans = 1;
    for (int i = 0; i < N; i++) {
        long long temp;
        cin >> temp;
        if (temp == 0){
            cout << 0 << endl;
            return 0;
        }
        a.push_back(temp);
    }

    sort(a.begin(), a.end());
    for (int i = 0; i < N; i++) {
        if(1000000000000000000/a[i] >= ans){
            ans *= a[i];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

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


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

int main() {
	ll x,y;
	cin >> x >> y;
	ll cnt = 0;
	while(x<=y) {
		cnt++;
		x*=2;
	}
	cout << cnt << endl;
	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    int A;
    cin >> A;
    if (0 == A%2)
    {
      if ((0 == A%3) || (0 == A%5))
        continue;
      else
      {
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
  return 0;
}


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


N = int(input())
divisors = calc_divisors(N)

ans = 0
for d in divisors:
    m = d - 1
    if m > 1 and N // m == N % m:
        ans += m
print(ans)


Measured memory_bytes: 39920
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,t,x=0;
    cin>>n>>t;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++){
        x+=min(t,a[i+1]-a[i]);
    }
    x+=t;
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define N 1000000
#define INF -10000000
int A[N], heapSize = 0;

void heapIncreaseKey(int i, int key) {
  int tmp;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]) {
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key) {
  int i;
  heapSize++;
  A[heapSize] = INF;
  i = heapSize;
  heapIncreaseKey(i, key);
}

void maxHeapify(int i) {
  int l, r, largest, tmp;

  while(1) {
    l = 2*i;
    r = 2*i+1;
    if(l <= heapSize && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= heapSize && A[r] > A[largest]) largest = r;
    if(largest != i) {
      tmp = A[i];
      A[i] = A[largest];
      A[largest] = tmp;
      i = largest;
    }
    else break;
  }
}

int extract(void) {
  int max;
  if(heapSize < 1) return 0;
  max = A[1];
  A[1] = A[heapSize];
  heapSize--;
  maxHeapify(1);
  return max;
}

int main () {
  char cmd[8];
  int key, i;

  while(1) {
    scanf("%s", cmd);
    if(cmd[0] == 'i') {
      scanf("%d", &key);
      insert(key);
    }
    if(cmd[0] == 'e' && cmd[1] == 'x') printf("%d\n", extract());
    if(cmd[0] == 'e' && cmd[1] == 'n') break;
  }

  return 0;
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
#define FF ios_base::sync_with_stdio(0);cin.tie(0)
#define binary(value, size) cout << bitset<size>(value) << '\n'
#define PI acos(-1.0)   //3.1416(180 degree to radian)
#define PIby2 asin(1)     //(3.1416/2) for angle(90 degree to radian)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sz size()
#define rr read
#define ww write
#define clr(arr) memset((arr),0,(sizeof(arr)))
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asort2(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define all2(v,a,b) (v).begin()+a,(v).end()-b
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define BS(v,x) binary_search(v.begin(),v.end(),x) //return true /false
#define LB(v,x) lower_bound(v.begin(),v.end(),x) //found and that value and not found than greater value pos
#define UB(v,x) upper_bound(v.begin(),v.end(),x) //found and greater value pos && not found also greater pos
#define convertlower(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
#define INF 2000000000
#define N 10000000
#define Ceil(n) (long long int)ceil(n)
#define Floor(n) (long long int)floor(n)
#define deb(x) std::cout << #x << " = " << x << std::endl;
#define out(ans) cout<<ans<<endl
#define outs(ans) cout<<ans<<" "<<endl
using namespace std;

typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mpl;
int main()
{
    ll n,t,ans=0;
    cin>>n>>t;
    vll v(n+2),sum(n+1);
    rep(i,1,n+1)
    {
        cin>>v[i];
    }
    v[n+1]=INF;
    rep(i,1,n+1)
    {
        sum[i]=min(t,v[i+1]-v[i]);
        ans+=sum[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int n, k;

double res = 0;

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        if (i >= k)
            res += 1.0 / n;
        else
        {
            int x = i, y = 0;
            while (x < k)
                ++y, x *= 2;
            res += 1.0 / n * pow(0.5, y);
        }
    }
    printf("%.12lf\n", res);
    return 0;
}



Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    N = int(readline())
    blue = Counter()
    red = Counter()

    for _ in range(N):
        s = input()
        blue[s] += 1

    M = int(readline())

    for _ in range(M):
        s = input()
        red[s] += 1

    ans = 0

    for key in blue.keys():
        score = blue[key] - red[key]
        ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){cin>>vec.at(i);}
  sort(vec.begin(),vec.end());
  int count=1;
  for(int i=1;i<N;i++){
    if(vec.at(i)>vec.at(i-1)){
      count++;
    }
  }
  cout<<count<<endl;
}



Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 10**18

def main():
    n = int(ipt())
    base = 10**9
    qs = []
    lma = 0
    li = -1
    ll = 0
    rmi = INF
    ri = INF
    lr = 0
    mal = 0
    for i in range(n):
        l,r = map(int,ipt().split())
        qs.append((l,r))
        d = r-l+1
        f = True
        if l > lma:
            if ll > mal:
                mal = ll
            lma = l
            li = i
            ll = d
            f = False
        elif l == lma and ll > d:
            li = i
            mal = max(mal,ll)
            ll = d
            f = False
        if r < rmi:
            if lr > mal:
                mal = lr
            rmi = r
            ri = i
            lr = d
            f = False
        elif r == rmi and lr > d:
            ri = i
            mal = max(mal,lr)
            lr = d
            f = False
        if f and mal < d:
            mal = d

    ans = mal+max(0,rmi-lma+1)
#    print(ans)

    q = []
    for la,ra in qs:
        v = (base-1-max(0,ra-lma+1))*base+max(0,rmi-la+1)
        q.append(v)

    q.sort()
    dp0 = [INF,0]
    dp1 = [0,INF]
    f = False
    for i in q:
        l = base-1-i//base
        r = i%base
        if f:
            dp1[1] = min(dp1[1],r)
            if dp0[0]+r > sum(dp1):
                dp1[0] = dp0[0]
                dp1[1] = r
        f = True
        dp0[0] = min(dp0[0],l)
#        print(dp0,dp1)

    print(max(ans,sum(dp1)))






    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 88040
using System;
using System.Linq;

namespace ABC126C
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NK = CIN.LongArray();
            long N = NK[0];
            long K = NK[1];

            double ans = 0.0;

            int pow = 1;
            double rate = 1;
            for (long i = N; i > 0; i--)
            {
                while (true)
                {
                    if (i * pow >= K)
                    {
                        double a = rate;
                        ans += a;
                        break;
                    }

                    pow *= 2;
                    rate /= 2;
                }
            }
            Console.WriteLine(ans/N);
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 11348
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n, m; cin >> n >> m;
	vector<pair<ll, string>> data(m);
	for (int i = 0; i < m; i++) {
		ll a; cin >> a;
		string b; cin >> b;
		data[i].first = a;
		data[i].second = b;
	}
	vl x(n, 0);
	vector<bool> y(n, true);
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		if (y[data[i].first-1]) {
			if (data[i].second == "AC") {
				y[data[i].first-1] = false;
			}
			else {
				x[data[i].first-1]++;
			}
		}
	}
	ll count = 0;
	for (int i = 0; i < n; i++) {
		if (y[i] == false) {
			ans++;
			count += x[i];
		}
	}
	cout << ans << " " << count << endl;
}

Measured memory_bytes: 8020
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
    int N,K; ll sum = 0; cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    queue<ll> que;
    for (int i = 1; i*i <= sum; i++){
        if (sum % i != 0) continue;
        que.push(i);
        if (i*i != sum) que.push(sum/i);
    }
    int ans = 1;
    while (que.size()){
        int x = que.front();
        que.pop();
        vector<int> b(N);
        int tmp = 0;
        for (int i = 0; i < N; i++){
            b[i] = a[i] % x;
            tmp += b[i];
        }
        sort(b.begin(),b.end());
        reverse(b.begin(),b.end());
        int cnt = tmp/x;
        for (int i = 0; i < cnt; i++){
            tmp -= b[i];
        }
        if (0 <= tmp && tmp <= K) ans = max(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int i,j;
    int a=0;
    int b=0;
    for(i=0;i<4;i++){
        int x;
        cin>>x;
        a+=x;
    }
    for(i=0;i<4;i++){
        int x;
        cin>>x;
        b+=x;
    }
    cout<<((a>b)? a: b)<<endl;

}


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

int main(){
    int k;
    string s;
    cin >> k >> s;
    //cout << s.size() << endl;
    if(s.size() > k){
        for(int i = 0; i < k; i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
    else{
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class d {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin >> n;
        vector<int> a(n);
        REP(i, n) {
            cin >> a[i];
        }

        int cur = 0;
        REP(i, n) {
            if (a[i] == cur + 1) {
                cur++;
            }
        }
        if (cur == 0) {
            cout << -1 << endl;
        } else {
            cout << n - cur << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    d solver;
    solver.solve(in, out);
    return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e3 + 5;

int cnt[MAXN][MAXN];
int dp_cnt[MAXN][MAXN];

int get_cnt(int il, int jl, int ir, int jr, int k){
	il = max(il, 0);
	jl = max(jl, 0);
	ir = min(ir, 2 * k - 1);
	jr = min(jr, 2 * k - 1);
	if (il > ir || jl > jr){
		return 0;
	}
	int ans = dp_cnt[ir][jr];
	if (il){
		ans -= dp_cnt[il - 1][jr];
	}
	if (jl){
		ans -= dp_cnt[ir][jl - 1];
	}
	if (il && jl){
		ans += dp_cnt[il - 1][jl - 1];
	}
	return ans;
}

void solve(){
	int n, k, x, y;
	char s[10];
	scanf("%d%d", &n, &k);
	REP(i, 0, n){
		scanf("%d%d%s", &x, &y, &s[0]);
		if (s[0] == 'B'){
			x += k;
		}
		x %= (2 * k);
		y %= (2 * k);
		cnt[x][y]++;
	}
	REP(i, 0, 2 * k){
		dp_cnt[i][0] = cnt[i][0];
		REP(j, 1, 2 * k){
			dp_cnt[i][j] = cnt[i][j] + dp_cnt[i][j - 1];
		}
	}
	REP(i, 1, 2 * k){
		REP(j, 0, 2 * k){
			dp_cnt[i][j] += dp_cnt[i - 1][j];
		}
	}
	/*REP(i, 0, 2 * k){
		REP(j, 0, 2 * k){
			printf("%d ", dp_cnt[i][j]);
		}
		putchar('\n');
	}*/
	int mx = 0;
	REP(i, 0, k){
		REP(j, 0, 2 * k){
			int cnt = 0;
			REPN(i1, -3, 3){
				REPN(j1, -3, 3){
					if ((i1 + j1) % 2 == 0){
						int i2 = i + i1 * k;
						int j2 = j + j1 * k;
						cnt += get_cnt(i2, j2, i2 + k - 1, j2 + k - 1, k);
						/*if (i == 1 && j == 2){
							printf("%d %d %d %d %d\n", i2, j2, i2 + k - 1, j2 + k - 1, get_cnt(i2, j2, i2 + k - 1, j2 + k - 1, k));
						}*/
						//printf("%d %d %d\n", i, j, cnt);
					}
				}
			}
			mx = max(mx, cnt);
		}
	}
	printf("%d\n", mx);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main(void){
    int n,m,a,i,sum=0;
    cin>>n>>m;
    for(i=1;i<=m;++i){
        cin>>a;
        sum+=a;
    }
    if(sum>n)cout<<-1<<endl;
    else cout<<n-sum<<endl;
}

Measured memory_bytes: 3652
r0, r1 = map(int, input().split())
a0, a1 = 1, 0
b0, b1 = 0, 1
while 0 < r1:
    q1 = r0 // r1
    a0, a1 = a1, a0 - q1 * a1
    b0, b1 = b1, b0 - q1 * b1    
    r0, r1 = r1, r0 % r1
 
print(a0, b0)

Measured memory_bytes: 7624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, x;

	while (cin >> n >> x) {
		if (n == 0 && x == 0)
			break;
		int ans = 0;
		for (int a = 1; a <= n; a++) {
			for (int b = a + 1; b <= n; b++) {
				for (int c = b + 1; c <= n; c++) {
					if (a + b + c == x)
						ans++;
				}
			}
		}
		cout << ans << endl;
	}
}



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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int ts(char *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 10007 , mo = 998244353;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;a=(a+mo)%mo;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

lint jc[_],rjc[_];

void fuck(int n=_-1)
{
	jc[0]=jc[1]=rjc[0]=1;
	for(int i=2;i<=n;i++)jc[i]=jc[i-1]*i%mo;
	rjc[n]=inva(jc[n]);
	for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}

lint C(int n,int m)
{
	if(n<m || n<0 || m<0)return 0;
	return jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}

int n;char sa[_],sb[_];
int f[_][_]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	fuck();
	
	n=ts(sa+1),ts(sb+1);
	int cnt1=0,cnt2=0;
	for(int i=1;i<=n;i++)
	{
		if(sa[i]=='1' && sb[i]=='1')cnt1++;
		if(sa[i]=='1' && sb[i]=='0')cnt2++;
	}

	for(int i=0;i<=cnt2;i++)f[0][i]=jc[i]*jc[i]%mo;
	for(int i=1;i<=cnt1;i++)
		for(int j=1;j<=cnt2;j++)
			f[i][j]=(1ll*f[i][j-1]*j%mo*j%mo+1ll*f[i-1][j]*i%mo*j%mo)%mo;
	lint ans=0;
	for(int i=0;i<=cnt1;i++)
		ad(ans,1ll*f[cnt1-i][cnt2]*jc[i]%mo*jc[i]%mo*C(cnt1,i)%mo*C(cnt1+cnt2,i)%mo);
	cout<<ans<<lf;

	return 0;
}


Measured memory_bytes: 389760
#include <iostream>
#include <string>
using namespace std;
string w;
int main()
{
  cin >> w;
  for (char c = 'a'; c != 'z'; c++)
  {
    int count = 0;
    for (int i = 0; i < w.size(); i++)
    {
      if (w[i] == c)
      {
        count++;
      }
    }
    if (count % 2 != 0)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lowbit(x) (x & -x)
#define lrt nl, nr, rt << 1
#define rrt nl, nr, rt << 1 | 1
const ll Inf = 1e18;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
	return f * x;
}

int main(void)
{
	int n;
	n = read();
	ll ans = (ll)n * (n - 1) / 2;
	printf("%lld\n", ans);
	return 0;
}

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

string toNaryNumber(long long x, int n)
{
    string s;
    while (x != 0)
    {
        int r = abs(x % n);
        s += to_string(r);
        x -= r;
        x /= n;
    }
    reverse(s.begin(), s.end());

    return s;
}

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

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

    vector<vector<int>> s(M);
    vector<int> p(M);
    for (int i = 0; i < M; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            s[i].push_back(a);
        }
    }
    for (int i = 0; i < M; i++)
    {
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 0; i < pow(2, 10); i++)
    {

        // cout << "########## i = " << i << endl;

        if (i == pow(2, N))
        {
            break;
        }

        string str = toNaryNumber(i, 2);
        while (str.size() < 9)
        {
            str = "0" + str;
        }

        int on_num = 0;
        for (int j = 0; j < M; j++)
        {
            int cnt = 0;
            for (int k = 0; k < s[j].size(); k++)
            {
                if (str[str.size() - s[j][k]] == '1')
                {
                    cnt++;
                }
            }

            if (cnt % 2 == p[j])
            {
                on_num++;
            }
        }

        // cout << "str: " << str << endl;
        // cout << "on_num: " << on_num << endl;

        if (on_num == M)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;

	int ans = n;

	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (a <= t && t < b) ans--;
	}

	cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll x, n;
bool used[1100];
int main() {
    cin >> x >> n;
    vector<ll> s(n);
    ll ans = INF;
    ll now = 0;
    REP(i, n){
        cin >> s[i];
        used[s[i]] = true;
    }
    REP(i, 1000) {
        if(!used[x - i]){
            cout << x - i << endl;
            return 0;
        }
        if(!used[x + i]){
            cout << x + i << endl;
            return 0;
        }
    }
}


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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] p = new int[N];
        for(int i=0;i<N; i++){
            p[i] = sc.nextInt();
        }
        sc.close();;
        Arrays.sort(p);
        int ans = 0;
        for(int i=0; i<K; i++){
            ans = ans + p[i];
        }
        System.out.println(ans);
    }
}


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

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

    vector<int> p;
    int x = 1;
    while(true) {
        p.push_back(x);
        if(x > k) break;
        x *= 2;
    }

    int m = p.size();

    long double prob = 0.0;
    for (int i = 1; i <= n; i++) {
        long double cnt = 0;
        for (int j = 0; j < m; j++) {
            if(i * p[j] >= k) {
                cnt = double(p[j]);
                break;
            }
        }
        prob += (1.0 / cnt / n);
    }
    cout << fixed << setprecision(15) << prob << endl;
}

Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())
water = 1
sugar = -1
for w_a in range(0, F + 1, 100 * A):
    for w_b in range(0, F - w_a + 1, 100 * B):
        new_w = w_a + w_b
        if new_w == 0:
            continue
        G = min(F - new_w, new_w * E // 100)
        for s_c in range(0, G + 1, C):
            for s_d in range(0, G - s_c + 1, D):
                new_s = s_c + s_d
                if sugar / water < new_s / new_w:
                    water = new_w
                    sugar = new_s
print(water + sugar, sugar)

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

using namespace std;

const int Maxn = 40;
const int Maxm = 510;
const int Inf = 0x7fffffff;

int n , c;
int a[Maxm][Maxm];
int d[Maxn][Maxn];
int dp[3][Maxn];

int main() {
	
	scanf("%d%d",&n,&c);
	for(register int i=1; i<=c; i++)
		for(register int j=1; j<=c; j++)
			scanf("%d",&d[i][j]);
	for(register int i=1; i<=n; i++)
		for(register int j=1; j<=n; j++)
			scanf("%d",&a[i][j]);
	
	
	for(register int z=0; z<3; z++)
		for(register int k=1; k<=c; k++)
			for(register int i=1; i<=n; i++)
				for(register int j=1; j<=n; j++)
					if(((i+j)%3) == z)
						dp[z][k] += d[a[i][j]][k];
	
	register int minl = Inf;
	for(register int i=1; i<=c; i++)
		for(register int j=1; j<=c; j++)
			for(register int k=1; k<=c; k++)
				if(i!=j && i!=k && k!=j)
					minl = min(minl,dp[0][i]+dp[1][j]+dp[2][k]);
	
	printf("%d\n",minl);
	
	return 0;
	
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t H, W;
    cin >> H >> W;

    auto mat = make_v(' ', H + 1, W + 1);
    for (size_t i = 1; i <= H; ++i) {
        for (size_t j = 1; j <= W; ++j) {
            cin >> mat[i][j];
        }
    }

    const int MOD = int(1e9) + 7;

    auto dp = make_v(0, H + 1, W + 1);
    dp[1][1] = 1;
    for (size_t i = 1; i <= H; ++i) {
        for (size_t j = 1; j <= W; ++j) {
            if (mat[i][j] == '.') {
                (dp[i][j] += dp[i - 1][j]) %= MOD;
                (dp[i][j] += dp[i][j - 1]) %= MOD;
            }
        }
    }

    cout << dp[H][W] << "\n";

    return 0;
}


Measured memory_bytes: 5248
n,h,w = map(int,input().split())
i = 0
k = 0
answer = 0
a = [""] * n
b = [""] * n
while i < n:
    a[i],b[i] = map(int,input().split())
    i += 1

while k < n:
    if h <= a[k] and w <= b[k]:
        answer += 1
    k += 1
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <unordered_map>
#include <algorithm>

using namespace std;
using ll = long long;

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

    unordered_map<string, ll> m;

    for(int i=0; i<n; i++){
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        m[str]++;
    }

    ll ans = 0;
    for(auto x: m){
        ans += x.second*(x.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10660