akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD      = 1000000007;
const int MOD_INV2 = 500000004;
const int MAX      = 2000;

void combination(int n, vector<vector<int> >& comb)
{
    comb.assign(n+1, vector<int>(n+1, 0));
    for(int i=0; i<=n; ++i){
        comb[i][0] = 1;
        for(int j=1; j<=i; ++j){
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
            comb[i][j] %= MOD;
        }
    }
}

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

    long long ans = 0;
    vector<int> dp(2*MAX+2, 0);
    for(int y=0; y<=2*MAX; ++y){
        vector<int> nextDp(2*MAX+2, 0);
        for(int x=0; x<=2*MAX; ++x){
            if(y < MAX && x < MAX){
                dp[x] += cnt[MAX-y][MAX-x];
                dp[x] %= MOD;
            }
            else if(y > MAX && x > MAX){
                ans += dp[x] * (long long)cnt[y-MAX][x-MAX];
                ans %= MOD;
            }

            nextDp[x] += dp[x];
            nextDp[x] %= MOD;
            dp[x+1] += dp[x];
            dp[x+1] %= MOD;
        }
    }
    cnt.clear();

    vector<vector<int> > comb;
    combination(4*MAX, comb);
    for(int i=0; i<n; ++i){
        ans += MOD - comb[2*(a[i]+b[i])][2*a[i]];
        ans %= MOD;
    }
    ans *= MOD_INV2;
    ans %= MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 252288
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let m: usize = read();
    let x: u64 = read();
    
    let mut c: Vec<u64> = Vec::with_capacity(n);
    let mut a: Vec<Vec<u64>> = Vec::with_capacity(n);

    for _ in 0..n {
        c.push(read());
        a.push((0..m).map(|_| read()).collect());
    }
    let mut bits: Vec<bool> = (0..n).map(|_| false).collect();

    let ans = dfs(&mut bits, 0, &a, &c, x);
    if ans == std::u64::MAX {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

fn dfs(bits: &mut Vec<bool>, depth: usize, a: &Vec<Vec<u64>>, c: &Vec<u64>, x: u64) -> u64 {
    if depth == c.len() {
        let mut ret: Vec<u64> = (0..a[0].len()).map(|_| 0).collect();
        for i in 0..c.len() {
            if bits[i] {
                for j in 0..a[0].len() {
                    ret[j] += a[i][j];
                }
            }
        }

        for i in &ret {
            if *i < x {
                return std::u64::MAX;
            }
        }
        let mut ans = 0;
        for i in 0..c.len() {
            if bits[i] {
                ans += c[i];
            }
        }
        return ans;
    }

    bits[depth] = true;
    let b = dfs(bits, depth + 1, &a, &c, x);
    bits[depth] = false;
    let c = dfs(bits, depth + 1, &a, &c, x);
    std::cmp::min(b, c)
}


Measured memory_bytes: 2160
#include <stdio.h>

int main() {
    char a[110], b[110], c[110];
    int i, n, count=0;

    scanf("%d%s%s%s", &n, a, b, c);

    for (i=0; i < n; i++) {
        if (a[i] == b[i] && b[i] == c[i] && c[i] == a[i]) continue;
        else if (a[i] == b[i] && b[i] == c[i] && c[i] != a[i]) count++;
        else if (a[i] == b[i] && b[i] != c[i] && c[i] == a[i]) count++;
        else if (a[i] != b[i] && b[i] == c[i] && c[i] == a[i]) count++;
        else if (a[i] == b[i] && b[i] != c[i] && c[i] != a[i]) count++;
        else if (a[i] != b[i] && b[i] == c[i] && c[i] != a[i]) count++;
        else if (a[i] != b[i] && b[i] != c[i] && c[i] == a[i]) count++;
        else if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) count+=2;
    }
    
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG // 配列エラー
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
// typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

// 各操作を行う関数を実装する

// AとBに共通して含まれる要素からなる集合を返す
bitset<50> intersection(bitset<50> A, bitset<50> B) {
  return A & B;
}
// AとBのうち少なくとも一方に含まれる要素からなる集合を返す
bitset<50> union_set(bitset<50> A, bitset<50> B) {
  return A | B;
}
// AとBのうちどちらか一方にだけ含まれる要素からなる集合を返す
bitset<50> symmetric_diff(bitset<50> A, bitset<50> B) {
  return A ^ B;
}
// Aから値xを除く
bitset<50> subtract(bitset<50> A, int x) {
  A.set(x, 0);
  return A;
}
// Aに含まれる要素に1を加える(ただし、要素49が含まれる場合は0になるものとする)
bitset<50> increment(bitset<50> A) {
  bitset<50> ANS = A << 1;
  if(A.test(49)) { // 指定した桁のビット値が1ならtrue
    ANS.set(0,1);
  }
  return ANS;
}
// Aに含まれる要素から1を引く(ただし、要素0が含まれる場合は49になるものとする)
bitset<50> decrement(bitset<50> A) {
  bitset<50> ANS = A >> 1; // >> は右シフトしたbitsetを生成して返す
  if(A.test(0)) { // 指定した桁のビット値が1ならtrue
    ANS.set(49,1);
  }
  return ANS;
}

// Sに値xを加える
bitset<50> add(bitset<50> S, int x) {
  S.set(x, 1);  // xビット目を1にする
  return S;
}

// 集合Sの内容を昇順で出力する(スペース区切りで各要素の値を出力する)
void print_set(bitset<50> S) {
  vector<int> cont;
  for (int i = 0; i < 50; i++) {
    if (S.test(i)) {
      cont.push_back(i);
    }
  }
  for (int i = 0; i < (int)cont.size(); i++) {
    if (i > 0) cout << " ";
    cout << cont.at(i);
  }
  cout << endl;
}


int main() {
  int64_t num;
  cin >> num;

  string S = to_string(num);

  vector<int64_t> s;
  int len = S.size()-1; // 10 - 1 = 9
  s.push_back( num );
  for (int i = 1; i < (1 << (len)); i++) {
    bitset<9> bit(i);
    int start = 0;
    for(int j = 0; j < len; j++) { // 0 ~ 9

      // cout << j << ":" << bit.test(j) << ": ";
      if(bit.test(j)) {
        s.push_back( stoi( S.substr(start, j - start + 1) ) );
        // cout << start << "=>" << j - start + 1 << ":" << stoi( S.substr(start, j - start + 1) );
        start = j + 1;
      }
      if(j == len-1) {
        s.push_back( stoi( S.substr(start) ) );
        // cout << endl << ": ";
        // cout << start << "=>" << len << ":" << stoi( S.substr(start) );
      }

      // cout << endl;
    }
    // cout << endl;
  }

  auto sum = accumulate(s.begin(), s.end(), 0LL);

  // cout << endl;
  cout << sum << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		double ans = (double)a / (double)b;
		System.out.print(a / b + " ");
		System.out.print(a % b + " ");
		System.out.printf("%.5f", ans);
	}
}

