akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
#include <queue>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

ull dfs(ull n, string x, ull res) {
  if (std::stoul(x) > n) {
    return res;
  }

  ull r = res;
  bool seven = false;
  bool five = false;
  bool three = false;
  for (ull i=0; i < x.size(); i++) {
    if (x[i] == '7') {
      seven = true;
    } else if (x[i] == '5') {
      five = true;
    } else if (x[i] == '3') {
      three = true;
    }
  }
  if (seven && five && three) {
    r += 1;
  }

  r += dfs(n, x + "7", res);
  r += dfs(n, x + "5", res);
  r += dfs(n, x + "3", res);

  return r;
}

int main() {
  //std::cout << std::fixed << std::setprecision(10);
  ull n;
  cin >> n;

  cout << dfs(n, "0", 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ll Kth_root(ll x,int k){
    if(x==1) return 1;
    if(k>64) return 1;
    ll l=0,r=numeric_limits<ll>::max();
    while(r-l>1){
        ll mid=(l+r)/(ll)2;
        ll d=mid;
        bool larger=false;
        rep(i,k-1){
            if(d>x/mid+(ll)1){
                larger=true;
                break;
            }
            d*=mid;
        }
        if(d>x) larger=true;
        if(larger) r=mid;
        else l=mid;
    }
    return l;
}

ll n,a;

void solve(){
    cin >> n >> a;
    ll ans=INF;
    Rep(k,1,60){
        ll s=Kth_root(n,k);
        ll m=1;rep(j,k) m*=s;
        ll cnt=0;
        while(m<n){
            m/=s;
            m*=s+1;
            cnt+=1;
        }
        //cout << k << endl;
        //cout << s << ":" << k-cnt << " & " << s+1 << ":" << cnt << " " << endl;
        ans=min(ans,s*(k)+cnt+(k-1)*a);
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3664
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    long long count = 0;
    for(int c = 1; c < N; ++c) {
        int maxA = sqrt(N-c);
        for(int a = 1; a <= maxA; ++a){
            if((N-c) % a == 0){
                count += 2;
            }
        }
        if(maxA*maxA == (N-c)){
            count--;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <cstring>
#include <bits/stdc++.h>
#include<algorithm>

using namespace std;

const int N = 1e5+6, M = 1e5+5, OO = 0x3f3f3f3f;
int n , h[N] ,op1 ,op2,dp[N] ;
int frog(){
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);


    for(int i = 3; i <= n; i++){


        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                    dp[i - 1] + abs(h[i] - h[i - 1]));
    }


    return dp[n];
}

int main(){
  scanf("%d",&n );
  for(int i = 1 ; i<=n ;i++)
    scanf("%d",h+i );
  printf("%d\n",frog() );
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int r = ni();
		int d = ni();
		int x = ni();
		for(int i = 0; i < 10; i++) {
			x = r*x-d;
			System.out.println(x);
		}		
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21204
#include <stdio.h>
int main(){
    long long a, b, k;
    scanf("%lld%lld%lld", &a, &b, &k);

    if( a-k < 0 ){
        if( a+b-k < 0 ){
            a=0;
            b=0;
        }else{
            b-=(k-a);
            a=0;
        }
    }else{
        a-=k;
    }
    printf("%lld %lld\n", a, b);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long h;
  cin>>h;
  long long ans=0;
  long long factor=1;
  while(h>0){
    ans+=factor;
    h=h/2;
    factor=factor*2;
  }
  cout<<ans<<"\n";
  return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		string tmpl;
		for(int i = 0; i < n; ++i)
		{
			tmpl += "IO";
		}
		tmpl += "I";
		int m;
		cin >> m;
		string s;
		cin >> s;
		int ans = 0;
		for(int i = 0; i < m; ++i)
		{
			if(s[i] == 'I' && i + tmpl.size() < m)
			{
				int same_num = 0;
				bool flag = true;
				for(int j = 1; j < tmpl.size(); ++j)
				{
					if(s[i + j] != tmpl[j])
					{
						flag = false;
						break;
					}
					++same_num;
				}
				if(flag)
				{
					++ans;
					
				}
				else
				{
					i += same_num;
				}
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 2124
def main():
  S = input()
  day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
  count = 7
  for i in day:
    if S == i:
        print(count)
    count -= 1

if __name__ == '__main__':
  main()


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

class union_find {
	const int N; // the number of nodes
	int M; // the number of trees
	std::vector<int> parent;

public :
	union_find(const int& n) : N(n), M(N), parent(n, -1) {}

	const int& root(const int& k) {return ((parent[k] == -1)?k:(parent[k] = root(parent[k])));}

	bool is_united(const int& i, const int& j) {return (root(i) == root(j));}

	bool unite(int i, int j) {
		i = root(i); j = root(j);
		if (i == j) return false;
		parent[j] = i;
		M--;
		return true;
	}

	const int& count_trees() const {return M;}
};

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

	int N, M;
	std::cin >> N >> M;
	union_find uf(N);

	while (M--) {
		int A, B;
		std::cin >> A >> B;
		uf.unite(A - 1, B - 1);
	}
	std::cout << uf.count_trees() - 1 << '\n';
}

Measured memory_bytes: 3700
K = int(input())
AB = input()
ABB = AB.split()
A = int(ABB[0])
B = int(ABB[1])
C = 0

for i in range(A, B+1):
  if i % K ==0:
    print('OK')
    C = 1
    break
if C == 0:
  print('NG')
    

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
int main(void){
    
     for (int i = 1; i > 0; i ++)
            {
                int a, b;
                char op;
                cin >> a >> op >> b;
                if ( op == '+' ){
                    cout << a + b <<endl;
                } else if ( op == '-' ){
                    cout << a-b <<endl;
                } else if ( op == '*' ){
                    cout << a * b << endl;
                } else if ( op == '/' ){
                    cout << a/b << endl;
                } else {
                break;
                }
            }

}


Measured memory_bytes: 3120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int kMaxN = 41, kMod = 1e9 + 7;
int n, x, y, z, result;
ll f[kMaxN][1 << 17], rem[kMaxN];

ll DP(int pos, int stat) {
  if (~f[pos][stat])
    return f[pos][stat];
  if (pos == n)
    return 0;
  ll ret = 0;
  for (int i = 1; i <= 10; ++i) {
    int nxt = (stat << i) | 1;
    if ((nxt & result) == result) {
      ret += rem[n - pos - 1];
    } else ret += DP(pos + 1, nxt & ((1 << 17) - 1));
  }
  return f[pos][stat] = ret % kMod;
}

int main() {
  memset(f, 0xff, sizeof f);
  rem[0] = 1;
  for (int i = 1; i < kMaxN; ++i)
    rem[i] = rem[i - 1] * 10LL % kMod;
  scanf("%d%d%d%d", &n, &x, &y, &z);
  result = (1 << (x)) | (1 << (x + y)) | (1 << (x + y + z));
  printf("%lld\n", DP(0, 1));
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    bool ans = true;
    rep(i, s.length()) {
        if ((i + 1) & 1) {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                ans = false;
            }
        } else {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                ans = false;
            }
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(a, b) << " " << max(0, a+b-n) << "\n";
    return 0;
}

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

typedef long long lint;

int main(){
    int N;
    lint A[100001];
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    A[N]=0;

    lint sum=0;
    for(int i=0;i<N;i++){
        sum+=A[i]/2;
        A[i]=A[i]%2;
        if(A[i]>0 && A[i+1]>0){
            sum++;
            A[i]--;
            A[i+1]--;
        }
    }

    cout << sum << endl;
    return 0;
}//

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int sum[10000001];
int main()
{
	int N;
	cin >> N;
	ll ans = 0;
	fx(N) {
		ans += ((ll)x + 1) * (sum[x + 1] + 1);
		int i = 2;
		while (i*(x+1)<=N) {
			sum[i * (x + 1)]++;
			i++;
		}
	}
	ce(ans)
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int max = 0, min = 1000000000;
	for(int i=0;i<n;++i){
		cin >> a[i];
		if(max < a[i]) max = a[i];
		if(min > a[i]) min = a[i];
	}
	cout << max-min << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
	private static BufferedReader br = null;
	
	public static void main(String[] args) {
		String[] strs = read(1)[0].split(" ");
		int n = Integer.parseInt(strs[0]);
		int x = Integer.parseInt(strs[1]);
		strs = read(1)[0].split(" ");
		int[] xs = new int[n + 1];
		for (int i = 0; i < n; i++) {
			xs[i] = Integer.parseInt(strs[i]);
		}
		xs[n] = x;
		
		Arrays.sort(xs);
		
		int d = 0;
		int i = 0;
		for (i = 1; i < xs.length && d == 0; i++) {
			d = xs[i] - xs[i - 1];
		}
		for (; i < xs.length; i++) {
			if (xs[i] == xs[i - 1]) {
				continue;
			}
			
			int d2 = xs[i] - xs[i - 1];
			int tmp = 1;
			if (d2 > d) {
				while (d2 % (d / tmp) != 0) {
					tmp++;
				}
				d /= tmp;
			} else {
				while (d % (d2 / tmp) != 0) {
					tmp++;
				}
				d = d2 / tmp;
			}
		}
		
		System.out.println(d);
		
		close();
	}
	
	private static String[] read(int len) {
		List<String> strList = new ArrayList<>();
		
		try {
			if (br == null) {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
			
			for (int i = 0; i < len; i++) {
				strList.add(br.readLine());
			}
		} catch (IOException e) {
		}
		
		return strList.toArray(new String[0]);
	}
	
	private static void close() {
		try {
			if (br != null) {
				br.close();
			}
		} catch (IOException e) {
		}
	}
}


Measured memory_bytes: 40068
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}


//#########################################




int main() {

   int n=D();
    if(n>=3){
        cout<<n/3;

    } else
        cout<<"0";

}


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

int main()
{
    // 入力
    int X;
    string result;
    cin >> X;

    // 計算
    if (X >= 30){
        result = "Yes";
    } else {
        result = "No";
    }
    


    // 出力
    cout << result << endl;
    return 0;  
}


Measured memory_bytes: 3624
/*      ...वहां तूफान भी हार जाते हैं जहां कश्तियां जिद पर होती हैं !...        */
#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;

int h,w;
vector<vector<char>> vect(1003,vector<char>(1003));
vector<vector<ll>> dp(1003,vector<ll>(1003,-1));
ll dfs(int x,int y) {
    if(vect[x][y]=='#') return 0;
    if(dp[x][y]!=-1)    return dp[x][y];
    if(x==h && y==w)    return 1;
    if(x>h || y>w)  return 0;
    return dp[x][y]=(dfs(x,y+1)+dfs(x+1,y))%mod;
}
int main()  {
    fast;
    cin>>h>>w;
    fl(i,1,h+1) {
        fl(j,1,w+1) {
            cin>>vect[i][j];
        }
    }
    dfs(1,1);
    cout<<dp[1][1]%mod;
}

Measured memory_bytes: 9344
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int main(){
	
	while(true){
		
		long long int N, M;
		
		cin >> N >> M;
		if(N == 0 && M == 0){
			break;
		}
		
		long long int a[20];
		
		for(int i = 0; i < 20; i++){
			a[i] = 0;
		}
		
		for(int i = 0; i < N; i++){
			int num1, num2;
			cin >> num1 >> num2;
			a[num2] += num1;
		}
		
		long long int ans = 0;
		
		for(int i = 10; i >= 0; i--){
			long long int ret = max(0LL, a[i] - M);
			ans += ret * i;
			M = max(0LL, M - a[i]);
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main() {
    fastio
	ll n,t,i,j,x,k;
	string s;
	
	cin>>s;
	n=s.length();
	
	x=0,k=0;
	
	for(i=0;i<n;i++){
	    if(s[i]=='R') x++;
	    else{
	        k=max(k,x);
	        x=0;
	    }
	}
	k=max(k,x);
	cout<<k;
	
	
	return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
const int MAXN = 100000;
const int MAXK = 1000;
int x[MAXN + 5], y[MAXN + 5], c[MAXN + 5];
int y1[10 * MAXK + 5];
int main() {
	int N, K, Max = 0, cnt = 0;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++) {
		char ch;
		scanf("%d%d %c",&x[i],&y[i],&ch);
		x[i] = x[i] % (2*K);
		y[i] = y[i] % (2*K);
		if( ch == 'W' ) c[i] = 1;
		else c[i] = 0;
	}
	for(int i=0;i<=K;i++) {
		cnt = 0;
		memset(y1,0,sizeof(y1));
		for(int j=1;j<=N;j++) {
			int p = ( i <= x[j] && x[j] < i+K );
			int q = ( 0 <= y[j] && y[j] < K );
			if( p ^ q == c[j] ){
				cnt++;
				y1[y[j]] ++;
			}
			else {
				y1[y[j]] --;
			}
		}
		for(int j=0;j<=K;j++) {
			if( cnt > Max ) Max = cnt;
			if( N - cnt > Max ) Max = N - cnt;
			if( j != K )
				cnt = cnt - y1[j] - y1[K+j];
		}
	}
	printf("%d\n",Max);
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  ll N;
  cin>>N;
  vector<ll> B(N-1);
  cin>>B;
  vector<ll> A(N,B[0]);
  for(int i=1;i+1<N;i++){
    A[i]=min(B[i],B[i-1]);
  }
  A.back()=B.back();
  ll sum=0;
  for(auto &I:A){sum+=I;}
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
def h_grid1(MOD=10**9 + 7):
    H, W = [int(i) for i in input().split()]
    Grid = ['#' * (W + 1)] + ['#' + input() for _ in range(H)]  # 左と上を埋める

    # path[r][c]: マス(r, c)に(0-based)到達する経路の数
    path = [[0] * (W + 1) for _ in range(H + 1)]
    path[0][1] = 1  # path[1][1] = 1 (スタート地点) とするための便宜上の代入

    for row in range(1, H + 1):
        for col in range(1, W + 1):
            if Grid[row][col] == '.':
                path[row][col] = (path[row - 1][col] + path[row][col - 1]) % MOD
    return path[H][W]

print(h_grid1())

Measured memory_bytes: 43612
import java.util.*;

public class Main {

    private static int N;
    private static int M;
    private static int[] max;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        a = a.replaceAll("0", "");
        System.out.println(a.length());
    }
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n, k;
bool b[10];

bool read() {
    if (!(cin >> n >> k))
        return false;

    forn (i, k) {
        int x;
        cin >> x;
        b[x] = true;
    }

    return true;
}

void solve() {
    auto bad = [&](int n) { for (; n > 0; n /= 10) if (b[n % 10]) return true; return false; };
    for (; bad(n); ++n) { }
    cout << n << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 256
(defun input (n d)
  (let ((A (make-array (+ n d 1))))
    (dotimes (i n)
      (setf (aref A (+ i d)) (read)))
    A))
(defun solve (n A B)
  (unless (= (aref A n) (aref B 1))
    (return-from solve 0))
  (let ((ans 1))
    (loop for i from 1 to n
          for Ai = (aref A i) for Bi = (aref B i)
          for f1 = nil for f2 = nil
          if (= Ai (aref A (1- i))) do (setq f1 t)
          if (= Bi (aref B (1+ i))) do (setq f2 t)
          if (and f1 f2)
          do (progn (setq ans (* ans (min Ai Bi)))
                    (setq ans (mod ans 1000000007)))
          else if (and f1 (> Bi Ai))
          do (return-from solve 0)
          else if (and f2 (> Ai Bi))
          do (return-from solve 0)
          else if (and (not f1) (not f2) (not (= Ai Bi)))
          do (return-from solve 0))
    ans))
(let* ((n (read))
      (A (input n 1))
      (B (input n 1)))
  (format t "~A~%" (solve n A B)))

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;

int main() {
    cin >> n;

    set<string> m;
    REP(i, n) {
        string s;
        cin >> s;
        m.insert(s);
    }

    cout << m.size() << '\n';

    return 0;
}


Measured memory_bytes: 19188
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,L,sum=0,ans2=0,count=0;
    cin>>N>>L;
    int ans=abs(L);
    vector<int>taste(N,0);
    for(int i=0;i<N;i++){
        taste[i]=L+i;
        sum += taste[i];
        if(ans>abs(taste[i])){
            ans=abs(taste[i]);
            count=i;
        }
    }
    ans2=sum-taste[count];
    cout<<ans2<<endl;
    return 0;
}


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

long long int INF = -1000000000000000001;

int main(void) {

	long long int a, b, c, d;
	cin >> a >> b >> c >> d;

	long long int ans = INF;

	ans = max(ans, a*c);
		ans = max(ans, a*d);
		ans = max(ans, b*c);
		ans = max(ans, b*d);

		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        //String s = sc.next();
        
        if(n < 10){
            System.out.println(n);
        }else if(n<100){
            System.out.println(9);
        }else if(n<1000){
            System.out.println(n-90);
        }else if(n<10000){
            System.out.println(909);
        }else if(n<100000){
            System.out.println(n-9090);
        }else{
            System.out.println(90909);
        }
        
        //System.out.println(max);
    }
}

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;

//iostream::sync_with_stdio(false);

const int maxn = 1e4 + 5;


int main()
{
	int n;
	int x, y;
	cin >> n;
	cin >> x >> y;
	int k = 0;
	for (int i = x; i <= y; i++)
	{
		if (i % n == 0)
		{
			k++;
			break;
		}
	}
	if (k)cout << "OK";
	else cout << "NG";
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include<math.h>
#include <algorithm>
 
#define EPS 1e-10
 
using namespace std;
 
int func(double x1,double y1,double x2, double y2, double xp, double yp){
    double naiseki,norm1,norm2,gaiseki;
    norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
    naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
    gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
    if(gaiseki > EPS){
        return 1;
    }else if(gaiseki < -EPS){
        return -1;
    }
 
    if(naiseki < -EPS){
        return 2;
    }
 
    if(norm1 < norm2){
        return -2;
    }
    return 0;
}
 
 
int main(){
    double x1,x2,x3,x4,y1,y2,y3,y4;
    int q;
    scanf("%d",&q);
 
    for(int i=0;i<q;i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
 
        if(func(x1,y1,x2,y2,x3,y3)*func(x1,y1,x2,y2,x4,y4) <= 0 &&
                func(x3,y3,x4,y4,x1,y1) * func(x3,y3,x4,y4,x2,y2) <= 0){
            printf("1\n");
        }else{
            printf("0\n");
        }
    }
 
    return 0;
}


Measured memory_bytes: 2680
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map read . words <$> getLine

readIntlines :: Int -> IO [[Int]]
readIntlines n = map (map read . words) <$> replicateM n getLine

main :: IO ()
main = do
    [n] <- readInt
    a <- readInt
    [q] <- readInt
    bc <- readIntlines q
    VU.mapM_ print . VU.take q . VU.tail $ solve a bc

solve :: [Int] -> [[Int]] -> VU.Vector Int
solve a bc = runST $ VU.freeze =<< do
    vec <- VUM.new 100001
    ret <- VUM.new 100001
    forM_ a (\x -> do
        VUM.modify vec (+1) x
        VUM.modify ret (+x) 0
        )
    forM_ (zip [1..] bc) (\(i, [b, c]) -> do
        nb <- (VUM.read vec b)
        nc <- (VUM.read vec c)
        VUM.modify vec (+nb) c
        VUM.write vec b 0
        t <- VUM.read ret (i - 1)
        VUM.write ret i ((c - b) * nb + t)
        )
    return ret


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

double dp[301][301][301];

double solve(int x, int y, int z, int &n){

    if(x<0 || y<0 || z<0)
        return 0;

    if(x == 0 && y == 0 && z == 0)
        return 0;

    if(dp[x][y][z] > -0.9)
        return dp[x][y][z];

    double exp = n + x*solve(x-1,y,z,n) + y*solve(x+1,y-1,z,n) + z*solve(x,y+1,z-1,n);

    return dp[x][y][z] = exp/(x+y+z);

}

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

    memset(dp,-1,sizeof dp);

    int ones = 0, twos = 0, threes = 0;

    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a==1)
            ones++;
        else if(a==2)
            twos++;
        else    
            threes++;
    }

    cout<<fixed<<setprecision(10)<<solve(ones,twos,threes,n);

    return 0;
}


Measured memory_bytes: 216896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    int n; cin >> n;
    cout << (1000 - n % 1000) % 1000;

    return 0;
}


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

using namespace std;

int main(void)
{
    int n;
    cin >> n;
    vector<pair<int, int>> rank(n);
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        rank.at(i) = make_pair(temp, i + 1);
    }
    sort(rank.begin(), rank.end());
    for (int i = 0; i < n; i++)
    {
        int temp, ans;
        tie(temp, ans) = rank.at(i);
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>data(N);
  vector<int>result(1000005);
  for(int i=0;i<N;i++) cin >> data.at(i);
  for(int i=0;i<N;i++){
    int x=data.at(i);
    if(!result.at(x)==0){
      result.at(x)=2;
      continue;
    }
    for(int j=x;j<1000005;j+=x){
      result.at(j)++;
    }
  }
  int count=0;
  for(int i=0;i<N;i++){
    int x=data.at(i);
    if(result.at(x)==1) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 8012
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t) {
	stringstream ss;
	ss << f;
	ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain() {
	int n;
	cin >> n;
	ll C, K;
	cin >> C >> K;
	vll v(n);
	rep(i, n) cin >> v[i];
	sort(ALL(v));
	ll ans = 0;
	rep(i, n) {
		ans++;
		int M = min(i + C, (ll)n);

		if(v[M - 1] - v[i] <= K) {
			i = M - 1;
			continue;
		}
		// cout<<v[i]<<endl;
		int l = i;
		int r = M - 1;
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(v[mid] - v[i] <= K) {
				l = mid;
			}
			else {
				r = mid;
			}
		}
		i = l;
	}
	cout << ans << endl;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	mainmain();
}

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


int n, k, ans, a[200001], kin;
int main(){
    cin >> n >> k;

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

    sort(a, a + n + 1);

    int start;
    for(start=0; a[start] == 0; ++start);

    for(int i=0; i < kin - k; ++i, ++start) ans += a[start];

    cout << ans << endl; 
}



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

int n, k;
const long MAX = 100000;
long T[MAX];

int check(long long p){
	int i = 0;
	for (int j = 0; j < k; j++){
		long long s = 0;
		while (s + T[i] <= p){
			s += T[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;
}

int solve(){
	long long left = 0;
	long long right = 100000 * 10000;
	long long mid;
	while (right - left > 1){
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n) right = mid;
		else left = mid;
	}
	return right;
}

main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> T[i];
	long long ans = solve();
	cout << ans << endl;
}

Measured memory_bytes: 1936
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int a,b; cin >> a >> b;
    
    if(a!=b) cout << max(a,b)*2-1 << ln;
    else cout << a*2 << ln;
    
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(2003)
s1 = input()
s2 = input()
len1 = len(s1) + 1
len2 = len(s2) + 1
_dp = [[None for _ in range(len2)] for _ in range(len1)]
def dp(i, j):
    if i == 0:
        return j
    if j == 0:
        return i
    if _dp[i][j] == None:
        _dp[i][j] = min(dp(i - 1, j) + 1,         # deletion
                        dp(i, j - 1) + 1,         # insertion
                        dp(i - 1, j - 1) + (0 if s1[i - 1] == s2[j - 1] else 1))  # replacement / no op
    return _dp[i][j]
print(dp(len1 - 1, len2 - 1))


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int x, y;
    cin >> x >> y;

    rep(kame, x+1){
        rep(turu, x+1){
            if(kame + turu != x) continue;
            int asi = kame*4 + turu*2;
            if(asi == y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int s, w;
  cin >> s >> w;
  if (w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)



int main (){
  int n;
  cin>>n;
  vector<int> s(n);
  int sum=0;
  r(i,n){
    cin>>s.at(i);
    sum+=s.at(i);
  }
  sort(s.begin(),s.end());

  if(sum%10!=0)cout<<sum<<endl;
  else{
    for(int i=0;i<n;i++){
      if(s.at(i)%10!=0){cout<<sum-s.at(i)<<endl;break;}
      if(i==n-1)cout<<0<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}';return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int n, z, w; cin >> n >> z >> w;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  if (n == 1) {
    cout << abs(w - a[0]) << endl;
  } else {
    cout << max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w)) << endl;
  }

  return 0;
}

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

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == -1){
				break;
			}
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(n & 3);
			n = n >> 2;
			while(n > 0){
				list.add(n & 3);
				n = n >> 2;
			}
			//oÍ
			for(int i=list.size()-1; i >= 0; i--){
				System.out.print(list.get(i));
			}
			System.out.println("");
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n;
    	cin>>n;
    	map<int,char>mp;
    	for(char c='a';c<='z';c++)
    		mp[c-'a'+1]=c;
    	ll x=1;
    	while(x*26<=n)
    		x*=26;
    	string s="";
    	while(n>26)
    	{
    		ll z=n%26==0?26:n%26;
    		s=mp[z]+s;
    		n-=z;
    		n/=26;
    	}
    	s=mp[n]+s;
    	cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e5+10;
const int mod = 998244353;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int a[maxn],num[maxn];
int main(){
	n=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	if(a[1]!=0){puts("0");return 0;}
	sort(a+2,a+n+1);
	if(a[2]==0){puts("0");return 0;}
	num[0]=1;
	long long ans=1;
	for(register int i=2;i<=n;i++){
		(ans*=num[a[i]-1])%=mod;
		num[a[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <vector>
#include<iostream>
#include <cstdlib>
#include<stdlib.h>
using namespace std;
    

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int> points;
    
    int temp_result = 0;
    points.push_back(temp_result);
    
    for (auto c: s) {
        if (c == 'I')
            temp_result++;
        else
            temp_result--;
        points.push_back(temp_result);
    }
    
    cout << *max_element(points.begin(), points.end()) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

void solve() {
  // int x;
  // cout << endl;
}

signed main() {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  // solve();
  return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Mon Dec 10 23:56:37 2018
//
package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
		arr[i] -= i + 1
	}
	b := make([]int, len(arr))
	copy(b, arr)

	sort.Ints(b)

	middle := b[len(b)/2]
	ans := 0
	for i := range arr {
		ans += abs(arr[i] - middle)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 2002;
const ll INF = LLONG_MAX/3;

ll f[N][N];

ll dp[N],nx[N];
int midx[N];
void minima(int ly, int ry, int lx, int rx){
    if(ly > ry) return;
    if(ly == ry){
        int idx = lx;
        ll v = dp[lx]+f[lx+1][ly];
        for(int j=lx+1; j<=rx; ++j){
            ll tv = dp[j]+f[j+1][ly];
            if(tv<v){
                idx = j;
                v = tv;
            }
        }
        nx[ly] = v;
        midx[ly] = idx;
        return;
    }

    int my = (ly+ry)/2;
    minima(my,my,lx,rx);
    minima(ly,my-1,lx,midx[my]);
    minima(my+1,ry,midx[my],rx);
}

int main(){
    int s,n,m;
    cin >>s >>n >>m;

    vector<int> x(s);
    rep(i,s) cin >>x[i];

    vector<int> a;
    rep(i,n){
        int t,p;
        cin >>t >>p;
        --p;

        // 待ち時間0のためにバス停0を出るべき時間
        t -= x[p];
        a.pb(t);
    }
    a.pb(-10101);
    sort(all(a));
    int A = a.size();

    fill(f[0],f[N],INF);
    rep(r,A){
        int d_time = a[r];
        ll sum = 0;
        for(int l=r; l>=0; --l){
            sum += d_time - a[l];
            f[l][r] = sum;
        }
    }

    fill(dp,dp+N,INF);
    dp[0] = 0;
    rep(i,m){
        minima(0,A-1,0,A-1);
        rep(j,N) dp[j] = min(dp[j],nx[j]);
    }
    printf("%lld\n", dp[A-1]);
    return 0;
}



Measured memory_bytes: 34632
n = int(input())

h = list(map(int, input().split()))

for i in range(n-1):
    if h[-i-2] - h[-i-1] >= 2:
        print("No")
        exit()
    elif h[-i-2] - h[-i-1] == 1:
        h[-i-2] = h[-i-2] - 1


print("Yes")

Measured memory_bytes: 15020
#include "bits/stdc++.h"
using namespace std;
int n,x,pv=INT_MIN,cnt,ans;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		if(x<=pv) cnt++;
		else cnt=0;
		ans=max(ans,cnt);
		pv=x;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll k;cin>>k;
    if(n==1||k==1){
        cout<<1<<endl;
        return;
    }
    cout<<(n*k+1)/2<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    b.push_back(LLINF);
    ll ans = 0;
    ans += b[0];
    rep(i, n - 1){
        ans += min(b[i], b[i + 1]);
    }
    print(ans);


    

}



Measured memory_bytes: 3656
import itertools
def s(): return input()
def I(): return map(int,input().split())

N,K = I()
S = list(s())
num = 1
cnt = 0
L = []
for i in range(N-1):
    if S[i] != S[i+1]:
        L.append(num)
        num = 0
        if S[i] == '0':
            cnt += 1
    num += 1
L.append(num)
if S[-1] == '0':
    cnt += 1
ruiseki = [0]+list(itertools.accumulate(L))
l = len(ruiseki)
if cnt <= K:
    print(N)
    exit()
start = 0
ans = 0
if S[0] == '0':
    start = 1
for i in range(start,l,2):
    if i+K*2+1 > l-1:
        break
    ans = max(ans,ruiseki[i+K*2+1]-ruiseki[i])
if S[0] == '0':
    ans = max(ans,ruiseki[K*2])
if S[-1] == '0':
    ans = max(ans,ruiseki[-1]-ruiseki[l-K*2-1])
print(ans)

Measured memory_bytes: 15376