akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter
readline = sys.stdin.readline

A = [0]
dp = [0]
N = int(readline())

cnt = 0
while N:
    cnt += 1
    idx = len(A)
    if N >= 1+dp[-1]:
        N -= 1+dp[-1]
        A.append(cnt)
        dp.append(1+2*dp[-1])
    else:
        for l in range(len(A)):
            if N >= dp[l] + 1:
                idx = l
    
        N -= dp[idx] + 1
        dp = dp[:idx+1] + [2*dp[idx]+1] + [dp[idx]+1 + dp[i] for i in range(idx+1, len(dp))]
        A = A[:idx+1] + [cnt] + A[idx+1:]

ans = (A[1:] + list(range(1, len(A))))
print(len(ans))
print(*ans)

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

namespace AOJHelloWorld1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            int x;
            x = 0;
            for (int i = a; i < b+1; i++)
            {
               if(c%i == 0)
                {
                    x++;
                }
                else { }
            }
            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 18044
k, n = map(int, input().split())
a = list(map(int, input().split()))

d = []
for i in range(n - 1):
    d.append(a[i + 1] - a[i])
d.append(k - a[n - 1] + a[0])
d.sort()
print(sum(d[:-1]))

Measured memory_bytes: 32196
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        sc.close();
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (i * r > n)
                break;
            for (int j = 0; j <= n; j++) {
                if (i * r + j * g > n)
                    break;
                int c = n - i * r - j * g;
                if (c % b == 0 && c / b <= n)
                    ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 7;
static const int MAX_M = 2000;
static const int MAX_S = 3000;
static const int MOD = 100000;
 
int N, M, S;
int memo[2][MAX_M + 1][MAX_S + 1];
 
int main(){
    for(;;){
        scanf("%d %d %d", &N, &M, &S);
        if(N == 0 && M == 0 && S == 0) break;
        N *= N;
        fill(memo[0][0], memo[2][0], 0);
        memo[0][0][0]++;
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= M; j++){
                for(int k = 0; k <= S; k++){
                    int diff = N - i + 1;
                    if(k - diff < 0) continue;
                    memo[1][j][k] = memo[1][j - 1][k - diff]; // b_iの値を1つ増やす場合
                    memo[1][j][k] += memo[0][j - 1][k - diff]; // b_(i-1)からb_iに切り替える場合
                    memo[1][j][k] %= MOD;
                }
            }
            for(int j = 0; j <= M; j++){
                for(int k = 0; k <= S; k++){
                    memo[0][j][k] = memo[1][j][k];
                }
            }
        }
        int res = 0;
        for(int i = 0; i <= M; i++){
            res += memo[0][i][S];
            res %= MOD;
        }
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 49636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





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


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n,d; cin >> n >> d;
    i32 cnt = 0;
    vec<vi> x(n, vi(d));
    rep(i,n)rep(j,d) cin >> x[i][j];

    bool can;
    for(int i = 0; i < n-1; ++i) {
        for(int j = i+1; j < n; ++j) {
            can = 0;
            i32 dist = 0;
            rep(k,d) dist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            for(i32 p = 1; p*p <= dist; ++p) if(p*p == dist) can = 1;
            if(can) ++cnt;
        }
    }

    cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int a[100010];

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n & 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1];
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  ll ans=1;
  rep(i,1,n+1){
    ans=ans*i%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def cost(i, j=1):
    return abs(a[i] - a[i+j])

n = int(input())
a = [0] + [int(i) for i in input().split()] + [0]

c = sum([cost(i) for i in range(n+1)])
for i in range(1, n+1):
    print(c - cost(i-1) - cost(i) + cost(i-1, 2))

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

int main(){
	long int i,a,n,min=1000000,max=-1000000,sum=0;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >>a;
		if(a<min){min=a;}
		if(a>max){max=a;}
		sum=sum+a;
	}
	cout <<min<<" "<<max<<" "<<sum<<endl;
}

