akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split(' '))
H = list(map(int, input().split(' ')))
MICHI = []

# 10**5回
for m in range(M):
    MICHI.append(tuple(map(int, input().split(' '))))

# 展望台接続関係マップ
# setsuzokumap = [[0 for i in range(N)] for j in range(N)]
setsuzokumap_d = {}
setsuzokumap_me = [[] for j in range(N)]

# 10**5回
for m in MICHI:
    # setsuzokumap[m[0] - 1][m[1] - 1] = 1
    # k = (m[0] - 1, m[1] - 1)

    setsuzokumap_me[m[0] - 1].append(m[1] - 1)
    setsuzokumap_me[m[1] - 1].append(m[0] - 1)

    # setsuzokumap_d.update({k: 1})

# print(setsuzokumap_d)

good_tenboudai = [None] * N

# すべての展望台を調べる
# 10**5
for n in range(N):
    # 未判断の展望台を調べる
    if good_tenboudai[n] is None:
        # すべての接続パターンを調べる
        if setsuzokumap_me[n]:
            # 最大10**5
            for setsuzokusaki in setsuzokumap_me[n]:

                m = setsuzokusaki

                # 接続先が良い展望台ならば、この展望台は自動的によくない
                if good_tenboudai[m] == 1:
                    good_tenboudai[n] = 0
                else:
                    # 接続先の高さが自分以下だったら接続先は必ずよくない
                    if H[m] <= H[n]:
                        good_tenboudai[m] = 0

                    # 自分の高さが接続先以下だったらよくない
                    if H[n] <= H[m]:
                        good_tenboudai[n] = 0


# 最後まで良くないと判定されなかったのが良いの
# 10**5
for n in range(N):
    if good_tenboudai[n] is None:
        good_tenboudai[n] = 1

# print(good_tenboudai)
print(sum(good_tenboudai))


Measured memory_bytes: 43728
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a,b,c,d,e,f;
  cin >> a >> b >> c>> d >> e >> f;
  if(a == f && b == e && c == d)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#coding:utf-8
import sys
S = input()

while len(S) >= 5:
    if len(S) >= 7 and S[-7:] == "dreamer":
        S = S[:-7]
        continue
    if len(S) >= 6 and S[-6:] == "eraser":
        S = S[:-6]
        continue
    if S[-5:] == "erase" or S[-5:] == "dream":
        S = S[:-5]
        continue
    else:
        print("NO")
        sys.exit()

if len(S) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None


def insert(T, z):
    y = None
    x = T
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y

    if y is None:
        T = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

    return T


def preorder(T, ret):
    ret.append(T.key)

    if T.left is not None:
        preorder(T.left, ret)

    if T.right is not None:
        preorder(T.right, ret)


def inorder(T, ret):
    if T.left is not None:
        inorder(T.left, ret)

    ret.append(T.key)

    if T.right is not None:
        inorder(T.right, ret)


def main():
    m = int(input())
    Tree = None
    for i in range(m):
        cmd, *v = input().split()
        if cmd == "print":
            print(" ", end="")
            inans = []
            inorder(Tree, inans)
            print(*inans)
            print(" ", end="")
            preans = []
            preorder(Tree, preans)
            print(*preans)
        else:
            z = int(v[0])
            znode = Node(z)
            Tree = insert(Tree, znode)


if __name__ == '__main__':
    main()



Measured memory_bytes: 116660
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

ll XOR (ll n)
{
    if (n<=0)
        return 0;
    if (n%4==0)
        return n;
    else if (n%4==1)
        return 1;
    else if (n%4==2)
        return n+1;
    else
        return 0;
}

main()
{
    fast;
    ll a,b;
    cin>>a>>b;
    cout<<(XOR(b)^XOR(a-1))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

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

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

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

ll dp[55][55][3000];

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

    int N, A; cin >> N >> A;
    vector<int> x(N);
    rep(i, 0, N) cin >> x[i];

    dp[0][0][0]=1;
    rep(i, 0, N) rep(j, 0, N+1) rep(k, 0, 2510){
        if(j>0 && k>=x[i]) dp[i+1][j][k] += dp[i][j-1][k-x[i]];
        dp[i+1][j][k] += dp[i][j][k];
    }

    ll ans=0;
    rep(j, 1, N+1) ans += dp[N][j][j*A];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 66560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define mll map<ll, ll>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

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;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  ll n, k;
  cin >> n >> k;
  vll a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  mll mp;
  rep(i, n) mp[a[i]] += b[i];
  ll cta = 0;
  for (auto i : mp) {
    cta += i.se;
    if (cta >= k) {
      out(i.fi);
      return;
    }
  }
}
int main(void) { solve(); }


