akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

ll g(ll n) {
    return n*(n+1)/2;
}
int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        ll j = N/i;
        ans += i*g(j); 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  
  unordered_map<string, int> cnts;
  int max_cnt = 0;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    cnts[s[i]]++;
    max_cnt = max(max_cnt, cnts[s[i]]);
  }

  set<string> results;
  for (auto p : cnts) {
    if (p.second == max_cnt) {
      results.insert(p.first);
    }
  }

  for (auto s : results) {
    cout << s << "\n";
  }

  return 0;
}

Measured memory_bytes: 35016
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    cin>>a>>b;
    c = a+b;
    int temp = 1,sum=0,p =0;
    for(int i=0;i<c.length();i++)
    {
        int x = c[i]-'0';
        sum = sum*10 +x;
    }
    int n1 = (int) sqrt(sum);
    if(n1*n1==sum)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main()
{
    long long  n,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    long long m = n/(a+b)*a;
    long long s = min(a,n%(a+b));
    cout<<m+s<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    if(a*b<=0)printf("Zero");
    else if(a>0&&b>0)printf("Positive");
    else if((b-a)%2==0)printf("Negative");
    else printf("Positive");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N;
int p[64], t[64];
int cnt;
int dp[64][4];


int main(){
  while(cin>>N, N){
    rep(i,N) cin >> p[i] >> t[i];
    rep(i,64) fill(dp[i], dp[i]+4, INF);
    if(p[0] > t[0]){
      cout << "NG " << 1 << endl;
      continue;
    }
    dp[0][0] = p[0];
    cnt = 1;
    for(int i=1;i<N;i++){
      for(int j=1;j<4;j++){
	if(dp[i-1][j-1]==INF) continue;
	cnt = i;
	if(j < 3 && abs(p[i]-p[i-1])*(j+1) <= abs(t[i]-t[i-1])){
	  dp[i][j] = min(dp[i][j], dp[i-1][j-1]+abs(p[i]-p[i-1]));
	}
	if(p[i] + p[i-1]*(j+1)<= abs(t[i]-t[i-1])){
	  dp[i][0] = min(dp[i][0], dp[i-1][j-1]+p[i]+p[i-1]);
	}
      }
    }
    int res = INF;
    rep(i,4) res = min(res, dp[N-1][i]);
    if(res==INF) cout << "NG " << cnt+1 << endl;
    else cout << "OK " << res+p[N-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
n = int(input())
l = list(map(int,input().split()))

ans = 0
a = b = c = 0

for fi in range(n):
    for si in range(fi+1,n):
        for ti in range(si+1,n):
            a = l[fi]
            b = l[si]
            c = l[ti]
            if a == b or b == c or c == a:
                pass
            else:
                if a+b > c and b+c > a and c+a > b:
                    ans += 1 
print(ans)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

class UnionFind {
public:
  // 親の番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> parent;

  // 作るときは parent の値を全て -1 にする
  // こうすると全てバラバラになる
  UnionFind(const int& n = 0) : parent(n, -1) {}

  // x がどのグループに属しているか調べる
  int find(const int& x) {
    if (parent[x] < 0) return x;
    return parent[x] = find(parent[x]);
  }

  // x と y をくっつける  O(log n)
  bool unite(int x, int y) {
    // x と y を直接くっつけるのではなく，root(x) に root(y) をくっつける
    x = find(x);
    y = find(y);
    if (x == y) return false;  // すでにくっついているからくっつけない

    // 大きい方(x) に小さい方(y)をくっつけたい 大小が逆だったらひっくり返す
    if (size(x) < size(y)) swap(x, y);

    parent[x] += parent[y];  // x のサイズを更新する
    parent[y] = x;  // y の親を x に変更する
    return true;
  }

  // 自分のいるグループの頂点数を調べる
  int size(const int& x) { return -parent[find(x)]; }

  // x と y が同じグループに属しているか否か
  bool same(const int& x, const int& y) { return find(x) == find(y); }
};

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

  ll n, m; cin >> n >> m;
  vector<ll> p(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }

  UnionFind uf(n);
  rep(i, m) {
    int x, y; cin >> x >> y; x--; y--;
    uf.unite(x, y);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] == i || uf.same(i, p[i])) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

const int MOD = 1e9 + 7;
int N, K;
ll mul(ll a, ll b) {
	return (a%MOD)*(b%MOD) % MOD;
}
ll add(ll a, ll b) {
	return ((a%MOD)+(b%MOD) + MOD) % MOD;
}
ll mpow(ll a, ll b) {
	if (b == 0) return 1;
	if (b & 1) return mul(a, mpow(a, b - 1));
	ll tmp = mpow(a, b / 2);
	return mul(tmp, tmp);
}

ll multiple[200000];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	ll ans = 0;
	for (int i = K; i >= 1; i--) {
		multiple[i] = mpow(K / i, N);
		for (int j = 2 * i; j <= K; j += i) multiple[i] = add(multiple[i], -multiple[j]);
		ans = add(ans, multiple[i] * i);
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;
const int MAX=3000+3;
typedef long long ll;
int N;
ll a[MAX], dp[MAX][MAX];

ll solve(int l, int r, int t){

    if(l > r) return 0;
    ll &ret=dp[l][r];
    if(ret!=-1) return ret;

    if(t){
        ret=min(solve(l+1, r, 0)-a[l], solve(l, r-1, 0)-a[r]);
    } else {
        ret=max(solve(l+1, r, 1)+a[l], solve(l, r-1, 1)+a[r]);
    }

    return ret;

}


int main(){
    scanf("%d",&N);
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<N;i++) scanf("%lld",&a[i]);
    printf("%lld\n",solve(0, N-1, 0));
    return 0;
}


Measured memory_bytes: 74452
#include <iostream>
using namespace std;
void insert(int *arr, int n);
void print(int *arr, int n);
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0;i < n;i ++)
    {
        cin>>arr[i];
    }

    insert(arr, n);

    //print(arr, n);


}

void insert(int *arr, int n)
{
    print(arr, n);
    for(int i = 1;i < n;i++)
    {
        int key = arr[i];
        int j = i - 1;
        while(j >= 0 && arr[j] > key)
        {
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = key;
        print(arr, n);
    }
}

void print(int *arr, int n){
    for(int i = 0;i < n;i++)
    {
        cout<<arr[i];
        if(i < n -1)
            cout<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 3100
games = int(input())

taro = 0
hanako = 0

for _ in range(games):
    taroinput, hanakoinput = input().split()
    if taroinput == hanakoinput:
        taro += 1
        hanako += 1
        continue
    attempts = min(len(taroinput), len(hanakoinput))
    if len(taroinput) > len(hanakoinput):
        isTaroLonger = True
    else:
        isTaroLonger = False
    iter_taro = iter(taroinput)
    iter_hanako = iter(hanakoinput)
    for i in range(attempts):
        next_taro = next(iter_taro)
        next_hanako = next(iter_hanako)
        if next_taro > next_hanako:
            taro += 3
            break
        elif next_hanako > next_taro:
            hanako += 3
            break
    else:
        if isTaroLonger:
            taro += 3
        else:
            hanako += 3

print(taro, hanako)


Measured memory_bytes: 5592
import sys
input = sys.stdin.readline

def inv(x):
    return pow(x, MOD-2, MOD)
    
def C(n, r):
    if r>n:
        return 0
    #return fact[n]//fact[r]//fact[n-r]
    #return fact[n]*inv(fact[r])*inv(fact[n-r])
    return fact[n]*inv_table[r]*inv_table[n-r]

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
MOD = 10**9+7

if K==1:
    print(0)
    exit()

fact = [1]

for i in range(1, N+1):
    fact.append(fact[-1]*i%MOD)
    #fact.append(fact[-1]*i)

inv_table = [-1]*(N+1)

for i in range(N+1):
    inv_table[i] = inv(fact[i])
    
ans = 0
c_acc = [0]

for i in range(N+1):
    c_acc.append((c_acc[-1]+C(i, K-2))%MOD)

for i in range(N):
    left = c_acc[i]-c_acc[0]
    right = c_acc[N-i-1]-c_acc[0]
    #print(left, right)
    ans += A[i]*(left-right)
    ans %= MOD

print(ans)

Measured memory_bytes: 65448
#include <stdio.h>

int main(){
	int a[6],k = 1;
	for(int i = 0;i < 6;i++)
		scanf("%d",&a[i]);
	for(int i = 0;i < 4;i++){
		for(int j = i + 1;j < 5;j++){
			if(a[j] - a[i] > a[5]){
				k = 0;
				break;
			}
		}
		if(k == 0) break;
	}
	if(k) printf("Yay!");
	else printf(":(");
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();      
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}
        int[][] X = new int[N][];
        for(int i = 0; i < N; i++)
            X[i] = r.ii();
        int ans = 0;
        for(int i = 0; i < N-1; i++){
            for(int j = i+1; j < N; j++){
                double d = 0;
                for(int k = 0; k < D; k++){
                    d += pow(X[i][k]-X[j][k]);
                }
                d = Math.sqrt(d);
                if(d%1 == 0){
                    ans++;
                }
            }
        }
        println(ans);
    }
    static int pow(int x){
        return x*x;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  int max = 0;
  int min = 1000000001;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
    if(a.at(i) > max) max = a.at(i);
    if(a.at(i) < min) min = a.at(i);
  }
  cout << max - min << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int w = in.nextInt();
        int h = in.nextInt();
        int x0 = 0, y0 = 0;
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int a1 = in.nextInt();
            switch (a1) {
                case 1:
                    x0 = Math.max(x0, x1);
                    break;
                case 2:
                    w = Math.min(w, x1);
                    break;
                case 3:
                    y0 = Math.max(y0, y1);
                    break;
                case 4:
                    h = Math.min(h, y1);
                    break;
            }
        }

        int square = Math.max(0, w - x0) * Math.max(0, h - y0);
        System.out.println(square);
    }
}