Measured memory_bytes: 1164
//ABC061B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> ans(n);
	for(int i=0;i<n;i++){
		ans.at(i) = 0;
	}
	for(int i=0;i<m;i++){
		int a, b;
		cin >> a >> b;
		ans.at(a-1)++;
		ans.at(b-1)++;
	}
	for(int i=0;i<n;i++){
		cout << ans.at(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<int>v(M + 1);
	for (int i = 0; i < N; i++) {
		cin >> K;
		for (int j = 0; j < K; j++) {
			cin >> L;
			v[L]++;
		}
	}
	for (int i = 1; i <= M; i++) {
		if (v[i] == N)R++;
	}
	cout << R << endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const ll mod=1e9+7;
const ll sze=4;
int main(){
  ll A,B;
  sl(A);sl(B);
  ll arr[sze];
  ms(arr,0);
  arr[A]=1;
  arr[B]=1;
  for(ll i=1;i<=3;i++){
	  if(arr[i]==0)cout<<i<<endl;
  }
    
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
#print(x)
if m-n <= 0: print(0)
else:
    dist = []
    for i in range(m-1):
        dist.append(x[i+1] -x[i]) #差を計算する
    dist.sort() #差を小さい順に並べる
    #print(dist)
    print(sum(dist[:m-n]))


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

using namespace std;

int main(void) {
    int A;
    cin >> A;
    int B;
    cin >> B;

    // 修正開始
    if (B == 1) {
        cout << 0 << endl;
        return 0;
    }
    // 修正終了
    
    int cnt = 1;
    int now = A;
    while (now < B) {
        now += A - 1;
        cnt++;
    }

    cout << cnt << endl;
}


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

const int N_MAX = 1e5;

int main()
{
	int N;
	cin >> N;
	int q = 0, even = 0, odd = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) {
			q += 1;
		}
		if (a % 2 == 0) {
			even += 1;
		}
		if (a % 2 == 1) {
			odd += 1;
		}
	}
	if (N%2==0) {
		if (q >= odd || odd == 0) {
			printf("Yes");
		}
		else {
			printf("No");
		}
	}
	if (N % 2 == 1) {
		if (even - q == 0) {
			if (q + 1 >= odd) {
				printf("Yes");
			}
			else {
				printf("No");
			}
		}
		else {
			if (q >= odd) {
				printf("Yes");
			}
			else {
				printf("No");
			}
		}
	}
	
}


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

int main()
{
	int C[3][3], B[100][3], Bs = 0, B2[100][3], Bs2 = 0;

	for (int i = 0; i < 3; i++) {
		for (int k = 0; k < 3; k++) {
			cin >> C[i][k];
		}
	}

	for (int a = 0; a <= 100; a++) {
		for (int k = 0, b1, b2, b3; k < 3; k++) {
			for (int b = 0; b <= 100; b++) {
				if (C[0][k] == a + b) {
					if (k == 0)b1 = b;
					if (k == 1)b2 = b;
					if (k == 2)b3 = b;
					break;
				}
			}
			if (k == 2 && a + b1 == C[0][0] && a + b2 == C[0][1] && a + b3 == C[0][2]) {
				B[Bs][0] = b1;
				B[Bs][1] = b2;
				B[Bs][2] = b3;
				Bs++;
			}
		}
	}

	int c = 0;
	for (int a = 0; a <= 100; a++) {
		int b1, b2, b3;
		for (int b = 0; b < Bs; b++) {
			b1 = B[b][0];
			b2 = B[b][1];
			b3 = B[b][2];
			if (a + b1 == C[1][0] && a + b2 == C[1][1] && a + b3 == C[1][2]) {
				B2[Bs2][0] = b1;
				B2[Bs2][1] = b2;
				B2[Bs2][2] = b3;
				Bs2++;
			}
		}
	}

	if (Bs2 == 0) {
		cout << "No" << endl;
		return 0;
	}


	for (int a = 0; a <= 100; a++) {
		int b1, b2, b3;
		for (int b = 0; b < Bs2; b++) {
			b1 = B2[b][0];
			b2 = B2[b][1];
			b3 = B2[b][2];
			if (a + b1 == C[2][0] && a + b2 == C[2][1] && a + b3 == C[2][2]) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}


	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    long long int X;
    scanf("%lld", &X);

    long long int i = 0;

    long long int p = 100;

    while(1){
        if(i < 0)
            break;
        if(p >= X)
            break;
        p *= 1.01;
        i++;
    }

    printf("%lld\n", i);

    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

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

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

H,W = map(int,readline().split())
a = [readline().rstrip() for i in range(H)]

h = [True] * H
w = [True] * W

for i in range(H):
    if a[i] == "."*W:
        h[i] = False
for i in range(W):
    if all(a[j][i] == "." for j in range(H)):
        w[i] = False
ans = []
for i in range(H):
    s = ""
    for j in range(W):
        if h[i] and w[j]:
            s += a[i][j]
    if s != "":
        print(s)


Measured memory_bytes: 9428
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll a, b;
  cin >> a >> b;
  cout << a * b << endl;

  return 0;
}


Measured memory_bytes: 3652
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def f(C, D, F, r):
    import collections

    L = []
    for i, f0 in enumerate(F):
        for j, c in enumerate(f0):
            if (i + j) % 3 != r:
                continue
            L.append(c - 1)
    d = collections.Counter(L)
    res = []
    for x in range(C):
        tmp = 0
        for y, v in d.items():
            tmp += D[y][x] * v
        
        res.append((x, tmp))
    
    res.sort(key=lambda l: l[1])
    return res[:3]


def main():
    N, C = read_values()
    D = [read_list() for _ in range(C)]
    F = [read_list() for _ in range(N)]

    r0 = f(C, D, F, 0)
    r1 = f(C, D, F, 1)
    r2 = f(C, D, F, 2)
    res = 10 ** 18
    for c0, v0 in r0:
        for c1, v1 in r1:
            if c0 == c1:
                continue
            for c2, v2 in r2:
                if c2 in (c0, c1):
                    continue
                res = min(res, v0 + v1 + v2)
    
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  int top=0,s[100];
  char str[100];

  while((scanf("%s",str))!=EOF){
  	if(str[0]=='+'){
  		s[top-2]=s[top-2]+s[top-1];
  		top--;
  	}
  	else if(str[0]=='-'){
  		s[top-2]=s[top-2]-s[top-1];
  		top--;
  	}
  	else if(str[0]=='*'){
  		s[top-2]=s[top-2]*s[top-1];
  		top--;
  	}
  	else{
  		s[top]=atoi(str);
  		top++;
  	}
  }

	printf("%d\n",s[top-1]);
	
  return 0;
}




Measured memory_bytes: 2108
#include"bits/stdc++.h"
// #include "prettyprint.hpp"

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 reps(i, s, e) for(ll i=s; i<e; i++)
#define all(x) x.begin(),x.end()


int main(){
	int H;
	int A;

	cin >> H >> A;

	double ans = (double)H/A;

	cout << ceil(ans) << endl;

	return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.ByteString.Char8       as BS
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

quickSortList xs = ST.runST $ do
    arr <- V.thaw $ V.fromList xs
    let beg = 0
        end = VM.length arr - 1
    quickSortVec beg end arr
    V.toList <$> V.freeze arr

quickSortVec l u arr
  | l >= u    = return ()
  | otherwise = do
      VM.unsafeSwap arr l ((u+l)`div`2)
      t <- VM.unsafeRead arr l
      let i = l
          j = u + 1
      nj <- loopVec t u i j arr
      VM.unsafeSwap arr l nj
      quickSortVec l (nj-1) arr
      quickSortVec (nj+1) u arr

loopVec !t !u !i !j arr = do
  ni <- doWhile i (+1)         (< t)
  nj <- doWhile j (subtract 1) (> t)
  if ni > nj
    then return nj
    else do VM.unsafeSwap arr ni nj
            loopVec t u ni nj arr
              where
                {-# INLINE doWhile #-}
                doWhile k op p
                  | nk > u    = return nk
                  | otherwise = do
                      x <- VM.unsafeRead arr nk
                      if p x then
                        doWhile nk op p
                        else
                        return nk
                        where
                          nk = op k

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  xs <- replicateM n $ do
    [x, l] <- getIntList
    return (x + l, x - l)

  let inf = 10^10 :: Int

  print $ sched 0 (-inf) (quickSortList xs)
  where
    sched ans _ [] = ans
    sched ans r ((e, b):xs) | r <= b = sched (ans+1) e xs
                            | otherwise = sched ans r xs

Measured memory_bytes: 45052
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a;
     cin >> a;
     while(a>0){
         if(a%10==7){
             cout << "Yes\n";
             return 0;
         }else{
             a = a/10;
        }
     }
     cout << "No\n";
 return 0;}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 998244353;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

ll fastPow(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n % 2 == 0)
        return fastPow(x * x % MOD, n / 2);
    else
        return x * fastPow(x, n - 1) % MOD;
}

ll fac[312345];
void combInit(int mx)
{
    fac[0] = 0;
    fac[1] = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }
}