Measured memory_bytes: 26528
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define loopinc(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define loop(i, a, b) for(int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define lloopinc(i, a, b, inc) for(ll i = a; i < (b); i += inc)
#define lloop(i, a, b) for(ll i = a; i < (b); i++)
#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

pii fn(pii a, pii b) {
	if (b.first > a.first) return {b.first, max(b.second, a.first)};
	else return {a.first, max(a.second, b.first)};
}
int sm(pii a) { return a.first + a.second; }

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<pii> arr(1<<n);
	rep(i, 1<<n) {
		int x; cin >> x;
		arr[i] = {x, INT_MIN};
	}
	rep(l, n) rep(i, 1<<n) if (i & 1<<l)
		arr[i] = fn(arr[i], arr[i ^ 1<<l]);

	int res = INT_MIN;
	loop(k, 1, 1<<n) {
		cout << (res = max(res, sm(arr[k]))) << endl;
	}
}


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

int main() {
	int A, B, C, D, S, E, time;
	cin >> A >> B >> C >> D;
	S = max(A, C);
	E = min(B, D);
	time = E - S;
	if (time < 0) cout << 0;
	else cout << time;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long ans = 0;

	long long n;

	std::cin >> n;

	long long pre = 0;
	for (long long i = 0; i < n - 1; i++)
	{
		long long val = 0;
		std::cin >> val;

		if (i == 0) {
			ans += val;
		}
		else {
			ans += std::min(pre, val);
		}
		pre = val;
	}

	ans += pre;
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
PNs = [list(map(int,input().split())) for _ in range(N)]
#price_and_number_of_drinks

PNs.sort(key=lambda x: x[0])

ans = 0
sum_drinks = 0 #sum of drinks which Takahashi has bought
for i in range(N):
    nos = PNs[i][1] #number of drinks at i_th shop
    ans += nos*PNs[i][0] #add money he spent at the shop
    sum_drinks += nos
    if sum_drinks>=M:
        ans -= (sum_drinks-M)*PNs[i][0]
        break

print(ans)

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

namespace Eye_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int al, ar, bl, br, cl, cr, dl, dr;
            al = ar = bl = br = cl = cr = dl = dr = 0;

            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) break;
                string[] temp = input.Split(' ');
                double l = double.Parse(temp[0]);
                double r = double.Parse(temp[1]);
                if (l >= 1.1) al++;
                else if (l >= 0.6) bl++;
                else if (l >= 0.2) cl++;
                else dl++;
                if (r >= 1.1) ar++;
                else if (r >= 0.6) br++;
                else if (r >= 0.2) cr++;
                else dr++;
            }
            Console.WriteLine(al + " " + ar);
            Console.WriteLine(bl + " " + br);
            Console.WriteLine(cl + " " + cr);
            Console.WriteLine(dl + " " + dr);

        }
    }
}