Measured memory_bytes: 27684
#include <cstdio>
int main()
{
	int n;
	char prime[50001];
	for(int i = 0; i <= 50000; i++)
		prime[i] = 1;
	prime[0] = 0; prime[1] = 0;
	for(int i = 2; i <= 50000; i++){
		if(!prime[i]) continue;
		for(int j = i + i; j <= 50000; j += i)
			prime[j] = 0;
	}
	while(scanf("%d\n", &n), n){
		int cnt = 0;
		for(int i = 2; i <= n / 2; i++)
			if(prime[i] && prime[n - i])
				cnt++;
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 2612
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, sum[1000000][20],ssum[1<<20], last, cnt, ans, a[1000000], dp[1 << 20] = {};
int dd[4][2] = { {1,0},{0,1},{ -1,0 },{ 0,-1 } };
string str,ss;
struct Edge { LL to; };
vector<Pll>vec[1000][1000];
bool f;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		rep(j, 20) {
			sum[i + 1][j] = sum[i][j];
			if (a[i]-1 == j)sum[i + 1][j]++;
		}
	}
	rep(i, 1 << m) {
		dp[i] = INF/2;
		rep(j, m)
			if (i & 1 << j)
				ssum[i] += sum[n][j];
	}
	dp[0] = 0;
	rep(i, 1 << m) {
		rep(j, m) {
			if (!(i&(1 << j))) {
				dp[i + (1 << j)] = min(dp[i] + sum[n][j] - (sum[ssum[i + (1 << j)]][j] - sum[ssum[i]][j]), dp[i + (1 << j)]);
			}
		}

	}
	cout << dp[(1 << m)-1] << endl;
	return 0;
}