ll modDiv(ll a, ll b)
{
    return a * fastPow(b, MOD - 2) % MOD;
}

ll comb(ll a, ll b)
{
    if (a < b)
        return 0;
    if (a <= 0 || b < 0)
        return 0;
    if (a == b)
        return 1;

    ll p, c;

    c = modDiv(fac[a], fac[a - b]);
    p = fac[b];

    ll res = modDiv(c, p);

    return res;
}

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

    combInit(312345);

    ll n, a, b, k;
    vector<pair<ll, ll>> v;

    cin >> n >> a >> b >> k;

    if (k == 0)
    {
        cout << 1 << endl;
        return 0;
    }

    for (ll i = 1; i <= n; i++)
    {
        ll j = k - a * i;

        if (j < 0)
            break;

        if (j % b)
            continue;

        if (j / b > n)
            continue;

        v.push_back(make_pair(i, j / b));
    }

    ll res = 0;

    for (pair<ll, ll> p : v)
    {
        res += comb(n, p.first) * comb(n, p.second) % MOD;
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 7664
k,a,b=map(int,input().split())
if b-a>1:
    if k-a+1>0:
        bisk=a
        k-=a-1
    else:
        bisk+=k
        print(bisk)
        exit()
    bisk+=k//2*(b-a)
    bisk+=k%2
    print(bisk)
else:print(1+k)

Measured memory_bytes: 3060
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;



int main()
{
	vec n(3);

	cin >> n[0] >> n[1] >> n[2];

	for (int i = 0; i < 3; ++i)
	{
		int a = n[i];
		int b = n[(i+1)%3]; 
		int c = n[(i + 2) % 3];

		if (a == b && a != c)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string> 
#include <sstream>  
#include <vector> 
#include <time.h>
#include <algorithm>
using namespace std;

int main(){
    int a,b;
    for(int i = 1;i <= 7;i++){cin >> a >> b;cout << a - b << endl;}
} 

Measured memory_bytes: 1160
N = int(input())
A = list(map(int,input().split()))
P = []

S = sum(A)

snuke = 0
ans = 10 ** 12

for i in range(N - 1):
  snuke += A[i]
  dif = abs(S - (2 * snuke))
  
  if ans >= dif:
    ans = dif
    
print(ans)

Measured memory_bytes: 23948
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n) {
		par = vector<int>(n, -1);
	}
	int root(int x) {
		if (par[x] < 0) return x;
		else return root(par[x]);
	}
	int size(int x) {
		return -par[root(x)];
	}
	bool unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return false;
		if (size(rx) < size(ry)) swap(rx, ry);
		par[rx] += par[ry];
		par[ry] = rx;
		return true;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int count() {
		int res = 0;
		rep(i, par.size()) {
			if (par[i] < 0) res++;
		}
		return res;
	}
};
int main() {
	ll n, m;
	cin >> n >> m;
	vector<P<ll>> e(m);
	rep(i, m) {
		ll a, b;
		cin >> a >> b;
		a--, b--;
		e[i] = make_pair(a, b);
	}
	reverse(all(e));
	VL ans(m);
	ll now = n * (n - 1) / 2;
	UnionFind G(n);
	rep(i, m) {
		ans[i] = now;
		ll a = e[i].first, b = e[i].second;
		ll sa = G.size(a), sb = G.size(b);
		ll plus = sa * sb;
		if (G.unite(a, b)) now -= plus;
	}
	reverse(all(ans));
	rep(i, m) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int n;
int a[N];
hash_map<int, int> M;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		M[a[i]] = i;
	}
	sort(a, a + n);
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (!(i & 1) && (M[a[i]] & 1))
			res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6072
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int K = cin.nextInt();
        long ans = 1;
        for (int i = 0; i < N; i++)
        {
            if (i == 0) ans *= K;
            else ans *= K - 1;
        }
        Console.WriteLine(ans);
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}