Measured memory_bytes: 15916
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 998244353
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (ll)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()

using namespace std;

vector<vector<int> > val,a;

int n;

int dp(int i,int p)
{
    if(i==n)
        return 0;
    if(val[i][p]!=-1)
        return val[i][p];
    for(int j=0;j<3;j++)
    {
        if(j!=p)
            val[i][p]=max(val[i][p],a[i][j]+dp(i+1,j));
    }
    return val[i][p];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    a.resize(n,vector<int> (3));
    f(i,0,n)
    {
        vector<int> v(4,-1);
        val.pb(v);
    }
    f(i,0,n)
    {
        f(j,0,3)
            cin>>a[i][j];
    }
    cout<<dp(0,3);
}

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

bool isA(const string &s) {
  if(s.size() < 6) return false;
  if(s.substr(0,2) != ">'") return false;
  if(*(s.rbegin()) != '~') return false;
  string t = s.substr(2, (int)s.size()-3);
  int m = t.find("#");
  if(m == string::npos) return false;
  if(t.substr(0,m) != string(m, '=')) return false;
  if(t.substr(m+1) != string(m, '=')) return false;
  return true;
}

bool isB(const string &s) {
  if(s.size() < 6) return false;
  if(s.substr(0,2) != ">^") return false;
  if(s.substr((int)s.size()-2) != "~~") return false;
  string t = s.substr(2, (int)s.size()-4);
  if(t.size()&1) return false;
  for(int i = 0; i < t.size(); i += 2) {
    if(t[i] != 'Q' || t[i+1] != '=') return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    if(isA(s)) cout << "A" << endl;
    else if(isB(s)) cout << "B" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
	LLI a, b, k;
	cin >> a >> b >> k;
	if( 2*k > b - a )
		for(int i = a; i <= b; i++)
			cout << i << "\n";
	else{
		for(int i = a; i < a+k; i++)
			cout << i << "\n";
		for(int i = b-k+1; i <= b; i++)
			cout << i << "\n";
	}
}

Measured memory_bytes: 3616
n = int(input())
p_list = list(map(int,input().split()))

ans = 0

for i in range(n - 2):
    li = [p_list[i], p_list[i + 1], p_list[i + 2]]
    li.sort()
    if li[1] == p_list[i + 1]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int h, w;
    cin >> h >> w;

    bool possible = true;
    int mn = 0, mx = 0;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = w-1; j >= 0; j--) if (s[j] == '#') mn = j;
        if (mx != mn) possible = false;
        for (int j = mn; j < w; j++) if (s[j] == '#') mx = j;
    }

    cout << (possible ? "Possible" : "Impossible") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int h=0;
  int64_t s=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    h=max(h,a);
    s+=h-a;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;

using namespace std;

const int N = 3010, mod = 1e9 + 7, inf = 1e18 + 7, logn = 23;
const double pi = acos(-1);

double p[N], dp[N][N];