Measured memory_bytes: 59360
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, K, M, R;
	static int[] buf = new int[10020];

	public static void main(String[] args) throws Exception {
		while (true) {
			N = sc.nextInt();
			K = sc.nextInt();
			M = sc.nextInt();
			R = sc.nextInt();
			if (N == 0) break;
			int[] ans = new int[R + 10];
			divide(1, N, ans);
			if (M == 1) {
				for (int i = 1; i < N; ++i) {
					divide(1, N * i, buf);
					add(ans, buf);
				}
			}
			boolean carry = true;
			for (int i = R + 1; i < ans.length - 4; ++i) {
				if (ans[i] != 9) {
					carry = false;
					break;
				}
			}
			if (carry) {
				int[] add = new int[ans.length];
				add[R + 1] = 1;
				add(ans, add);
			}
			StringBuilder sb = new StringBuilder();
			sb.append((char) (ans[0] + '0'));
			sb.append('.');
			for (int i = 1; i <= R; ++i) {
				sb.append((char) (ans[i] + '0'));
			}
			System.out.println(sb);
		}
	}

	static void divide(int num, int den, int[] ret) {
		for (int i = 0; i < R + 10; ++i) {
			ret[i] = num / den;
			num %= den;
			num *= 10;
		}
	}

	static void add(int[] recipient, int[] donor) {
		int carry = 0;
		for (int i = recipient.length - 1; i >= 0; --i) {
			recipient[i] += carry + donor[i];
			carry = recipient[i] / 10;
			while (recipient[i] >= 10) {
				recipient[i] -= 10;
			}
		}
	}

}