Measured memory_bytes: 13140
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt64

func maxInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func minInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	a := nextInt()
	v := nextInt()
	b := nextInt()
	w := nextInt()
	T := nextInt()
	dis := absInt(b - a)
	if a == b {
		fmt.Println("YES")
	}
	speed := v - w
	if speed*T >= dis {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int A, B, K;
  cin >> A >> B >> K;
  if(A < K){
    printf("0");
    printf(" ");
    if(A+B-K >= 0){
      printf("%ld", A+B-K);
    }
    else{
      printf("0");
    }
  }
  else{
    printf("%ld", A-K);
    printf(" ");
    printf("%ld", B);
  }
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;
bool check(ll x)
{
    str s = to_string(x);
    str d = s;
    reverse(d.begin() , d.end());
    if(d == s) return 1;
    return 0;
}
int main()
{_
    ll a , b , res = 0; cin >> a >> b;
    for(ll i = a ; i <= b ; i++)
        if(check(i))res++;
	return cout << res , 0;
}
///SAliB


Measured memory_bytes: 256
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

int64_t top, S[1000];

void push(int64_t x) {
    top++;
    S[top] = x;
}

int64_t pop() {
    top--;
    return S[top + 1];
}

void solve() {
    int64_t a, b;
    top = 0;
    char s[100];

    while (scanf("%s", s) != EOF) {
        if (s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if (s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        } else if (s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(std::atoll(s));
        }
    }

    std::cout << pop() << std::endl;

    return;
}

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}



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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);

    char s[123222];
    Scs(s);

    vi ev;
    char prev = s[0];
    int streak = 0;
    Rep(i,N){
        // printf ("[%lld]%d\n", i, K);
        if( prev != s[i] ){
            if( !streak ) K--;
            streak++;
            s[i] = prev;
        }else{
            streak = 0;
            if( K == 0 ) break;
        }
    }

    int ans = 0;
    streak = 0;
    prev = s[0];
    Rep(i,N){
        if( prev == s[i] ){
            streak++;
        }else{
            ans += streak-1;
            streak = 1;
        }
        prev = s[i];
    }
    ans += streak-1;

    // printf ("%s\n", s );
    printf ("%d\n", ans );

    return 0;
}





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