void solve() {
	//soln
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> p[i];
	}

	dp[0][0] = 1;

	for(int i = 1; i <= n; i++) {
		double head = p[i], tail = 1 - p[i];
		dp[i][0] = dp[i - 1][0] * tail;
		for(int j = 1; j <= i; j++) {
			dp[i][j] = head * dp[i - 1][j - 1] + tail * dp[i - 1][j]; 			
		}
	}

	double ans = 0;
	for(int i = n / 2 + 1; i <= n; i++) {
		ans += dp[n][i];
	}
	cout << fixed;
	cout.precision(10);
	cout << ans << endl;
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


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

#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long INF = 1e9;
const long long mod = 1e9 + 7;

int n;
int m;
int cnt;
int main()
{
    /// freopen("sum.in", "r", stdin);
    /// freopen("sum.out", "w", stdout);

    ios_base::sync_with_stdio( 0 );

    cin >> n >> m;
    cout << ceil(( float )n / ( ( m * 2 ) + 1 ));
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i32>();
    let mut  v = read_vec::<i32>();
    v.sort();
    let ans = (v[0] - v.last().unwrap()).abs();
    println!("{}",ans);
}

Measured memory_bytes: 4352
h,w,d=(int(i) for i in input().split())
num=[None for i in range(h*w)]
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        num[a[j]-1]=(i,j)
numm=[None for i in range(h*w)]
for i in range(d):
    numm[i]=0
for i in range(d,h*w):
    numm[i]=numm[i-d]+abs(num[i][0]-num[i-d][0])+abs(num[i][1]-num[i-d][1])

q=int(input())
for i in range(q):
    l,r=list(map(int,input().split()))
    print(numm[r-1]-numm[l-1])

Measured memory_bytes: 16084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 200001;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    sort(all(a));
    com_init();
    int nn = n - 1, kk = k - 1;
    int ans = 0;
    rep (i, n) {
        eprintf("%d %d\n", (nn - i >= kk ? com_mod(nn - i, kk) : 0), (i >= kk ? com_mod(i, kk) : 0));
        if (nn - i >= kk) ans = mod(ans - mul_mod(a[i], com_mod(nn - i, kk)));
        if (i >= kk) ans = mod(ans + mul_mod(a[i], com_mod(i, kk)));
    }
    cout << ans << "\n";
    return 0;
}

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

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

	
	if (a*b % 2 != 0) {
		cout << "Odd" << endl;
	}
	else {
		cout << "Even" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            int N;
            int Q;
            {
                var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
                N = items[0];
                Q = items[1];
            }

            var S = Console.ReadLine();
            var list = new List<int>();
            int countt = 0;
            for (int index = 0; index < S.Length; index++)
            {
                if (index > 0)
                {
                    if (S[index - 1] == 'A' && S[index] == 'C')
                    {
                        countt++;
                    }
                }

                list.Add(countt);
            }

            List<int> answers = new List<int>();
            for (int i = 0; i < Q; i++)
            {
                int l;
                int r;
                {
                    var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
                    l = items[0];
                    r = items[1];
                }
                int index = l - 1;
                int lastIndex = r - 1;
                int count = list[lastIndex] - list[index];
                Console.WriteLine(count);
            }
        }
    }
}


Measured memory_bytes: 19260
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    dic = {}
    for i in range(n):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1

    def comb(n,r,p = mod):
        r = min(r,n-r) # nCr
        res = 1
        div = 1 # nCr := n*n-1*...n-r+1 // 1*2*3...r
        for i in range(n-r+1,n+1):
            res *= i
            res %= p
        for i in range(1,r+1):
            div *= i
            div %= p
        res *= pow(div,p-2,p) # 掛け算に
        res %= p
        return res
    ans = 0
    for k,v in dic.items():
        ans += v * (v-1) // 2
    print(ans)

if __name__ == '__main__':
  main()


Measured memory_bytes: 61272
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL)
#define cases ll t; cin>>t; while(t--)
#define rep1(qq,pp) for(ll i=qq;i<pp;i++)
#define rep2(qqq,ppp) for(ll i=qqq;i>=ppp;i--)
#define nl "\n"
#define Y cout<<"Yes\n"
#define N cout<<"No\n"
//cout<<fixed<<setprecision(13);

int main(){
	faster;

	int d,x,s;
	dl ans;

    cin>>d>>x>>s;
    
    ans=(dl)d/(dl)s;
    
    if(ans<=x) Y;
    else N;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int P,Q,R;
    cin>>P>>Q>>R;
    cout<<P+Q+R-max(max(P,Q),R)<<endl;
}