Measured memory_bytes: 12000
n = int(input())
l = list(map(int, input().split()))
mod = 10**9+7
if n % 2 == 0 and len(set(l)) == n//2:
  print(2**(n//2)%mod)
elif not n % 2 == 0 and l.count(0) == 1:
  print(2**((n-1)//2)%mod)
else:
  print(0)


Measured memory_bytes: 13880
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        for (int i = 0; i <= n; i++) {
            for (int j = n - i; j >= 0; j--) {
                int x = i * 10000 + j * 5000 + (n - i - j) * 1000;
                if (x == y) {
                    System.out.printf("%d %d %d\n", i, j, n - i - j);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

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

int main() {
  int i, j, n, m;
  cin >> n;
  int a[n];
  
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  j=0;
  m=0;
  sort(a, a+n, greater<int>());
  for(i=0;i<n;i+=2){
    j+=a[i];
  }
  for(i=1;i<n;i+=2){
    m+=a[i];
  }
  cout << j-m << endl;
}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	count := 0
	for i := N; i > 0; i-- {
		if len(strconv.Itoa(i))%2 != 0 {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
int main(void)
{
    int num;
    double weight,hight;
    while(scanf("%d,%lf,%lf",&num, &weight,&hight) != EOF){
        if(25<=(weight/(hight*hight))){
            printf("%d\n", num);
        }
    }
	return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    int q;
    cin >> q;
    int t[q];
    for (int i = 0; i < q; ++i)
        cin >> t[i];
    int ans(0);
    for (int i = 0; i < q; ++i)
    {
        int j = 0, key = t[i];
        while (key != s[j] && j < n)
            ++j;
        if (j != n)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	LL W;
	cin >> N >> W;
	vector<vector<LL>> dp(N+1, vector<LL>(303, 0));
	LL w1;
	LL ans = 0;
	REP(i, N){
		LL w, v;
		cin >> w >> v;
		if(i==0)w1=w;
		w-=w1;
		PER(i, 303){
			PER(j, N+1){
				if(j*w1+i>W||j==0||i-w<0)continue;
				chmax(dp[j][i], dp[j-1][i-w]+v);
				chmax(ans, dp[j][i]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

ans = []
for i in range(h):
    for j in range(w-1):
        if a[i][j] % 2 != 0:
            ans.append([i+1, j+1, i+1, j+2])
            a[i][j+1] += 1
            a[i][j] -= 1

for i in range(h-1):
    if a[i][-1] % 2 != 0:
        ans.append([i+1, w, i+2, w])
        a[i][-1] -= 1
        a[i+1][-1] += 1

print(len(ans))
for _ans in ans:
    print(str(_ans[0]) + ' ' + str(_ans[1]) + ' ' + str(_ans[2]) + ' ' + str(_ans[3]))


Measured memory_bytes: 29864
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b;
    c=a+b;
    if(c>0){
        cout << "1";
    }
    else if(c<0){
        cout << "-1";
    }
    else{
        cout << "0";
    }
    cout << "\n";
    return 0;
}


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

vector<vector<bool>> TFcombination(int n){
    vector<vector<bool>> ans(pow(2, n), vector<bool>(n));
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j < n; j++){
            ans[i][j] = i >> j & 1;
        }
    }
    return ans;
}

int main(){
    int d, g;
    cin >> d >> g;
    vector<ll> p(d), c(d);
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }

    vector<vector<bool>> isPerfect = TFcombination(d);
    int ans = 1e9;
    for(auto x : isPerfect){
        int score = 0;
        int tmpans = 0;
        int remainNumMax;
        rep(i, d){
            if(x[i]){
                score += (100 * (i + 1) * p[i] + c[i]);
                tmpans += p[i];
            }
            else{
                remainNumMax = i;
            }
        }
        if(score < g){
            for(int i = 0; i < p[remainNumMax]; i++){
                score += 100 * (remainNumMax + 1);
                tmpans++;
                if(score >= g){
                    // ans = min(ans, tmpans);
                    break;
                }
            }
        }
        // ans = min(ans, tmpans);
        if(score >= g){
            ans = min(ans, tmpans);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	
	int train = N * A;
	int taxi = B;
	
	if (train < taxi)
	{
		cout << train << endl;
	}
	else {
		cout << taxi << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int w,h,n,a,x,y,x1=0,y1=0,x2,y2;
    cin >> w >> h >> n;
    x2 = w;
    y2 = h;
    for(int i=0;i<n;i++){
        cin >> x >> y >> a;
        if(a==1)
            x1 = max(x,x1);
        else if(a==2)
            x2 = min(x,x2);
        else if(a==3)
            y1 = max(y,y1);
        else
            y2 = min(y,y2);
    }
    cout << max(0,x2-x1)*max(0,y2-y1) << endl;
}


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

const ll INF = 1e13;

int main()
{
	ll N, K;
	cin >> N >> K;
	vector<vector<ll>> s(N);
	for (int i = 0; i < N; i++)
	{
		ll t, d;
		cin >> t >> d;
		t--;
		s[t].push_back(d);
	}

	for (auto &v : s)
	{
		sort(v.begin(), v.end(), greater<ll>());
		if (v.empty())
			v.push_back(-INF);
	}

	sort(s.begin(), s.end(), [](vector<ll> a, vector<ll> b) { return a[0] > b[0]; });

	// まずK種類選ぶ
	ll cur = 0;
	priority_queue<ll> pq;

	for (int i = 0; i < K; i++)
	{
		cur += s[i][0];
		for (int j = 1; j < s[i].size(); j++)
			pq.push(s[i][j]);
	}
	for (int i = K; i < N; i++)
		for (int j = 0; j < s[i].size(); j++)
			pq.push(s[i][j]);

	ll ans = cur + K * K;
	for (ll x = K - 1; x >= 1; x--)
	{
		ll v = s[x][0];
		ll w = pq.top();
		if (v < w)
		{
			pq.pop();
			cur += w;
			pq.push(v);
			cur -= v;
			ans = max(ans, cur + x * x);
		}
		else
		{
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 8696
h, w = map(int, input().strip().split())
pattern1 = (w + 1) // 2
pattern2 = w // 2

ans = pattern1 * ((h + 1) // 2) + pattern2 * (h // 2)

if h == 1 or w == 1:
    print(1)
else:
    print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A = in(),B = in(),C = in();
    cout << max({A,B,C})*9+A+B+C << "\n";
}

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

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

	int mod0  = 0;
	int mod1_3  = 0;
	int mod2  = 0;

	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		switch(a%4){
			case 0: mod0++;break;
			case 1:case  3: mod1_3++;break;
			case 2: mod2++; break;
		}
	}
	if(mod1_3 > mod0){
		if(mod2 > 0) {
			cout << "No" << endl;
			return 0;
		} else {
			cout << (mod1_3 - mod0 == 1 ? "Yes" : "No") << endl;
		}
	} else {
		cout << "Yes" << endl;
	}
}

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

using namespace std;
typedef long long ll;

ll N,T;
ll dp[6000][3001];
vector<pair<ll,ll>> v;

int main(){
    cin >> N >> T;
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    for(int i=0;i<2*T;i++){
        for(int j=0;j<=N;j++) dp[i][j] = -1e15;
    }
    dp[0][0] = 0;
    for(int i=0;i<T;i++){
        for(int j=0;j<=N;j++){
            dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
            if(j < N){
                dp[i][j+1] = max(dp[i][j], dp[i][j+1]);
                dp[i+v[j].first][j+1] = max(dp[i][j]+v[j].second, dp[i+v[j].first][j+1]);
            }
        }
    }
    ll max_b = -1;
    for(int i=T;i<T+3000;i++){
        for(int j=0;j<=N;j++){
            max_b = max(max_b, dp[i][j]);
        }
    }
    cout << max_b << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    int n;
    set<int> s;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        s.insert(a);
    }
    if(s.size() == n){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 12916
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val aaa = a.toString().repeat(b)
    val bbb = b.toString().repeat(a)
    println(if (aaa < bbb) aaa else bbb)
}

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

signed main() {
 	ios::sync_with_stdio(false);
  			cout.tie(nullptr);
  			cin.tie(nullptr);
  long long a,b;
  cin >> a >>b;
  long long t = a*(a-1)/2;
  long long d = b*(b-1)/2;
  cout << (t+d);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool isSquare(int n) {
    for (int i=1; i*i<=n; i++) {
        if (i*i==n) return true; 
    }
    return false;
}
int main() {
    string a, b;
    cin >> a >> b;
    string s = a + b;
    int n = atoi(s.c_str());
    cout << (isSquare(n) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+10;
int N,A[MAXN];
inline void work(){
    int Xor=0;
    for(int i=1;i<=N;i++) Xor^=A[i];
    for(int i=1;i<=N;i++) A[i]^=Xor;
}
int main(){
    cin>>N;
    for(int i=1;i<=N;i++) cin>>A[i];
    work();
    for(int i=1;i<=N;i++) cout<<A[i]<<" ";
    return 0;
}

Measured memory_bytes: 4356
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, q;
    queue<int> que;
    vector<bool> visited;
    vector<int> value;
    vector<list<int> > graph;
    cin >> n >> q;
    visited.resize(n + 1);
    value.resize(n + 1);
    graph.resize(n + 1);
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        value[p] += x;
    }
    visited[1] = true;
    que.push(1);
    while (que.size()) {
        int now = que.front();
        que.pop();
        for (int next : graph[now])
            if (!visited[next]) {
                visited[now] = true;
                value[next] += value[now];
                que.push(next);
            }
    }
    for (int i = 1; i <= n; i++) cout << value[i] << ' ';
    return 0;
}

Measured memory_bytes: 19456
S = input()
L = len(S)
MOD = 10**9+7

dp = [[0]*2 for i in range(L+1)]
dp[0][0] = 1

for i,c in enumerate(S):
    dp[i+1][0] = dp[i][0]*2 if int(c) else dp[i][0]
    dp[i+1][1] = dp[i][0] if int(c) else 0
    dp[i+1][1] += dp[i][1]*3
    dp[i+1][0] %= MOD
    dp[i+1][1] %= MOD
print(sum(dp[-1])%MOD)

Measured memory_bytes: 19700
#include<cstdio>


int main(){
  int N,A,B;
  scanf("%d %d %d\n",&N,&A,&B);
//  printf("%d %d %d\n",N,A,B);
  if(N*A>B){
    printf("%d\n",B);
  }
  else{
    printf("%d\n",N*A);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int* a = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int total = 0;
	float level;
	for (int i = 0;i < n;i++) {
		total += a[i];
	}
	level = ((float)total) / ((float)(4 * m));
	int count = 0;
	for (int i = 0;i < n;i++) {
		if ((float)a[i] >= level)count++;
	}
	if (count >= m) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 201

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

int mm[SIZE][SIZE];
int h,w;

bool dfs(int y,int x){
  
  if(y<0 || h<=y || x<0 || w<=x) return false;
  if(mm[y][x]==0) return false;
  mm[y][x] = 0;
  
  for(int i=0;i<8;i++){
    dfs(y+dy[i],x+dx[i]);
  }

  return true;
}

void calc(){
  int ans = 0;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%d",mm[i]+j);
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans += dfs(i,j);
    }
  }
  
  printf("%d\n",ans);
}

int main(){
  
  while(1){
    scanf("%d%d",&w,&h);
    if(h==0) break;
    calc();
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll calc(ll x){
  ll ret = 0;
  while(x>=3){
    x--;
    x/=2;
    ret++;
  }
  return ret;
}

int main(){
  ll x;
  cin>>x;
  ll mn = 0, mx = 1ll<<62;
  while(mn+1<mx){
    ll mid = (mn+mx)/2;
    ll y = calc(mid);
    if(y<=x)mn = mid;
    else mx = mid;
  }
  cout<<mn<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MAX 2000000
#define INFTY 2000000000

using namespace std;

int A[MAX+1], h;

void heapIncreaseKey(int i, int key){
    if(key < A[i]) cerr << "new key is smaller than current key" << endl;
    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        int tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
        i /= 2;
    }
}

void maxHeapInsert(int key){
    h++;
    A[h] = -INFTY;
    heapIncreaseKey(h, key);
}

void maxHeapify(int i){
    int l = 2 * i;
    int r = 2 * i + 1;
    int largest;
    if(l <= h && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= h && A[r] >  A[largest]) largest = r;
    if(largest != i){
        int tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(largest);
    }
}

int heapExtractMax(){
    if(h < 1) cerr << "head underflow" << endl;
    int max = A[1];
    A[1] = A[h];
    h--;
    maxHeapify(1);
    return max;
}

int main(){
    string com;
    int key;
    
    cin >> com;
    while(com != "end"){
        if(com == "insert"){
            cin >> key;
            maxHeapInsert(key);
        }
        else cout << heapExtractMax() << endl;
        cin >> com;
    }

    return 0;
}


Measured memory_bytes: 7112
#include<iostream>
#include<algorithm>
using namespace std;
inline int read()
{
    int x=0,t=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}
struct nodes{
	int x, y;
	bool operator < (const nodes & a)const{ if(a.y==y)return x<a.x;return y<a.y;}
}node[1000000];
int main(){
	int a,b;
	a=read();
	b=read();
	for(int i=1;i<=b;i++){
		node[i].x=read();
		node[i].y=read();
	}
	sort(node+1,node+b+1);
	int ans=1;
	int Min=node[1].y;
 	for(int i=2;i<=b;i++){
 		if(node[i].x>=Min){
 			ans++;
 			Min=node[i].y;
		 }
	 }
	 cout<<ans<<endl;
} 

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

namespace AtCoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var input1Arr = input1.Split(' ');
            var N = int.Parse(input1Arr[0]);
            var M = int.Parse(input1Arr[1]);

            var input2 = Console.ReadLine();
            var input2Arr = input2.Split(' ');
            var A = new int[N];
            for (int i = 0; i < A.Length; i++)
            {
                A[i] = int.Parse(input2Arr[i]);
            }

            Array.Sort(A);

            var comparedValue = A[A.Length - M];
            var compareValue = A.Sum() / ((double)4 * M);

            var returnValue = comparedValue >= compareValue ? "Yes" : "No";

            Console.WriteLine(returnValue);
        }
    }
}


Measured memory_bytes: 13268
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


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

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

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

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

    return result % MOD


def solve(N: int, K: int):

    for i in range(1, K+1):
        if N-K+1 < i:
            ans = 0
        else:
            ans = cmb(N-K+1, i)
        ans *= cmb(K-1, i-1)
        ans %= MOD
        print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    ll ans=0;
    FOR(i,1,N){
        ans+=(N-1)/i;
    }
    cout << ans << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3652
N,W=map(int,input().split())
S = [[0 for j in range(2)] for i in range(N+1)]

DP= [[0 for j in range(100010)] for i in range(110)]
def chmax(a,b):
    if a>b:
        return a
    else:
        return b


for i in range(N):
    w,v=map(int,input().split())
    S[i][0]=w
    S[i][1]=v


for i in range(N):
    for j in range(W+1):
        if j-S[i][0]>=0:
            
            DP[i+1][j]=chmax(DP[i][j],DP[i][j-S[i][0]]+S[i][1])
        
        else:
            DP[i+1][j]=DP[i][j]
        
print(DP[N][W])


Measured memory_bytes: 180504
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int main()
{
	ll ans=1;
	int n, x[100010], a[100010]={};
	cin >> n;
	reps(i, n) cin >> x[i];
	repp(j, 2, n+1)
	{
		if(x[j-1]<(2*j-3))
		{
			a[1]=j-1;
			break;
		}
	}
	if(a[1]==0) a[1]=n;
	repp(k, 2, n+1)
	{
		repp(j, a[k-1], n+1)
		{
			if(x[j-1]<(2*j-3-2*(k-1)))
			{
				a[k]=j-1;
				break;
			}
		}
		if(a[k]==0) a[k]=n;
	}
	reps(i, n)
	{
		ans*=((long long)a[i]+1-i);
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
 */
import java.util.*;

class Node {
	char c;
	List<Node> childs = new LinkedList<Node>();
	boolean isRoot = false;
	boolean isTerminator = false;
	Node() {
		this.isRoot = true;
	}
	Node(char c, boolean isTerminator) {
		this.c = c;
		this.isTerminator = isTerminator;
	}
	Node get(char childChar) {
		for (Node node : childs) {
			if (node.c == childChar) return node;
		}
		return null;
	}
	Node dig(char c, boolean isTerminator) {
		Node node = get(c);
		if (node == null) {
			node = new Node(c, isTerminator);
			childs.add(node);
		}
		if (isTerminator && !node.isTerminator) node.isTerminator = true; 
		return node;
	}
	public String toString() {
		String ret = "\'" + String.valueOf(c) + "\'";
		for (Node node : childs) {
			ret += " " + node.c;
		}
		return ret;
	}
}

public class Main {
	void insert(Node root, String str) {
		char[] ca = str.toCharArray();
		Node node = root;
		for (int i = 0; i < ca.length; i++) {
			node = node.dig(ca[i], i==(ca.length-1));
		}
	}
	boolean find(Node root, String str) {
		//System.out.println("### " + str);
		char[] ca = str.toCharArray();
		//System.out.println("root: " + root.toString());
		Node node = root;
		for (int i = 0; i < ca.length; i++) {
			node = node.get(ca[i]);
			//System.out.println(ca[i] + " : " + (node != null));
			if (node == null) return false;
		}
		return node.isTerminator;
	}
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node root = new Node();
		for (int i = 0; i < n; i++) {
			String cmd = sc.next();
			String str = sc.next();
			if (cmd.equals("insert")) {
				insert(root, str);
			} else if (cmd.equals("find")) {
				if (find(root, str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



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

int main(){
  int x[10][10];
  int a,b,c;
  int cou=0,max=0;
  int ink[3]={5,9,13};
  int tmp[3][2][13]={
    {{0,0,1,0,-1},{0,-1,0,1,0}},
    {{0,0,1,1,1,0,-1,-1,-1},{0,-1,-1,0,1,1,1,0,-1}},
    {{0,0,1,1,1,0,-1,-1,-1,0,2,0,-2},{0,-1,-1,0,1,1,1,0,-1,-2,0,2,0}}
  };
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      x[i][j] = 0;
    }
  }
  while(scanf("%d,%d,%d\n",&a,&b,&c) != EOF){
    c--;
    for(int i=0;i<ink[c];i++){
      if(a+tmp[c][0][i]>=0 && a+tmp[c][0][i]<10 && b+tmp[c][1][i]>=0 && b+tmp[c][1][i]<10){
	x[a+tmp[c][0][i]][b+tmp[c][1][i]]++;
      }
    }
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(x[i][j] == 0){
	cou++;
      }
      else if(x[i][j] > max){
	max = x[i][j];
      }
    }
  }
  cout << cou << endl << max << endl;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
#define mod 1000000007
int C[maxn],lst[maxn];
ll dp[maxn],sum[maxn];
bool hsr[maxn];
struct seg
{
	int l,r;
	seg(){}
	seg(int l,int r):l(l),r(r){}
	bool operator <(const seg &t)const
	{
		return l<t.l;
	}
};
vector<seg> all;
int main()
{
	memset(lst,-1,sizeof(lst));
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&C[i]);
		if(lst[C[i]]!=-1&&lst[C[i]]!=i-1)
		{
			all.push_back(seg(lst[C[i]],i));
		}
		lst[C[i]]=i;
	}
	sort(all.begin(),all.end());
//	for(int i=0;i<all.size();i++)
//		cout<<all[i].l<<" "<<all[i].r<<endl;
	//dp[i] last right pos
	memset(dp,0,sizeof(dp));
	memset(sum,0,sizeof(sum));
	int j=0;
	for(int i=0;i<n;i++)
	{
		if(i)sum[i]=sum[i-1];
		else sum[i]=1;
		sum[i]+=dp[i];
		if(sum[i]>=mod)sum[i]-=mod;
		if(j<all.size()&&all[j].l==i)
		{
			dp[all[j].r]+=sum[i];
	//		cout<<all[j].r<<" "<<dp[all[j].r]<<endl;
			if(dp[all[j].r]>=mod)dp[all[j].r]-=mod;
			j++;
		}
	//	cout<<dp[i]<<" "<<sum[i]<<endl;system("pause");
	}
	printf("%lld\n",(sum[n-1])%mod);
	return 0;
}

Measured memory_bytes: 7152
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
c.sort()

sum = 0
for j in range(n):
  atemp = bisect.bisect_left(a, b[j])
  ctemp = n - bisect.bisect_right(c, b[j])
  sum += atemp * ctemp

print(sum)


Measured memory_bytes: 23360
#include <bits/stdc++.h>
using namespace std;
int fx4[] = {1 , -1 , 0 , 0};
int fy4[] = {0 , 0 , 1 , -1};
int Kfx[]= {-2,-2,2,2,1,1,-1,-1}; ///knight move x - exis
int Kfy[]= {1,-1,1,-1,2,-2,2,-2}; ///knight move y- exis
int fx8[]= {1,1,1,0,0,-1,-1,-1};
int fy8[]= {0,1,-1,1,-1,0,1,-1};
#define ll long long int
#define pii pair<int,int>
#define llu unsigned long long
#define inf 1<<28
#define gama 0.57721566490
#define PI              acos(-1.0)
#define INF             0x7fffffff
#define MOD             1000000007
#define EPS             1e-7
#define all(r)(r).begin(),(r).end()
/*
bool status[mx];
void sieve(){
   long long int  i,j;
    for(i=2;i<=mx;i++)
    {
        status[i]=0;
    }
    for( i=2;i<=sqrt(mx);i++){
        if(status[i]==0)
        {
            for(j=i*i;j<=mx;j+=i){
                status[j]=1;
            }
        }
    }
}*/
ll BM( ll a , ll b , ll m )
{
    if ( b == 0 ) return 1 ;
    ll x = BM(a,b/2,m);
    x = (( x % m) * (x % m))%m;

    if( b % 2 ) x = (( x % m) * (a %m)) % m ;
    return x ;
}
#define dd double
#define sc scanf
#define pr printf
#define VI vector<int>
#define VS vector<string>
#define VC vector<char>
#define VLL vector<long long int>
#define FILE freopen("input.txt","rt",stdin); freopen("output.txt","w",stdout);
#define p_b push_back
#define mem(x,y) memset(x,y,sizeof(x))
#define F(i,a,b) for(i=a;i<=b;i++)
#define sc1(a) scanf("%d",&a)
#define scL1(a) scanf("%lld",&a)
#define scL2(a,b) scanf("%lld%lld",&a,&b)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define fori(N)          for(int i = 0; i<(N); i++)
#define forj(N)         for(int j = 0; j<(N); j++)
#define fork(N)         for(int k = 0; k<(N); k++)
#define forl(N)         for(int l = 0; l<(N); l++)
#define ford(N)         for(int d = 0; d<(N); d++)
#define fori1(N)          for(int i = 1; i<=(N); i++)
#define forj1(N)         for(int j = 1; j<=(N); j++)
#define fork1(N)         for(int k = 1; k<=(N); k++)
#define ford1(N)         for(int d = 1; d<=(N); d++)
#define sqr(x)           (x)*(x)
#define TEST int test,te=0;cin>>test;
#define segment_tree int l=(n*2),r=(n*2)+1,mid=(l+r)/2
#define Mx 100005
#define mx 10005

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);///Beware of use it, if u use it dont use scanf or printf
    int arr[]={300000,200000,100000};
    int x,y;
    cin>>x>>y;
    int sum=0;
     if(x==1 and y==1)sum+=400000;
     if(x<=3)
     sum+=arr[x-1];
	 if(y<=3)sum+=arr[y-1];
    
   
    cout<<sum<<endl;
}


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

int fanc(vector<int> a) {
  vector<int> b(a.size());
  for(int i=0; i<a.size(); i++) {
    b.at(i) = a.at(i);
  }
  sort(b.begin(), b.end());
  for(int i=0; i<a.size(); i++) {
    if(b.at(i) == a.at(a.size()-1))
      return i;
  }
}

int fact(int n) {
  if(n == 0)
    return 1;
  else
    return n * fact(n-1);
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i=0; i<n; i++) 
    cin >> a.at(n-1-i);
  for(int i=0; i<n; i++)
    cin >> b.at(n-1-i);
  
  int ans_a = 1;
  int ans_b = 1;
  
  for(int i=0; i<n; i++) {
    ans_a += fanc(a) * fact(a.size() - 1);
    ans_b += fanc(b) * fact(b.size() - 1);
    a.pop_back();
    b.pop_back();
  }
  
  cout << fabs(ans_a - ans_b) << endl;
}

Measured memory_bytes: 256