int main() 
{
	int c[4][4];

	for (int i = 1; i <= 3; i++)
	{
		for (int j = 1; j <= 3; j++)
		{
			cin >> c[i][j];
		}
	}

	int a = 0;
	for (int i = 1; i <= 2; i++)
	{
		if ((c[i][1] - c[i + 1][1] != c[i][2] - c[i + 1][2]) || (c[i][2] - c[i + 1][2] != c[i][3] - c[i + 1][3]))
		{
			a++;
		}
	}
	if ((c[1][1] - c[3][1] != c[1][2] - c[3][2]) || (c[1][2] - c[3][2] != c[1][3] - c[3][3]))
	{
		a++;
	}
	for (int i = 1; i <= 2; i++)
	{
		if ((c[1][i] - c[1][i + 1] != c[2][i] - c[2][i + 1]) || (c[2][i] - c[2][i + 1] != c[3][i] - c[3][i + 1]))
		{
			a++;
		}
	}
	if ((c[1][1] - c[1][3] != c[2][1] - c[2][3]) || (c[2][1] - c[2][3] != c[3][1] - c[3][3]))
	{
		a++;
	}

	if (a > 0)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
//Confuse them with your silence and shock them with your results;
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define int long long 

const int mod=1e9+7;
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}


int rr[]={0,1,1,1,0,-1,-1,-1};
int cc[]={1,1,0,-1,-1,-1,0,1};


signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    booster;
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin >> n;
        int a[n], b[n], c[n-1];
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for(int i = 0; i < n; i++) {
            cin >> b[i];
        }
        int ans = 0;
        for(int i = 0; i < n - 1; i++) {
            cin >> c[i];
        }
        for(int i = 0; i < n; i++) {
            ans += b[a[i] - 1];
            if(i && a[i] == a[i - 1] + 1)
                ans += c[a[i - 1] - 1];
        }
        cout << ans; 

    }
    rtime();
    return 0;
}

Measured memory_bytes: 384
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

class union_find:
  def __init__(self, n):
    self.par = [-1] * n
  def __repr__(self):
    return "union_find({0})".format(self.par)
  def unite(self, x, y):
    if self.root(x) != self.root(y):
      self.par[self.root(x)] = y
  def root(self, x):
    if self.par[x] == -1:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  def same(self, x, y):
    return self.root(x) == self.root(y)
  
N, M = reads()
p = reads()

uf = union_find(N)
for _ in range(M):
  x, y = reads()
  uf.unite(x-1, y-1)

d = defaultdict(set)
for i in range(N):
  d[uf.root(i)].add(i)
print(d, file=stderr)

ans = 0
for grp in d.values():
  ans += len(grp & {p[i]-1 for i in grp})
print(ans)

Measured memory_bytes: 141728
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  ll N, M;
  cin >> N >> M;
  if(N == 1 && M == 1)
    cout << 1 << endl;
  else if(N == 1 || M == 1)
    cout << N * M - 2 << endl;
  else
    cout << N * M - (2 * (N + M) - 4) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

ll gcd(ll a, ll b) {
    if (a<b) swap(a, b);
    while(b!=0) {
        ll t = a;
        a = b;
        b = t%b;
    }
    return a;
}