Measured memory_bytes: 8752
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H = INT()
W = INT()
N = INT()

print(ceil(N/max(H,W)))

Measured memory_bytes: 4464
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
//#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

LL xx1, yy1, xx2, yy2, xx3, yy3;
const LL MAXN = 1e9;

void hora(int tc) {
	LL s;
	cin>>s;
	xx1 = yy1 = 0;
	xx2 = MAXN;
	yy2 = 1;
	yy3 = s / MAXN + 1;
	xx3 = MAXN - (s % MAXN);
	if(xx3 == MAXN) xx3 = 0, yy3--;
	cout<<xx1<<" "<<yy1<<" "<<xx2<<" "<<yy2<<" "<<xx3<<" "<<yy3<<endl;
}

int main(){
//	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,k;
    bool arr[101];
    cin>>n>>k;
    for(int i=0;i<101;i++)arr[i]=false;
    for(int i=0;i<k;i++){
    	int c;
    	cin>>c;
    	for(int j=0;j<c;j++){
    		int d;
    		cin>>d;
    		if(!arr[d])arr[d]=true;
    	}
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    	if(!arr[i]){cnt++;}
    cout<<cnt<<endl;
    return 0;
}

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

int main(){
    int Q;
    cin>>Q;
    string now;
    for(int i=0;i<Q;i++){
        cin>>now;
        int ans=0;
        for(;;){
            if(now.size()==1) break;
            int ma=0;
            for(int j=1;j<now.size();j++){
                ma=max(ma,stoi(now.substr(0,j))*stoi(now.substr(j,now.size()-j)));
            }
            now=to_string(ma);
            ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define clear(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define mset(a, b) memset(a, b, sizeof(a))
#define Rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define dRep(i, a, b) for(int i = (a); i >= (b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define un unsigned
#define ll long long
#define db double
#define dbg cout<<"c "

template<typename _T>
inline void read(_T &dig) {
	int flg; char c;
	flg = dig = 0;
	while (c = getchar(), !isdigit(c)) if (c == '-') flg = 1;
	while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
	if (flg) dig = -dig;
}

template <typename _T, typename ...Args>
inline void read(_T &x, Args &...args) {
	read(x);
	read(args...);
}

const int N = 4;

int main() {
	string s;
	cin >> s;
	if (s == "SSS") printf("0");
	else if (s == "SRR" || s == "RRS") puts("2");
	else if (s == "RRR") puts("3");
	else puts("1");
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
    return 0;
}

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

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n,x,d;cin>>n>>x>>d;
  map<int, vector<pii>> z;
  int ans = 0;

  if (x==0 && d==0){
    cout << 1 << endl;
    return 0;
  }

  if (d==0){
    cout << n+1 << endl;
    return 0;
  }

  if (d<0){
    int last = x+(n-1)*d;
    x = last;
    d = -d;
  }
  dump(x, d);

  int l = 0;
  int r = 0;
  rep(a, 0, n+1){
    int add = (a*x)/d;
    int rem = (a*x)%d;
    if (rem<0){
      rem += d;
      add -= 1;
    }
    dump(a,l,r);

    ans += r-l+1;
    if (sz(z[rem])>0){
      auto tmp = *(z[rem].rbegin());
      int preladd = tmp.first;
      int preradd = tmp.second;
      int dec = max(0LL, min(add+r, preradd) - max(add+l, preladd) + 1);
      dump(preladd, preradd, add+l, add+r, dec);
      ans -= dec;
    }
    z[rem].pb(mp(add+l, add+r));

    l += a;
    r += n-(a+1);
  }
  dump(z);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 22144
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<long long> s(n + 1, 0);
    for (int i = 0; i < n; i++) {
        s[a[i]]++;
    }

    long long r = 0;
    for (int i = 1; i <= n; i++) {
        r += s[i] * (s[i] - 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        cout << r - s[a[i]] * (s[a[i]] - 1) / 2 + (s[a[i]] - 1) * (s[a[i]] - 2) / 2 << endl;
    }
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
int main()
{
	int N, M, C;
	std::vector<int> B;
	std::vector<std::vector<int>> A;
	int l;
	std::cin >> N >> M >> C;
	for (int i = 0; i < M; i++)
	{
		std::cin >> l;
		B.push_back(l);
	}
	for (int i = 0; i < N; i++)
	{
		std::vector<int> al;
		for (int j = 0; j < M; j++)
		{
			std::cin >> l;
			al.push_back(l);
		}
		A.push_back(al);
	}
	int result, cnt;
	cnt = 0;
	for (int i = 0; i < N; i++)
	{
		result = 0;
		for (int j = 0; j < M; j++)
		{
			result += B[j] * A[i][j];
		}
		result = result + C;
		if (result > 0)
		{
			cnt++;
		}
	}
	std::cout << cnt << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int d[410][410];
int v,h,w;

int pton(pii x){
    int a=x.F;
    int b=x.S;
    return a*w+b;
}

void warshall_floyd(){
    rep(k,v)rep(i,v)rep(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int main() {
    cin >> h >> w;
    v=h*w;
    rep(i,v){
        rep(j,v){
            if(i==j)d[i][j]=0;
            else d[i][j]=mod;
        }
    }
    char c[h][w];
    rep(i,h){
        rep(j,w)cin >> c[i][j];
    }
    rep(i,h){
        rep(j,w){
            if(c[i][j]=='#')continue;
            rep(k,4){
                if(0<=i+dy[k] && i+dy[k]<h && 0<=j+dx[k] && j+dx[k]<w){
                    if(c[i+dy[k]][j+dx[k]]=='.'){
                        int p=pton(mp(i,j));
                        int q=pton(mp(i+dy[k],j+dx[k]));
                        d[p][q]=1;
                    }
                }
            }
        }
    }
    warshall_floyd();
    int mx=0;
    rep(i,v){
        rep(j,v){
            if(d[i][j]<=100000000)chmax(mx,d[i][j]);
        }
    }
    cout << mx;


}

/*



 */



Measured memory_bytes: 896
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		Vector2 beginPoint = new Vector2(decimal.Parse(input[0]), decimal.Parse(input[1]));
    Vector2 endPoint = new Vector2(decimal.Parse(input[2]), decimal.Parse(input[3]));
		long q = long.Parse(Console.ReadLine());

    for(long i = 0; i < q; i++)
    {
      string[] inputSub = Console.ReadLine().Split(' ');
      Vector2 answer = Vector2.Reflection(beginPoint, endPoint,
        new Vector2(decimal.Parse(inputSub[0]), decimal.Parse(inputSub[1])));
      Console.WriteLine(answer.x + " " + answer.y);
    }
	}
}

class Vector2//2次元ベクトル
{
  public Vector2 (decimal X, decimal Y)
  {
    this.x = X;
    this.y = Y;
  }

  public decimal x {private set; get;}
  public decimal y {private set; get;}

  public static Vector2 operator + (Vector2 ob1, Vector2 ob2)//ベクトルの基本演算
  {
    return new Vector2 (ob1.x + ob2.x, ob1.y + ob2.y);
  }
  public static Vector2 operator - (Vector2 ob1, Vector2 ob2)
  {
    return new Vector2 (ob1.x - ob2.x, ob1.y - ob2.y);
  }
  public static Vector2 operator * (decimal scalar, Vector2 ob)
  {
    return new Vector2 (ob.x * scalar, ob.y * scalar);
  }
  public static Vector2 operator * (Vector2 ob, decimal scalar)
  {
    return new Vector2 (ob.x * scalar, ob.y * scalar);
  }
  public decimal Length()//ベクトルの長さ
  {
    return x * x + y * y;
  }
  public static decimal DotProduct(Vector2 ob1, Vector2 ob2)//内積
  {
    return ob1.x * ob2.x + ob1.y * ob2.y;
  }

  public static Vector2 Projection(Vector2 beginPoint, Vector2 endPoint, Vector2 point)//点の射影
  {
    Vector2 segment = endPoint - beginPoint;
    decimal ratio = Vector2.DotProduct(point - beginPoint, segment) / segment.Length();
    return beginPoint + segment * ratio;//始点にたす
  }

  public static Vector2 Reflection(Vector2 beginPoint, Vector2 endPoint, Vector2 point)
  {
    Vector2 middlePoint = Vector2.Projection(beginPoint, endPoint, point);
    Vector2 memo = middlePoint - point;
    return point + 2*memo;
  }
  
}



Measured memory_bytes: 17948
import fractions
A,B,K=map(int,input().split(' '))

gcd=fractions.gcd(A,B)
k=0
if gcd==1:
  print(1)
else:
  for i in reversed(range(1,gcd+1)):
    if gcd%i==0:
      k+=1
      if k==K:
        print(i)
        break


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

// End of Template //



int main() {

    lint N, M;
    cin >> N >> M;
    if (M == 1 || N == 1) {
        cou(1);
        exit(0);
    }
    lint K = (N * M + 1) / 2;
    cout << K << endl;
}


Measured memory_bytes: 256
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
if n == 1:
	print(1)
else:
	lcm = a[0] * a[1] // gcd(a[0], a[1])
	for x in a[2:]:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= MOD
	ans = 0
	for x in a:
		ans += lcm * pow(x, MOD-2, MOD)
		ans %= MOD
	print(ans)

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

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

  int cnt = 0;
  int num[100010] = {};
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    num[a]++;
  }

  int sum = num[0] + num[1] + num[2];
  for (int i = 2; i < 100010; ++i)
  {
    sum = max(sum, num[i - 2] + num[i - 1] + num[i]);
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int n;
    scanf("%d", &n);
    int ary[n];

    REP(i, n) {
        scanf("%d", &ary[i]);
    }

    bool state = false;
    deque< int > q;

    REP(i, n) {
        if (state) {
            q.push_front(ary[i]);
            state = !state;
        } else {
            q.push_back(ary[i]);
            state = !state;
        }
    }

    if (state) {
        for (int i = n - 1; i >= 0; --i) {
            if (i != n - 1) printf(" ");
            printf("%d", q[i]);
        }
    } else {
        for (int i = 0; i < n; ++i) {
            if (i) printf(" ");
            printf("%d", q[i]);
        }
    }

    OUT("");

    return 0;
}



Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define N 605
#define LL long long
using namespace std;

int main()
{
	LL q,h,s,d,n;
	while(~scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n))
	{
		LL x,y;
		x=q*4;
		y=q*8;
		x=min(x,h*2);
		y=min(y,h*4);
		x=min(x,s);
		y=min(y,s*2);
		y=min(y,d);
		printf("%lld\n",n/2*y+(n&1)*x);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	char a[2],b[2];

	scanf("%s %s",a,b);

	if(a[0] == b[0]){

		printf("H\n");

	}else{

		printf("D\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ASandglass2 {
public:
	void solve(istream& in, ostream& out) {
        ll x,t; in >> x >> t;
        if(x - t >= 0) out << x - t << endl;
        else out << 0 << endl;
	}
};

int main() {
	ASandglass2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
  int X;
  cin >> X;
  if (X >= (int)ceil((X % 100) / 5.0) * 100) {
    printf("1\n");
  } else {
    printf("0\n");
  }
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// w, r, b
// w, b, r
// r, w, b
// r, b, w
// b, w, r
// b, r, w
int hori[6] = {5, 3, 4, 1, 2, 0};
int vert[6] = {2, 4, 0, 5, 1, 3};
int top[6] = {0, 0, 1, 1, 2, 2};
char WRB[] = "WRB";
struct S{
  vector<int> grid;
  int time;
};
int main(){
  // white, red, blue
  int sx, sy;
  while(cin >> sx >> sy && sx){
    sx--; sy--;
    char goal[3][3];
    REP(i, 3) REP(j, 3) cin >> goal[i][j];
    vector<int> goal_v;
    REP(i, 3) REP(j, 3) {
      if(goal[i][j] == 'E') goal_v.push_back(-1);
      REP(k, 3) if(WRB[k] == goal[i][j]) goal_v.push_back(k);
    }
    S start;
    start.time = 0;
    REP(i, 3) REP(j, 3){
      if(sy == i && sx == j) start.grid.push_back(-1);
      else start.grid.push_back(0);
    }
    queue<S> que;
    que.push(start);
    static bool used[1700000][9] = {};
    memset(used, 0, sizeof(used));
    int ans = -1;
    int pow6[10] = {};
    pow6[0] = 1; REP(i, 9) pow6[i + 1] = pow6[i] * 6;
    while(!que.empty()){
      S s = que.front(); que.pop();
      if(s.time > 30) break;
      int hstar = 0;
      REP(i, 9) if(s.grid[i] != -1 && top[s.grid[i]] != goal_v[i]) hstar ++;
      if(hstar == 0){
        ans = s.time;
        break;
      }
      if(s.time + hstar > 30) continue;
      REP(y, 3) REP(x, 3) {
        if(s.grid[y * 3 + x] == -1){
          REP(r, 4){
            int fx = x + dx[r];
            int fy = y + dy[r];
            if(!valid(fx, fy, 3, 3)) continue;
            S next = s;
            next.time++;
            next.grid[y * 3 + x] = (r % 2 ? vert[s.grid[fy * 3 + fx]] : hori[s.grid[fy * 3 + fx]]);
            next.grid[fy * 3 + fx] = -1;
            int hash = 0;
            int c = 0;
            REP(i, 9) if(next.grid[i] != -1) hash += next.grid[i] * pow6[c++];
            if(used[hash][fy * 3 + fx]) continue;
            used[hash][fy * 3 + fx] = true;
            que.push(next);
          }
        }
      }
    }
      cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 35824
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int h, w;
string s[2020];
int x[2020][2020], y[2020][2020];

int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#') continue;
			int k = 0;
			while(j+k < w && s[i][j+k] == '.'){
				k++;
			}
			for(int l = 0; l < k; l++){
				x[i][j+l] = k;
			}
			j += k;
		}
	}
	
	for(int i = 0; i < w; i++){
		int cnt = 0;
		for(int j = 0; j < h; j++){
			if(s[j][i] == '#') continue;
			int k = 0;
			while(j+k < h && s[j+k][i] == '.'){
				k++;
			}
			for(int l = 0; l < k; l++){
				y[j+l][i] = k;
			}
			j += k;
		}
	}
	
	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#') continue;
			ans = max(ans, x[i][j]+y[i][j]-1);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n, i;
  cin >> n;

  bool flag = 0;
  REP(i, 1, 10){
      if(n % i == 0 && n/i/10 == 0){
        flag = 1;
        break;
      }
  }
  cout << ((flag) ? "Yes" : "No") << endl;

  return 0;
}


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

/*
  REMEMBER:
  1.Think TWICE, code ONCE!
  Are there any counterexamples to your algo?
	
  2.Be careful about the BOUNDARIES in your algo!
  N=1? P=1? Is P a prime? Something about 0?
	
  3.Never make STUPID MISTAKES!
  Integer overflow? Array size? Time complexity? Memory usage? Precition error?
*/

int main(){
	string s; cin >> s;
	int cnt1 = (find(s.begin() , s.end() , 'N') != s.end()) + (find(s.begin() , s.end() , 'S') != s.end()) ,
		cnt2 = (find(s.begin() , s.end() , 'E') != s.end()) + (find(s.begin() , s.end() , 'W') != s.end());
	puts(cnt1 % 2 || cnt2 % 2 ? "No" : "Yes");
	return 0;
}


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    ll W,a,b,tmp,cmp,ans=0;
    cin >> W >> a >> b;
    tmp = max(a,b);
    cmp = min(a,b);
    if(cmp + W < tmp) {
        ans = tmp - cmp - W;
    }else {
        ans = 0;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define ll long long
#define hh puts("")
#define pc putchar
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
int n;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
    return ret*ff;
}
void write(int x){
    if(x<0){x=-x;putchar('-');}
    if(x>9) write(x/10);
    putchar(x%10+48);
}
void writeln(int x){write(x),hh;}
void writesp(int x){write(x),pc(' ');}
void add(int x,int y){
	writesp(x),writeln(y);
}
signed main(){
	n=read();
	for(int i=0;i<=18;i++){
		if(n==(1<<i)){
			printf("No");
			return 0;
		}
	}
	puts("Yes");
	if(n&1){
		for(int i=2;i<=n;i+=2){
			add(i,i+1);
			add(i+1,1);
			add(1,i+n);
			add(i+n,i+n+1);
		}
		add(1+n,2);
		return 0;
	}
	else{
		for(int i=2;i<=n-1;i+=2){
			add(i,i+1);
			add(i+1,1);
			add(1,i+n);
			add(i+n,i+n+1);
		}
		add(1+n,2);
		int t;
		for(int i=18;i>=0;i--){
			if(n&(1<<i)){
				t=i;
				break;
			}
		}
		int to=(1<<t)+1;
		add(n,to);
		add(n+n,(n^(to-1))+n);
	}
    return 0;
}

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

struct tEdge{
	short to, val;
	tEdge( short t, short v ){
		to = t;		val = v;
	}
};

bool operator<( const tEdge &l, const tEdge &r ){
	return ( l.val > r.val );
}

int main(){
	vector< vector<short> > cost, time;
	priority_queue< tEdge >	edges;
	vector<bool> checked;
	int n, m;
	while( cin >> n >> m, n||m ){
		cost.resize(m+1);
		time.resize(m+1);
		checked.resize(m+1);
		for( int i=1; i<=m; i++ ){
			cost[i].resize(m+1);
			time[i].resize(m+1);
			for( int j=1; j<=m; j++ ){
				cost[i][j] = time[i][j] = -1;
			}
		}
		for( int i=0; i<n; i++ ){
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			cost[a][b] = cost[b][a] = c;
			time[a][b] = time[b][a] = t;
		}
		int k;
		cin >> k;
		for( int i=0; i<k; i++ ){
			int p, q, r;
			cin >> p >> q >> r;
			if( p==q ){	cout << 0 << endl;	continue;	}
			while( !edges.empty() )	edges.pop();
			for( int j=1; j<=m; j++ ){
				if( r==0 && cost[p][j]!=-1 )		edges.push( tEdge( j, cost[p][j] ) );
				else if( r==1 && time[p][j]!=-1 )	edges.push( tEdge( j, time[p][j] ) );
				checked[j] = false;
			}
			checked[p] = true;
			while(1){
				tEdge e(0,0);
				do{
					e = edges.top();
					edges.pop();
				}while( checked[e.to] );
				if( e.to == q ){
					cout << e.val << endl;
					break;
				}
				checked[e.to] = true;
				for( int x=1; x<=m; x++ ){
					if( !checked[x] ){
						if( r==0 && cost[e.to][x]!=-1 ){
							edges.push( tEdge( x, e.val+cost[e.to][x] ) );
						}else if( r==1 && time[e.to][x]!=-1 ){
							edges.push( tEdge( x, e.val+time[e.to][x] ) );
						}
					}
				}
			}
		}
	}	
	return 0;
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code


int main()
{
	int n;
	cin>>n;
	int curr = 1;
	int cnt = 0;
	rep(i, 0, n)
	{
		int x;
		cin>>x;
		if(x == curr)
		{
			curr++;
		}
		else
			cnt++;
	}
	if(cnt == n) puts("-1");
	else cout<<cnt<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
 
typedef long long ll;
 
int N,x;
int a[100];
int main(){
        scanf("%d %d",&N,&x);
        for(int i = 0; i < N; i++){
                scanf("%d",a+i);
        }
        std::sort(a,a+N);
 
        int c = 0;
        while(c < N && x >= a[c] ){
                x -= a[c];
                c++;
        }
  	    ll ans = 0;
  		if(c == N && x > 0) ans = N-1;
        else ans = c;
        
  		printf("%d\n",ans);        
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
long long dp[3010][3010][5];
int a,b;
long long v[3010][3010];
int main(){
	cin>>n>>m>>k;
	long long c;
	for(int i=1;i<=k;i++){
		cin>>a>>b>>c;
		v[a][b]=c;
	}
	long long mx=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int kk=1;kk<=3;kk++){
				dp[i][j][kk]=max(dp[i-1][j][3]+v[i][j],max(dp[i][j-1][kk-1]+v[i][j],dp[i][j-1][kk]));
				mx=max(mx,dp[i][j][kk]);
			}
		} 
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 426856
n = int(input())
a = list(map(int, input().split()))
d = {1:0, 2:0, 4:0}
for i in a:
  if i % 4 == 0:
    d[4] += 1
  elif i % 2 == 0:
    d[2] += 1
  else:
    d[1] += 1
if d.get(2, 0) >= 1:
  d[1] += 1
if d.get(1, 0) <= d.get(4, 0)+1:
  print("Yes")
else:
  print("No")


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
vector<vector<PLL>> adj;
//ll c[10][10];
void solve()
{
    ll r,fuck;
    cin>>r>>fuck;
    //adj.assign(10,vector<PLL>());
    vector<VL> c(10,VL(10));
    fr(i,0,10)
    {
        fr(j,0,10)
        {
            cin>>c[i][j];            
        }
    }
    fr(k,0,10)
    {
        fr(i,0,10)
        {
            fr(j,0,10)
            {
                if(c[i][j]>c[i][k]+c[k][j])
                {
                    c[i][j]=c[i][k]+c[k][j];
                }
            }
        }
    }
    //vector<VL> mat(r,VL(c));
    ll ans=0;
    fr(i,0,r)
    {
        fr(j,0,fuck)
        {
            ll x;
            cin>>x;
            if(x!=-1)
            {
                ans+=c[x][1];
            }
        }
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;
    string u;
    double x;
    double all =0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> x >> u;
        if(u== "BTC") x*=380000.0;
        all += x;
    }
    cout << all << endl;        
}

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

using namespace std;

int main() {
  int n = 0;
  long long h = 0;
  cin >> n >> h;
  vector<long long> b(n);
  long long max_a = 0;
  for (int i=0; i<n; i++) {
    long long buf = 0;
    cin >> buf >> b.at(i);
    max_a = max(max_a, buf);
  }
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  int cnt = 0;
  long long dam = 0;
  for (int i=0; i<n && b.at(i) > max_a; i++) {
    dam += b.at(i);
    cnt++;
    if (dam >= h) break;
  }
  if (dam < h) {
    cnt += ((h-dam)%max_a == 0 ? (h-dam)/max_a : (h-dam)/max_a + 1);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		char[][] a = new char[N][N];
		char[][] b = new char[M][M];
		for (int i = 0; i < N; i++) {
			a[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < M; i++) {
			b[i] = sc.next().toCharArray();
		}

		boolean exist = false;
		for (int y = 0; y < N; y++) {
			for (int x = 0; x < N; x++) {
				if(y + M - 1 >= N || x + M - 1 >= N) continue;

				boolean match = true;
				for (int y2 = 0; y2 < M; y2++) {
					for (int x2 = 0; x2 < M; x2++) {
						if(a[y + y2][x + x2] != b[y2][x2]) match = false;
					}
				}
				if(match) exist = true;
			}
		}

		if(exist) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

using namespace std;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	
	vector<int> A(n), B(m);
	
	vector<long long> a(n + 1), b(m + 1);
	
	for(int i = 0; i < n; i++) {
		cin >> A[i];
		a[i + 1] = a[i] + A[i];
	}
	
	for(int i = 0; i < m; i++) {
		cin >> B[i];
		b[i + 1] = b[i] + B[i];
	}
	
	int books = 0, j = m;
	
	for(int i = 0; i <= n; i++) {
		if(a[i] > k) break;
		
		while(b[j] > k - a[i]) j -= 1;
		
		books = max(books, i + j);
	}
  cout << books;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N;
ll x[100050];

int main() {
    //cout.precision(10);
    cin >> N;
    ll out = 0;
    ll ans = 1;
    for(ll i = 1; i <= N; i++) {
        cin >> x[i];
        if((i - out - 1) * 2 >= x[i]) {
            ans = ans * (i - out) % mod;
            out++;
        }
    }
    for(ll i = out; i < N; i++) {
        ans = ans * (N - i)% mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())

nlist = [] * N
for i in range(N):
    nlist.append([])
for i in range(M):
    X, Y, Z = map(int, input().split())
    X -= 1
    Y -= 1
    nlist[X].append(Y)
    nlist[Y].append(X)

visit = [False] * N
ans = 0
for i in range(N):
    if visit[i]:
        continue
    ans += 1
    visit[i] = True
    vlist = nlist[i]
    while vlist:
        tmp = []
        for to in vlist:
            if visit[to]:
                continue
            visit[to] = True
            tmp.extend(nlist[to])
        vlist = tmp

print(ans)


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

int main(){
    int k;
    cin >> k;
    vector<int> v(33);
    v[1]=1;
    v[2]=1;
    v[3]=1;
    v[4]=2;
    v[5]=1;
    v[6]=2;
    v[7]=1;
    v[8]=5;
    v[9]=2;
    v[10]=2;
    v[11]=1;
    v[12]=5;
    v[13]=1;
    v[14]=2;
    v[15]=1;
    v[16]=14;
    v[17]=1;
    v[18]=5;
    v[19]=1;
    v[20]=5;
    v[21]=2;
    v[22]=2;
    v[23]=1;
    v[24]=15;
    v[25]=2;
    v[26]=2;
    v[27]=5;
    v[28]=4;
    v[29]=1;
    v[30]=4;
    v[31]=1;
    v[32]=51;
    cout << v[k] << endl;
}

//2, 2, 5, 4, 1, 4, 1, 51

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] A = new char[H][W];
		for (int i = 0; i < H; i++) {
			A[i] = sc.next().toCharArray();
		}

		for (int i = 0; i < H - 1; i++) {
			for (int j = 0; j < W - 1; j++) {
				if (A[i][j + 1] == '#' && A[i + 1][j] == '#') {
					System.out.println("Impossible");
					return;
				}
			}
		}

		System.out.println("Possible");
	}

	public static class Route {
		public List<Position> route = new ArrayList<>();

		public Route(List<Position> prev, Position next) {
			route = new ArrayList<>(prev);
			route.add(next);
		}

		public Position getLast() {
			return route.get(route.size() - 1);
		}
	}

	public static class Position {
		public int x;
		public int y;

		public Position(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x;
			result = prime * result + y;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Position other = (Position) obj;
			if (x != other.x)
				return false;
			if (y != other.y)
				return false;
			return true;
		}

	}
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    
    if (s[0] == '0' || s[n-2] == '0' || s[n-1] == '1') {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 1; i < n/2; i++) {
        if (s[i] != s[n-2-i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    int cnt = 1;
    cout << "1 2" << endl;
    for (int i = 3; i <= n; i++) {
        cout << cnt << " " << i << endl;
        if (i < n && s[i-2] == '1') cnt = i;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

vector<int> Zalgo(const string &S) {
    int N = (int)S.size();
    vector<int> res(N);
    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) {++i; continue;}
        int k = 1;
        while (i+k < N && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}


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

    int res = 0;
    for (int i = 0; i < N; ++i) {
        string T = S.substr(i);
        auto lcp = Zalgo(T);

        for (int j = 0; j < T.size(); ++j) {
            int l = min(lcp[j], j);
            res = max(res, l);
        }
    }
        
    cout << res << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
using ll = long long;
using Graph = vector<vector<int>>;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);

    vector<int> P, M;
    rep(i, N)
    {
        if (A.at(i) >= 0)
            P.push_back(A.at(i));
        else
            M.push_back(A.at(i));
    }

    int Psize = P.size(), Msize = M.size();
    bool ok = false; //積が正
    if (Psize > 0)
    {
        if (N == K)
            ok = (Msize % 2 == 0);
        else
            ok = true;
    }
    else
    {
        ok = (K % 2 == 0);
    }

    mint res = 1;

    // 積が負
    if (!ok)
    {
        sort(A.begin(), A.end(), [](int x, int y) { return abs(x) < abs(y); });
        rep(i, K) res *= A.at(i);
    }
    else
    {
        sort(P.begin(), P.end());
        sort(M.rbegin(), M.rend());
        if (K % 2 == 1)
        {
            res *= P.back();
            P.pop_back();
        }
        vector<ll> tmp;
        while (P.size() >= 2)
        {
            ll x = P.back();
            P.pop_back();
            x *= P.back();
            P.pop_back();
            tmp.push_back(x);
        }

        while (M.size() >= 2)
        {
            ll x = M.back();
            M.pop_back();
            x *= M.back();
            M.pop_back();
            tmp.push_back(x);
        }
        sort(tmp.rbegin(), tmp.rend());
        rep(i, K / 2) res *= tmp.at(i);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6372
def main():
    from math import ceil
    d, g, *pc = map(int, open(0).read().split())
    p, c = pc[::2], pc[1::2]

    ans = sum(p)

    for i in range(2 ** d - 1):
        tmp = g
        count = 0
        # i は集合の表現 ex 1001101
        for j in range(d):
            # iのj桁目が1はどうか
            if i >> j & 1:
                # process
                tmp -= (c[j] + 100 * (j + 1) * p[j])
                count += p[j]

        j = d - 1
        while i >> j & 1:
            j -= 1

        if tmp <= 0:
            ans = min(ans, count)
            continue
        else:
            k = ceil(tmp / ((j + 1) * 100))
            if k >= p[j]:
                continue
            else:
                count += k
                ans = min(count, ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

ans = 0

(A+1).times do |a|
    (B+1).times do |b|
        (C+1).times do |c|
            if X == a*500 + b*100 + c*50
                ans += 1
            end
        end
    end
end

puts ans

Measured memory_bytes: 14272
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])
    A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
         1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

    return str(A[k-1])


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 3060