Measured memory_bytes: 256
# 2019-11-16 21:01:15(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
import operator as op
# from scipy.misc import comb # float
# import numpy as np 


mod = 10 ** 9 + 7

def comb(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


def main():
    x, y = [int(x) for x in sys.stdin.readline().split()]
    # n(+1, +2), m(+2, +1)
    n, m = (2 * y - x) / 3, (2 * x - y) / 3

    if n != abs(int(n)) or m != abs(int(m)):
        print(0)
        sys.exit()
    else:
        n, m = int(n), int(m)
        ans = comb(n+m, n) % mod
        print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 46204
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"

int main()
{
	int n, i, v[30], c[30], ans = 0;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> v[i];
	}
	for (i = 1; i <= n; i++)
	{
		cin >> c[i];
	}
	for (i = 1; i <= n; i++)
	{
		if (v[i] > c[i]) ans += v[i] - c[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int M[N][N] = {0}, d[N], n;

void bfs() {
  int u, v;
  queue<int> q;
  for (u = 0; u < n; u++) {
    d[u] = INFTY;
  }
  d[0] = 0;
  q.push(0);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (v = 0; v < n; v++) {
      if (M[u][v] == 0) continue;
      if (d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for (u = 0; u < n; u++) {
    cout << u + 1 << ' ' << ((d[u] == INFTY) ? (-1) : d[u]) << endl;
  }
}

int main() {
  int u, v, k, i, j;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs();

  return 0;
}

Measured memory_bytes: 3128
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), k = scan.nextInt();
        int last = 1 + (k-1)*2;
        System.out.println(last > n ? "NO" : "YES");
    }
}


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

int n;

typedef struct{
    char name[256];
    int cost;
    char used[100][256];
    int size;
} ITEM;

ITEM list[100];

int getCost(int vertex)
{
    int i, j;
    int ans;
    
    if (list[vertex].size == 0){
        return (list[vertex].cost);
    }
    else {
        ans = 0;
        for (i = 0; i < list[vertex].size; i++){
            for (j = 0; j < n; j++){
                if (strcmp(list[vertex].used[i], list[j].name) == 0){
                    ans += getCost(j);
                }
            }
        }
        list[vertex].cost = list[vertex].cost > ans ? ans : list[vertex].cost;
    }
    return (list[vertex].cost);
}

int main(void)
{
    int i, j, k;
    int m, kk;
    char key[256], temp[256];
    int look, sum;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%s%d", list[i].name, &list[i].cost);
            list[i].size = 0;
        }
        
        scanf("%d", &m);
        for (i = 0; i < m; i++){
            scanf("%s", key);
            for (j = 0; j < n; j++){
                if (strcmp(key, list[j].name) == 0){
                    look = j;
                }
            }
            scanf("%d", &kk);
            list[look].size = kk;
            for (j = 0; j < kk; j++){
                scanf("%s", temp);
                for (k = 0; k < n; k++){
                    if (strcmp(temp, list[k].name) == 0){
                        strcpy(list[look].used[j], temp);
                    }
                }
            }
        }
        scanf("%s", key);
        for (j = 0; j < n; j++){
            if (strcmp(key, list[j].name) == 0){
                look = j;
            }
        }
        
        printf("%d\n", getCost(look));
        
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define max(a, b) (a)>(b)?(a):(b)
int main(){
    int i, j;
    int n;
    double a[2][100];
    double reg[4]={0};
    scanf("%d", &n);
    for(i=0; i<2; i++)for(j=0; j<n; j++)scanf("%lf", &a[i][j]);
    for(i=0; i<n; i++){
        a[0][i]=abs(a[0][i]-a[1][i]);
        reg[0]+=a[0][i];//
        reg[1]+=a[0][i]*a[0][i];
        reg[2]+=a[0][i]*a[0][i]*a[0][i];
        reg[3]=max(reg[3], a[0][i]);//
    }
    reg[1]=sqrt(reg[1]);
    reg[2]=pow(reg[2], 1.0/3.0);
    for(i=0; i<4; i++)printf("%f\n",reg[i]);
    return 0;
}

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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

int n;
ll a[100];

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  REP(i,n)cin >> a[i];

  ll tmp = 1000;
  ll st = 0;
  bool flag = false;
  int last = 0;
  REP(i,n){
    if(!flag){
      last = i;
      flag = 1;
    }else{
      if(a[i] > a[last]){
        st = (tmp / a[last]);
        tmp -= st * a[last];
        tmp += st* a[i];
        st = 0;
        last = i;
      }else if(a[i] < a[last]){
        last = i;
      }
    }
  }

  cout << tmp << '\n';
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int k, x;

    cin >> k >> x;

    for (int i = x-k+1; i <= x+k-1; i++) {
        if (i != x-k+1) cout << " ";
        cout << i;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long y = sc.nextLong();
    if(x%y==0){
      System.out.println(-1);
    }else{
      System.out.println(x);
    }
  }
}


Measured memory_bytes: 35828
#include <stdio.h>

int main()
{
long long int a,b,c,d;

scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

long long int ans_a,ans_b;

a--;
long long int i;

if(c>d)
{
    i =c;
    c = d;
    d = i;
}

long long int x=c,y=d,z;

z = y % x;
    while(z!= 0)
    {
        y = x;
        x = z;
        z = y%x;
    }

    i = c*d;
    i = i/x;
ans_a =  a - a/c - a/d + a/i;

 

ans_b =  b - b/c - b/d + b/i;

printf("%lld\n",ans_b-ans_a);


    return 0;
}

Measured memory_bytes: 128
def makePrimeChecker(n):
    isPrime = [True] * (n + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if isPrime[i]:
            for j in range(i * i, n + 1, i):
                isPrime[j] = False
    return isPrime

def main():
    N = int(input())
    ls = makePrimeChecker(10**6)
    for i in range(N,10**6+1):
        if ls[i]:
            print(i)
            exit()
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 46320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    if (a > b) cout << '>';
    else if (a < b) cout << '<';
    else cout << '=';
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 1234567890123456789;
const ll mod = 998244353;
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())

vi important(int depth){
    if(depth == 0) return vi{0};
    int tw = depth;
    for(int i = 0;; i++){
        if(!(tw&~(1<<i))) break;
        tw = tw&~(1<<i);
    }
    vi x = important(depth^tw);
    vi r;
    for(int i = 0; i < sz(x); i++){
        r.push_back(x[i]-tw);
    }
    for(int i = 0; i < sz(x); i++){
        r.push_back(x[i]+tw);
    }
    return r;
}

vi step(vi a){
    vi b;
    for(int i = 1; i < sz(a); i++){
        b.push_back(abs(a[i]-a[i-1]));
    }
    return b;
}

int solve2(vi a){
    while(sz(a) > 1) a = step(a);
    return a[0];
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vi a(n);
    for(int i = 0; i < n; i++) a[i] = s[i]-'1';
    //cout << solve2(a) << endl;
    if(sz(a)%2 == 0) a = step(a);
    int o2 = 1;
    for(int i = 0; i < sz(a); i++) if(a[i] == 1) o2 = 0;
    if(o2){
        for(int i = 0; i < sz(a); i++) if(a[i] == 2) a[i] = 1;
    }
    vi x = important(sz(a)-1);
    for(int i = 0; i < sz(x); i++){
        assert(x[i]%2 == 0);
        x[i] /= 2;
        x[i] += sz(a)/2;
    }
    int oc = 0;
    for(int i = 0; i < sz(x); i++) if(a[x[i]] == 1) oc++;
    if(oc%2){
        cout << 1+o2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

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

int main() {
  ll n; cin >> n;
  vector<ll> A(n+1),B(n);
  rep(i,n+1) cin >> A[i];
  rep(i,n) cin >> B[i];
  
  ll ans = min(A[0], B[0]);
  B[0] = max(B[0]-A[0], (ll)0);
  
  for(ll i=1; i<n; i++){
    ans += min(A[i], B[i-1]);
    A[i] = max(A[i] - B[i-1], (ll)0);
    ans += min(A[i], B[i]);
    B[i] = max(B[i]-A[i], (ll)0);
  }
  ans += min(A[n], B[n-1]);
  
  cout << ans << endl;
}

Measured memory_bytes: 4828
from sys import stdin
R, G, B, N = (int(i) for i in input().split())

count = 0
for i in range(N+1):
    for j in range(N+1):
        b = (N-i*R-j*G)/B
        if b.is_integer() and b >= 0:
            count +=1

print(count)


Measured memory_bytes: 41068
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

#define loop(i,first,end) for(int i=(first);i<(end);i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ull>
#define vll vector<ll>
#define init(type,var) type var;cin>>var;
#define vinit(vtype,var,n) vtype var(n);loop(i,0,n)cin>>var[i];

const ull MOD = 1000000007ULL;
const ull INF = (ull)(-1LL);

int main(void){
	init(int, a);
	init(int, b);

	int p = a + b;
	int m = a - b;
	int x = a * b;

	cout << max(p, max(m, x)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long bit[62][2];
signed main(){
    long long n , a , biggest=0 , k=0 , p=1 , ans=0 , inf=1000000007;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a; 
        biggest=max(biggest,a);
        for(int j=0;j<=61;j++){
            bit[j][a%2]++;
            a/=2;
        }
    }
    
    while(biggest>0){
        biggest/=2;
        ans+=(((bit[k][0]*bit[k][1])%inf)*p)%inf;
        ans%=inf;
        k++;
        p=(p*2)%inf;
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  if (a >= b and a >= c) {
    cout << a * 10 + b + c << endl;
    return 0;
  }
  if (b >= a and b >= c) {
    cout << b * 10 + a + c << endl;
    return 0;
  }
  if (c >= a and c >= b) {
    cout << c * 10 + a + b << endl;
    return 0;
  }
}


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

int main(){
  char weather[10] = "\0";
  char *weather_kind[] = {"Sunny", "Cloudy", "Rainy"};
  scanf("%s", weather);
  
  int i;
  for(i = 0; i<3; i++){
    if(strcmp(weather, weather_kind[i]) == 0){
      break;
    }
  }
  
  printf("%s", weather_kind[(i+1)%3]);
}

Measured memory_bytes: 128
//id:miiifa (AOJ,PEどちらも)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt=0;
    REP(i,s.size()-1){
        if((s[i]=='O'&&s[i+1]=='X')||(s[i]=='X'&&s[i+1]=='O')){
            cnt++;
            i++;
        }else if(s[i]=='O'||s[i]=='X') {
            
            // if(i==s.size()-2) 
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3336
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll ans=0;
    ll a=1;
    while(a<N/a-1){
        if(N%a!=0) {
            a++;
            continue;
        }
        else{
            ans+=N/a-1;
        }
        a++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    double L;
    cin>>L;
    cout<<fixed<<setprecision(9)<<L*L*L/27<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char s[51],t[51];
  int i,j,z,x,y;
  scanf("%s%s",s,t);for(x=0;s[x];x++);for(y=0;t[y];y++);
  for(i=x-y;i>=0;i--){
    z=0;
    for(j=0;j<y;j++)z+=(s[i+j]=='?')+(s[i+j]==t[j]);
    if(z==y){for(j=0;j<y;j++)s[i+j]=t[j];for(j=0;j<x;j++)printf("%c",s[j]=='?'?'a':s[j]);return 0;}
  }
  printf("UNRESTORABLE");
}


Measured memory_bytes: 1716
#include <iostream>

using namespace std;

int main() {
	int a[5];
	int b[5];
	int ans = 0;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		b[i] = 10 - (a[i] % 10);
		if ((a[i] % 10) == 0) {
			b[i] = 0;
		}
	}
	int temp = b[0];
	int maxn = 0;
	for (int i = 0; i < 5; i++) {
		if (temp < b[i]) {
			temp = b[i];
			maxn = i;
		}
	}
	for (int i = 0; i < 5; i++) {
		ans += a[i] + b[i];
	}
	ans -= b[maxn];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

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

int main(void) {

	unsigned long long int a, b, r, tmp;
	unsigned long long int gd;
	unsigned long long int  res;
	
	scanf("%lld %lld", &a, &b);

	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	

	gd = gcd(a, b);

	res = a*b/gd;

	printf("%lld", res);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;int N,C,D[5010][2],i,j;main(){cin>>N;fill_n(*D+3,1e4,1e9);D[0][0]=1e9;for(;cin>>C,i<N-1;i++)for(j=N/2;~j;)D[j+1][0]=min(D[j][0],D[j][1]+C),D[j--][1]=min(D[j][0]+C,D[j][1]);cout<<min(D[N/2][0],D[N/2][1])<<endl;}

Measured memory_bytes: 1204
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9 + 7;
int N;
int x[100010];

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		scanf("%d" , x + i);
	}
	LL ans = 1;
	int p = 0;
	int q = 0;
	repp(i,0,N){
		while(p < N && x[p] > q * 2){
			++p;
			++q;
		}
		if(p < N && x[p] == q * 2) ++p;
		(ans *= (p-i)) %= mod;
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

vector<vector<ll>> adj;
vector<ll> g;
vector<ll> used;
void dfs(ll pos, ll num) {
	used[pos]=true;
	g[pos]=num;
	REP(i,(ll)adj[pos].size()) {
		if(!used[adj[pos][i]]) {
			dfs(adj[pos][i],num);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	adj.resize(n);
	REP(i,m) {
		ll x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	g.resize(n);
	used.resize(n);
	REP(i,n) used[i]=false;
	ll cnt=0;
	REP(i,n) {
		if(!used[i]) {
			dfs(i,cnt);
			cnt++;
		}
	}
	if(cnt==1) {
		cout<<0<<endl;
		return 0;
	}
	if((cnt-1)>n/2) {
		cout<<"Impossible"<<endl;
		return 0;
	}
	ll ans=0;
	vector<vector<ll>> gg(cnt);
	REP(i,n) {
		gg[g[i]].pb(i);
	}
	REP(i,cnt) {
		ll buf=INF*INF;
		REP(j,(ll)gg[i].size()) {
			buf=min(buf,a[gg[i][j]]);
		}
		REP(j,(ll)gg[i].size()) {
			if(a[gg[i][j]]==buf) {
				a[gg[i][j]]=INF*INF;
				break;
			}
		}
		ans+=buf;
	}
	sort(ALL(a));
	REP(i,(cnt-2)) {
		ans+=a[i];
	}
	cout<<ans<<endl;
}


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


int main() {
    int price=700;
    for (int i = 0; i < 3; ++i) {

        char op;
        cin >> op;
        if (op == 'o')price += 100;

    }
    cout<<price<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>  // log10(int n);
#include<math.h>

using namespace std;


int gcd(int x,int y){  //最大公約数 
if(y==0)return x;

if(x>y)return gcd(y,x%y);
else return gcd(x,y%x);
}



int main(){

int x,y;
while(cin>>x>>y)cout<<gcd(x,y)<<" "<<x/gcd(x,y)*y<<endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

string s, t;

bool cmp(char a, char b) {
  return a > b;
}

string solve() {
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), cmp);
  if (s < t) return "Yes";
  else return "No";
}

int main() {
  cin >> s >> t;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005],b[100005],c[100005];
ll A,B;
ll ans;
ll d;
int main(void){
    ll n; cin>>n;
    for(int i=0;i<n;i++){
		cin>>a[i];
		A=A+a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		B=B+b[i];
		if(a[i]<b[i]){
			ans++;
			d=d+b[i]-a[i];
		}else{
			c[i]=a[i]-b[i];
		}
	}
	if(A<B){
		cout<<-1<<endl; return 0;
	}
	sort(c,c+n);
	if(d==0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=n-1;i>=0;i--){
		d=d-c[i];
		ans++;
		if(d<=0){
			cout<<ans<<endl;
			return 0;
		}
	}
	
    
}


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

bool isChangeble(int start, int goal, string s){
    int p = start;
    int num = 0;
    while (p < goal)
    {
        if(s[p] == '.'){
            num += 1;
            p += 1;
            if(num == 3){
                return true;
            }
            continue;
        }else{
            num = 0;
            p += 1;
            continue;
        }
    }

    return false;
}

bool isDoubleSharpe(int start, int goal, string s){
    int p = start;
    int num = 0;

    while(p < goal){
        if(s[p] == '#'){
            num += 1;
            p += 1;
            if(num == 2){
                return true;
            }
            continue;
        }else{
            num = 0;
            p += 1;
        }
    }

    return false;
}


int main()
{
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a -= 1;
    b -= 1;
    c -= 1;
    d -= 1;
    string s;
    cin >> s;

    if(isDoubleSharpe(a, max(c, d), s)){
        cout << "No" << endl;
    }else if(d < c && (s[d-1] == '#' || s[d+1] == '#') && !isChangeble(b-1,d+1,s)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 772