ll lcm(ll a, ll b) { return a/gcd(a, b)*b; }

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

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

    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    int cnt = 0;
    int tmp = a[0]; while(tmp%2==0) { tmp/=2; ++cnt; }
    rep(i, n) {
        tmp = a[i]; int tmpcnt = 0;
        while(tmp%2==0) { tmp/=2; ++tmpcnt; }
        if  (tmpcnt!=cnt) { cout << 0 << endl; return 0; }
    }

    ll l = 1;
    rep(i, n) l = lcm(l, a[i]/2);
    cout << m/l - m/l/2 << endl;

    
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;
import java.io.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        
        int[][] A = new int[N][N-1];
        
        //試合の頂点
        Match[][] vs = new Match[N][N];
        
        //試合の頂点の入次元数 (i < j)
        int[][] dim = new int[N][N];
        
        for(int i = 0; i < N; i++){
            String[] stdR = br.readLine().split(" ");
            A[i] = Stream.of(stdR).mapToInt(Integer::parseInt).map(num -> num - 1).toArray();
        }
        
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j < N; j++){
                vs[i][j] = vs[j][i] = new Match(i, j);
            }
        }
        
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N - 2; j++){
                vs[i][A[i][j]].add(vs[i][A[i][j+1]]);
                if( i < A[i][j+1] ) {
                    dim[i][A[i][j+1]]++;
                } else {
                    dim[A[i][j+1]][i]++;
                }
            }
        }
        
        Queue<Match> que = new LinkedList<>();
        
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j < N; j++){
                
                if ( dim[i][j] != 0 ) continue;
                
                que.offer(vs[i][j]);
                vs[i][j].depth = 1;
                
            }
        }
        
        int cnt = 0;
        
        while(!que.isEmpty()){
            
            Match m = que.poll();
            cnt++;
            
            for( Match w : m ) {
                dim[w.p][w.q]--;
                w.depth = Math.max(w.depth, m.depth + 1);
                
                if(dim[w.p][w.q] == 0){
                    que.offer(w);
                }
            }
        }
        
		if (cnt != N * (N - 1) / 2) {
			System.out.println(-1);
			return;
		}
		int diam = 0;
		for (int i = 0; i < N-1; i++) {
			for (int j = i + 1; j < N; j++) {
				diam = Math.max(diam, vs[i][j].depth);
			}
		}
		System.out.println(diam);
        
    }
    
    static class Match extends ArrayList<Match> {
        int p;
        int q;
        int depth = 0;
        
        public Match (int _p, int _q){
            p = _p;
            q = _q;
        }
    }
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 2e5+5;
int pre[maxn], pst[maxn];
VI G[maxn];
int tree[4*maxn];

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    string s,t;
    while (cin >> s >> t) {
        const int n = s.size();
        const int m = t.size();
        set<char> A; map<char,VI> pos;
        FOR(i,0,n) {
            const char c = s[i];
            A.insert(c);
            pos[c].push_back(i);
        }
        bool good = true;
        FOR(i,0,m)
            good &= in_(t[i],A);
        if (!good) 
            cout << -1 << endl;
        else {
            int i = 0, j = 0; LL ans = 0;
            while (j < m) {
                const VI& p = pos[t[j]];
                auto x = lower_bound(ALL(p),i);
                if (x == p.end()) {
                    ans += n-i; i = 0;
                }
                else {
                    j++; ans += *x-i+1; i = *x+1;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n;
        cin >> n;

        vector<pair<long, long>> a(n);
        vector<vector<long>> d(150);
        for (auto &v : d) {
            v.resize(150);
        }
        for (auto &p : a) {
            double y;
            cin >> y;

            long ten = 0;
            long pot = 10;
            double z = y;
            while (ten < 10) {
                z = y * pot;
                pot *= 10;
                ten++;
            }
            long two = ten;
            long five = ten;
            long x = round(z);
            while (x % 2 == 0) {
                two--;
                x /= 2;
            }
            while (x % 5 == 0) {
                five--;
                x /= 5;
            }
            p.first = -two;
            p.second = -five;
            // two = max(-two, 0LL);
            // five = max(-five, 0LL);
            d[-two + 70][-five + 70]++;
        }
        long ans = 0;
        for (long two = -20; two <= 30; two++) {
            for (long five = -20; five <= 30; five++) {
                if (d[two + 70][five + 70] == 0) continue;
                long count = d[two + 70][five + 70];
                long total = 0;
                for (long i = -two; i <= 60; i++) {
                    for (long j = -five; j <= 60; j++) {
                        long c = d[i + 70][j + 70];
                        total += c;
                    }
                }
                total *= count;
                if (two >= 0 and five >= 0) total -= count;
                ans += total;
            }
        }
        ans /= 2;
        printf("%lld\n", ans);
    }
}


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

int Dice[6];

void shake(char c) {
  if (c == 'E') {
    swap(Dice[0], Dice[3]);
    swap(Dice[3], Dice[5]);
    swap(Dice[5], Dice[2]);
  }
  if (c == 'N') {
    swap(Dice[0], Dice[1]);
    swap(Dice[1], Dice[5]);
    swap(Dice[5], Dice[4]);
  }
  if (c == 'S') {
    swap(Dice[1], Dice[0]);
    swap(Dice[0], Dice[4]);
    swap(Dice[4], Dice[5]);
  }
  if (c == 'W') {
    swap(Dice[3], Dice[0]);
    swap(Dice[0], Dice[2]);
    swap(Dice[2], Dice[5]);
  }
}

int main() {
  int i;
  char c;
  for (i = 0; i < 6; i++) {
    cin >> Dice[i];
  }
  while (cin >> c)
    shake(c);

  cout << Dice[0] << endl;
  return 0;
}

Measured memory_bytes: 3116