akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define maxx 100005
#define inf 1000000009
#define edge pair<ll,ll>
using namespace std;
 

 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦
ll ks(ll ww,ll w[],ll v[],ll n)
{
	ll k[n+1][ww+1];
	ll i;
	ll j;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=ww;j++)
		{
			if(i==0 || j==0 )
			k[i][j]=0;
			else if(w[i-1]<=j)
			{
				k[i][j]=max(v[i-1]+k[i-1][j-w[i-1]],k[i-1][j]);
			}
			else
			k[i][j]=k[i-1][j];
		}
	}
	return k[n][ww];
}

int main()
{
	ll n,ww;
	cin>>n>>ww;
	ll v[n],w[n];
	for(ll i=0;i<n;i++)
	cin>>w[i]>>v[i];
	ll ans=0;
	ans=ks(ww,w,v,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a;
	cin>>a;
	double b[1003];
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	for(int i=0;i<a;i++){
		for(int j=i;j<a;j++){
			if(b[i]>b[j]){
				int temp=b[i];
				b[i]=b[j];
				b[j]=temp;
			}
		}
	}
	double sum=b[0];
	for(int i=1;i<a;i++){
		sum=(sum+b[i])/2;
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353 
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector <int> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        ll ans=0ll;
        sort(a.begin(),a.end());
        vector <int> ctr(n+1,0);
        for(int i=0;i<n;i++){
            int j=i+1;
            while(j<n&&a[i]==a[j])
                j++;
            ctr[i]+=(j-i-1);
            ctr[j]-=(j-i-1);
            for(int k=2;k*a[i]<=a[n-1];k++){
                auto it=lower_bound(a.begin(),a.end(),k*a[i]);
                auto it1=lower_bound(a.begin(),a.end(),k*a[i]+1);
                int pos1=it1-a.begin();
                int pos=it-a.begin();
                ctr[pos]+=(j-i);
                ctr[pos1]-=(j-i);
            }
            i=j-1;
        }
        for(int i=1;i<n;i++)
            ctr[i]+=ctr[i-1];
        for(int i=0;i<n;i++){
            //cout<<ctr[i]<<" ";
            if(ctr[i]==0)
                ans++;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4760
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x;
    cin >> x;
    ll ans=100;
    ll count=0;
    while(ans<x){
        ans+=ans/100;
        count++;
    }
    cout << count ENDL;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

using namespace std;
int main()
{
    // 文字列の入力
    long long X, K, D;
	cin >> X >> K >> D;
	
	X = abs(X);
	long long result;
	if(abs(X) / D >= K) {
		// 折り返しなし
		result = (X >= 0) ? (X - K * D) : (-X + K * D);
		printf("%lld\n", result);
		return 0;
	}
	
	long long div = X / D;
	long long sur = X % D;
	
	if((K - div) % 2 == 0) {
		result = sur;
	} else {
		result = (sur > 0) ? (sur - D) : (sur + D);
	}
	
	printf("%lld\n", abs(result));
	
    return 0;
}

//1000000000000001

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll K, N;
    cin >> K >> N;

    vector<ll> a(N + 1);
    rep(i, N)
    {
        cin >> a[i];
    }
    a[N] = a[0] + K;


    ll tmp = 0;

    rep(i, N)
    {
        chmax(tmp, a[i + 1] - a[i]);
    }
    cout << K - tmp << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define REPRANGE(i, s, e) for (int i = (s); i < (e); i++)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A; REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl
#define rsort(p, q) sort(p, q, greater<int>());

#define DEBUGV(V) REP(i, V.size() - 1) cout << V.at(i) << " "; cout << endl 

int
main()
{
  CIN2(A, B);
  string S; cin >> S;

  bool flg = true;
  REP(i, A) {
    if (!('0' <= S.at(i) && S.at(i) <= '9')) flg = false; 
  }
  if ('-' != S.at(A)) flg = false;
  REPRANGE(i, A+2, A+B+1) {
    if (!('0' <= S.at(i) && S.at(i) <= '9')) flg = false; 
  }

  if (flg) ANS("Yes");
  else ANS("No");

  return 0;
}


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

int main() {

	unsigned long long s; cin >> s;
	unsigned long long n, k;
	if (s < 1000000000ull) {
		cout << 0 << " " << 0 << " "
			<< 0 << " " << 1 << " "
			<< s << " " << 0 << endl;
	}
	else {
		n = (s - 1) / 1000000000ull;
		k = s - n * 1000000000ull;
		cout << 0 << " " << 1 << " "
			<< 1000000000u << " " << 0 << " "
			<< k << " " << n + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque


def bfs(H, W, maze, visited, sharp):
    queue = deque([[0, 0]])
    visited[0][0] = 0
    while queue:
        y, x = queue.popleft()
        if[y, x] == [H-1, W-1]:
            return ((H*W-sharp)-(visited[y][x]+1))
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if  new_y != -1 and new_y != H and  \
                new_x != -1 and new_x != W and  \
                maze[new_y][new_x] == "." and   \
                visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])

    return -1












def main():
    sharp = 0

    H, W = map(int,input().split())
    maze = [input() for i in range(H)]
    visited = [[-1]*W for j in range(H)]

    for k in range(H):
        sharp += maze[k].count('#')

    print(bfs(H, W, maze, visited, sharp))

main()

Measured memory_bytes: 3316
#include <stdio.h>
int main(){
	int n, m, i, j, k, a, b;
	scanf("%d%d", &n, &a);
	m = a;
	for(i=2; i<=n; i++){
		scanf("%d", &b);
		if(b > a) m += b - a;
		a = b;
	}
	printf("%d\n", m);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n;
int a, b, c;
string s[MN];
string ans;

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

    cin >> n;
    cin >> a >> b >> c;
    F0R(i, n) cin >> s[i];
    F0R(i, n){
        if(s[i] == "AB"){
            if(a==0&&b==0){
                cout << "No\n";
                return 0;
            }
            if(a==0){
                ans.pb('A');
                ++a; --b;
            } else if(b == 0){
                ans.pb('B');
                ++b; --a;
            } else{
                if(i == n-1){
                    ans.pb('A');
                    ++a; --b;
                } else{
                    if(s[i+1] == "AC"){
                        ans.pb('A');
                        ++a; --b;
                    } else{
                        ans.pb('B');
                        ++b; --a;
                    }
                }
            }
        } else if(s[i] == "AC"){
            if(a==0&&c==0){
                cout << "No\n";
                return 0;
            }
            if(a==0){
                ans.pb('A');
                ++a; --c;
            } else if(c == 0){
                ans.pb('C');
                ++c; --a;
            } else{
                if(i == n-1){
                    ans.pb('A');
                    ++a; --c;
                } else{
                    if(s[i+1] == "AB"){
                        ans.pb('A');
                        ++a; --c;
                    } else{
                        ans.pb('C');
                        ++c; --a;
                    }
                }
            }
        } else{
            if(b==0&&c==0){
                cout << "No\n";
                return 0;
            }
            if(b==0){
                ans.pb('B');
                ++b; --c;
            } else if(c==0){
                ans.pb('C');
                ++c; --b;
            } else{
                if(i == n-1){
                    ans.pb('B');
                    ++b; --c;
                } else{
                    if(s[i+1] == "AB"){
                        ans.pb('B');
                        ++b; --c;
                    } else{
                        ans.pb('C');
                        ++c; --b;
                    }
                }
            }
        }
    }
    cout << "Yes\n";
    F0R(i, n) cout << ans[i] << "\n";
    
    return 0;
}


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

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N, 0);
    vector<vector<int>> A(N, vector<int>(M, 0));
    for(int i=0;i<N;i++){
        cin >> C[i];
        for(int j=0; j<M; j++){
            cin >> A[i][j];
        }
    }

    int res = numeric_limits<int>::max();
    for(int bit=0; bit < (1 << N); bit++){
        int cost = 0;
        vector<int> Asum(M, 0);
        for(int i=0;i<N;i++){
            if((bit & (1<<i)) == 0) continue;
            cost += C[i];
            for(int j=0; j<M; j++){
                Asum[j] += A[i][j];
            }
        }
        bool isPassed = true;
        for(int j=0; j<M; j++){
            if(Asum[j] < X) isPassed = false;
        }
        if(isPassed){
            res = min(res, cost);
        }
    }
    if(res == numeric_limits<int>::max()) cout << "-1" << endl;
    else                                  cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $in = <STDIN>);
my @s = split //, $in;
my @t = reverse @s;
my $ans = 0;
for my $i (0..@s-1) {
  if ($s[$i] ne $t[$i]) {
    $ans++;
  }
}
say $ans/2;

Measured memory_bytes: 768
X,K,D = list(map(int,input().split()))
max_number = X + K*D
min_number = X - K*D
if min_number >= 0:
    ans = min_number
elif max_number <= 0:
    ans = -max_number
else:
    q = max_number // (2*D)
    ans1 = max_number - 2*q*D
    ans2 = max_number - 2*(q+1)*D
    if ans1 > -ans2:
        ans = -ans2
    else:
        ans = ans1
print(ans)


Measured memory_bytes: 9084
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
int C, K;
int T[100010];

void solve()
{
	sort(T, T+N);
	int res = 1;
	int i, j;
	i = 0;
	j = 0;
	while(1){
		if(T[j]-T[i] <= K && j-i+1<=C){
			j ++;
			if(j == N)
				break;
		}
		else{
			res ++;
			i = j;
		}
	}
	printf("%d\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	scanf("%d%d", &C, &K);
	for(i=0; i<N; i++)
		scanf("%d", &T[i]);
	solve();
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
	int n, i, frac;
	float out;
	out = 100000;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		out = out * 1.05;
		frac = (int)out % 1000;
		if(frac != 0) out = out - (float)frac + 1000;
	}
	printf("%d\n", (int)out);
	return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    unsigned long long A[N];
    unsigned long long s[N+1];
    unsigned long long sum = 0;
    s[0] = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        s[i+1] = s[i]+A[i];
    }
    for(int i=0;i<N-1;i++){
        sum = sum+A[i]*((s[N]-s[i+1])%1000000007);
        sum = sum%1000000007;
    }
    printf("%llu\n",sum);
    return 0;
}

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

using namespace std;

int cnt[200][200000 + 10];

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

    for(int i = 0; i < n; i++) {
        cnt[s[i]][i] ++;
        if(i != 0) {
            cnt['#'][i] += cnt['#'][i-1];
            cnt['.'][i] += cnt['.'][i-1];
        }
    }

    int b = cnt['.'][n-1], a = cnt['#'][n-1];

    int ans = min(a, b);

    for(int i = 0; i < n; i++) {
        ans = min(ans, cnt['#'][i] + b - cnt['.'][i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // 変数の宣言
  int a, b;
  int c;
  
  //値の取得
  cin >> a>>b;
  
  //型変換
  c=(a+b+1)/2;
  //出力
  cout << c;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,l;
    string a,b;
    cin >> l >> a >> b;
    for(i=0;i<l;i++)cout << a[i] << b[i];
    return 0;
}


Measured memory_bytes: 256
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    s = str(stdin.readline().rstrip())
    t = str(stdin.readline().rstrip())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = len(t)
    for i in range(len(s)-len(t) + 1):
        test = s[i:i+len(t)]
        a = len(t)
        for j in range(len(t)):
            if test[j] == t[j]:
                a -= 1
        ans = min(ans,a)
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9084
import scala.io.StdIn._
object Main extends App {
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val person = Array.tabulate(n){_ ⇒ new UnionFind}
  var isNonParadoxical = true
  for (_ ← 0 until m){
    val Array(l, r, d) = readLine.trim.split(' ').map(_.toInt)
    if (person(r - 1).isCompatible(person(l - 1), d)) {
      person(r - 1).setInfo(person(l - 1), d)
    }else {
      isNonParadoxical = false
    }
  }
  println(
    if (isNonParadoxical) "Yes" else "No"
  )

  class UnionFind{
    private var parent = this
    private var size: Int = 1
    private var differ: Long = 0
    private def root: UnionFind = {
      if (parent != this){
        val newRoot = parent.root
        differ += parent.differ
        parent = newRoot
      }
      parent
    }
    private def isSameUnion(that: UnionFind): Boolean = {
      root == that.root
    }
    def isCompatible(that: UnionFind, diff: Int): Boolean = {
      root != that.root || differ == that.differ + diff
    }
    def setInfo(that: UnionFind, diff: Int): Unit = {
      if (!isSameUnion(that)){
        val thisR = root
        val thatR = that.root
        //differ == that.differ + diff
        if (thisR.size < thatR.size){
          thisR.differ = that.differ + diff - differ
          thisR.parent = thatR
          thatR.size += thisR.size
        }else {
          thatR.differ = differ - diff - that.differ
          thatR.parent = thisR
          thisR.size += thatR.size
        }
      }
    }
  }
}

Measured memory_bytes: 104324
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int a,b;
	cin >> a >> b;
	
	if(a == b)
	{
		cout << "Draw" << endl;
	}
	else if((a == 1 || a > b) && b != 1)
	{
		cout << "Alice" << endl;
	}
	else
	{
		cout << "Bob" << endl;
	}
		
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		int[] a=fs.readArray(n);
		long ans=0;
		int max=a[0];
		for (int i:a) {
			max=Math.max(i, max);
			ans+=max-i;
		}
		System.out.println(ans);
	}

	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


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

int main() {
  int N, K, L = 0;
  cin >> N >> K;

  for(int i = 0; i < N; i++){
  int x;
  cin >> x;
    if(x > (K / 2))
    L += ((K-x) * 2);
    else
    L += (x * 2);
  }
  cout << L;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int A, B;

    cin >> A >> B;

    if (A + B == 24) {
        cout << 0 << endl;
    } else if (A + B > 24) {
        cout << (A + B) - 24 << endl;
    } else {
        cout << A + B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int a[505][505];

struct A { int y1, x1, y2, x2; };
vector<A> v;

int32_t main() {
    int h,w; cin >> h >> w;
    rep (i,h) rep (j,w) cin >> a[i][j];

    rep (i,h) rep (j,w-1) {
        if (a[i][j] & 1) {
            v.push_back(A {i,j,i,j+1});
            a[i][j]--; a[i][j+1]++;
        }
    }
    rep (i,h-1) {
        if (a[i][w-1] & 1) {
            v.push_back(A {i,w-1,i+1,w-1});
            a[i][w-1]--; a[i+1][w-1]++;
        }
    }

    cout << v.size() << endl;
    for (A p : v) cout << p.y1+1 << " " << p.x1+1 << " " << p.y2+1 << " " << p.x2+1 << endl;
}


Measured memory_bytes: 8432
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int A[100][100];
	int b[100];
	int c[100] = { 0 };
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	for (int k = 0; k < m; k++){
		cin >> b[k];
	}
	for (int l = 0; l < n; l++){
		for (int o = 0; o < m; o++){
			c[l] += (A[l][o] * b[o]);
		}
	}
	for (int p = 0; p < n; p++){
		cout << c[p] << endl;
	}
	return 0;
	}


Measured memory_bytes: 3132
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    h, a = rli()
    print((h+a-1)//a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
// https://atcoder.jp/contests/dp/tasks/dp_c

#include <bits/stdc++.h>

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<vector<int>> v(n, vector<int>(3));
	for (auto &x : v) {
		cin >> x[0] >> x[1] >> x[2];
	}

	// Everyday, you can take ai or bi or ci
	// If taken yesterday, you can't take it again
	// Maximize the amount taken

	// max_today(n) = max(max(a(n - 1) + bn, a(n - 1) + cn),
	//                max(b(n - 1) + an, b(n - 1) + cn),
	//                max(c(n - 1) + an, c(n - 1) + bn))

	// [day][activity]
	vector<int[3]> dp(n);
	dp[0][0] = v[0][0];
	dp[0][1] = v[0][1];
	dp[0][2] = v[0][2];

	for (int d = 1; d < n; ++d) {
		int ma = dp[d - 1][0];
		int mb = dp[d - 1][1];
		int mc = dp[d - 1][2];

		dp[d][0] = max(v[d][0] + mb, v[d][0] + mc);
		dp[d][1] = max(v[d][1] + ma, v[d][1] + mc);
		dp[d][2] = max(v[d][2] + ma, v[d][2] + mb);
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});

	return 0;
}


Measured memory_bytes: 6912
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val list = List.fill(n, 3)(sc.nextInt.toInt)
    
  val check = (term: Int, start: (Int, Int), end: (Int, Int)) => {
    val diffX = math.abs(end._1 - start._1)
    val diffY = math.abs(end._2 - start._2)
    val diff = diffX + diffY
    
    (diff <= term) && (diff % 2 == term % 2)
  }
  
  val result = (Seq(0,0,0) :: list).zip(list).forall{
    case ((Seq(t,x,y), Seq(t2, x2, y2))) => {
  	  check(t2 - t, (x, y), (x2, y2))
  	}
  }
  
  println(if (result) "Yes" else "No")
}

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

using namespace std;

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

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

    vector <int> b, c;
    int cb = 0, cc = 0;
    for (int i = 0; i < n; i++){
        if (a[i] <= max / 2){
            b.push_back(a[i]);
            cb ++;
        }else{
            c.push_back(a[i]);
            cc ++;
        }
    }
    
    int ans;
    if (cb == 0){
        sort(c.begin(), c.end());
        ans = c[0];
    }else if (cc == 0){
        sort(b.begin(), b.end(), greater <int> ());
        ans = b[0];
    }else{
        sort(b.begin(), b.end(), greater <int> ());
        sort(c.begin(), c.end());

        ans = b[0];
        if (abs(b[0]*2 - max) > abs(c[0]* 2 - max)){
            ans = c[0];
        }
    }
    
    cout << max << " " << ans << endl;
    

    return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    ft
    long long t,i,j,k,n,m,l=0,r,c[10][10];
    string s,p;
    cin>>n>>s;
    p="ABC";
    for(i=0;i+3<=n;i++)
    {
        r=0;
        for(j=i,k=0;k<3;j++,k++)
        {
            if(s[j]!=p[k])
            {
                r=1;
                break;
            }
        }
        l+=(r==0);
    }
    cout<<l<<"\n";
    return 0;
}



Measured memory_bytes: 3628
a=[1 for i in range(1000001)]
b=[0,0]
a[0]=a[1]=0
c=0
for i in range(2,1000001):
  if a[i]==1:
    c+=1
    for j in range(i * 2,1000001,i):
      a[j]=0
  b.append(c)
while True:
  try:
    print(b[int(input())])
  except EOFError:
    break


Measured memory_bytes: 23784
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, M;
	long long X, Y, Z, ans = 0;
	long long XYZ[8][1000] = {};
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> X >> Y >> Z;
		for (int j = 0; j < 8; j++) {
			int k = j;
			XYZ[j][i] += X - (k % 2) * 2 * X;
			k /= 2;
			XYZ[j][i] += Y - (k % 2) * 2 * Y;
			k /= 2;
			XYZ[j][i] += Z - (k % 2) * 2 * Z;
		}
	}
	for (int i = 0; i < 8; i++) {
		sort(XYZ[i], XYZ[i] + N, greater<long long>());
		long long count = 0;
		for (int j = 0; j < M; j++) {
			count += XYZ[i][j];
		}
		ans = max(ans, count);
	}
	cout << ans;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	int n;
	int a[101];
	int pos = 0;
	double mini = INF;
	double ave = 0;

	cin >> n;
	FOR(i, 0, n-1) {
		cin >> a[i];
		ave += a[i];
	}
	ave /= (double)n;

	mini = fabs((double)a[0] - ave);

	FOR(i, 1, n - 1) {
		if (fabs((double)a[i] - ave) < mini) {
			mini = fabs((double)a[i] - ave);
			pos = i;
		}
	}
	cout << pos << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n, count;
	bool flag;
	while(cin >> n, n){
		count = 0;
		for(int i = n + 1; i <= 2 * n; i++){
			flag = true;
			for(int j = 2; j <= sqrt(i); j ++){
				if(i % j == 0){
					flag = false;
					break;
				}
			}
			if(flag)
				count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int[] a={sc.nextInt(),sc.nextInt(),sc.nextInt()};
    Arrays.sort(a);
    int b=a[2]-a[0]+a[2]-a[1];
    if(b%2==0){
      System.out.println(b/2);
    }else{
      System.out.println(b/2+2);
    }
  }
}

Measured memory_bytes: 23764
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Sun,  4th Aug 2019                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define pb          push_back
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(int i = a; i < (int)b; i++)
#define req(i,a,b)  for(int i = (int)b - 1; i >= a; i--)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << x << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

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

int gcd(int a, int b) {return b?gcd(b,a%b):a;}

#ifdef LOCAL
	#define wa(x)       cerr << (#x) << " --- " << (x) << endl
	#define pvi(v)      {for(auto it:v) cerr << it << " "; cerr << endl;}
	#define line1	    cerr << "---------------------------" << endl;
#else
	#define wa //
	#define line1 //
	#define pvi //
	#define printf //
#endif

void solve();
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);

	int t=1; 
	// cin>>t;
	while(t--) solve();
	return 0;
}

//___________________________________________________________________________________________________

void maxi(int &a, int b){
	a = max(a,b);
}

void solve() {

	int n,w;
	cin >> n >> w;

	vi wt(n+1,0);
	vi val(n+1,0);
	rep(i,0,n) cin >> wt[i+1] >> val[i+1];

	// dp[i][j] - max value reachable using first i items
	// and maximum weight j
	vector<vi> dp(n+1, vi(w+1,0));

	rep(i,0,n+1){

		// wa(wt[i]);
		// wa(val[i]);

		rep(j,0,w+1){

			if(i==0) continue;
			maxi(dp[i][j], dp[i-1][j]);

			if(j-wt[i] >= 0){
				maxi(dp[i][j], dp[i-1][j-wt[i]] + val[i]);
			}
		}

		// for(auto r:dp) pvi(r);	
		// line1;
	}

	

	cout << *max_element(all(dp[n])) << endl;

}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int i,j,a,n,b,c,l,k,m=0;
int main()
{
  for(cin>>n;i<n;i++){
    cin>>a;
    m=max(a,m);
    if(a==m)c++;
  }
  cout<<c;
}

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

#define pb push_back
#define pp pop_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
typedef long long ll;

using namespace std;

const int N = 1e5 + 111, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0), eps = 1e-10;

ll A, B, C, ans;

int main(){
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cout << setprecision(10) << fixed;

	cin >> A >> B >> C;

	if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0)
		cout << 0;
	else cout << min(min(A * C, B * A), B * C);

	return 0;
 	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <utility>

using namespace std;

vector<int> G[200001];

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

    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int from, to;
        cin >> from >> to;
        G[from].push_back(to);
        G[to].push_back(from);
    }

    bool ans = false;
    stack<pair<int, int> > states;
    states.push(make_pair(1, 0));
    while (!states.empty()) {
        pair<int, int> q = states.top();
        states.pop();
        if (q.second == 2) {
            if (q.first == N)
                ans |= true;
            continue;
        }

        for (int i = 0; i < G[q.first].size(); ++i) {
            states.push(make_pair(G[q.first][i], q.second + 1));
        }
    }

    if(ans)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;

}

Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
#define N 2010

int n,K,Q,ans=2e9;
int a[N],b[N],c[N];

int main()
{
	scanf("%d%d%d",&n,&K,&Q);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) {
		int tot=0;
		for (int j=1,nex;j<=n;j=nex+1) {
			nex=j; while (a[nex]>=a[i]) nex++;
			if (nex-j>=K) {
				for (int k=j;k<nex;k++) b[k]=a[k];
				sort(b+j,b+nex);
				for (int k=j;k<=nex-K;k++) c[++tot]=b[k];
			}
		}
		sort(c+1,c+tot+1);
		if (tot>=Q) ans=min(ans,c[Q]-a[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, h; cin >> w >> h;
    vector<int> a(w), b(h);
    for(int i = 0; i < w; i++) cin >> a[i];
    for(int i = 0; i < h; i++) cin >> b[i];
    sort(b.begin(), b.end(), greater<int>());
    bool ok = true;
    for(int i = 0; i < h; i++)
    {
        sort(a.begin(), a.end(), greater<int>());
        for(int j = 0; j < w; j++)
        {
            if(a[j] == 0) continue;
            if(b[i] == 0) break;
            b[i]--;
            a[j]--;
        }
        if(b[i] > 0) ok = false;
    }
    cout << (ok ? 1 : 0) << endl;
    return 0;
}




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

const long long MOD=998244353;

long long powM(long long a, long long b){
	if(a==0)return 0;
	else if(b==0)return 1;
	else if(b==1)return a%MOD;

	if(b%2==0){
		return powM((a*a)%MOD, b/2)%MOD;
	}else{
		return (a*powM(a,b-1) )%MOD;
	}
}

long long cnt[100001];
long long d[100001];

signed main(){
	for(int i=0;i<100001;i++)cnt[i]=0;

	long long n;	cin>>n;
	long long maxD=0;
	for(long long i=0;i<n;i++){
		cin>>d[i];
		if(d[i]>maxD)maxD=d[i];
	}

	for(long long i=0;i<n;i++){
		cnt[ d[i] ]++;
	}


	if(cnt[0]!=1 || d[0]!=0){
		cout<<0<<endl;
		return 0;
	}

	long long ans=1;
	for(long long i=1;i<=maxD;i++){
		ans*=powM(cnt[i-1],cnt[i]);
		ans%=MOD;
	}


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


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <queue>

using namespace std;

char field[402][402];
queue<pair<int,int>> q;

void syori(int first, int second){
    q.push(make_pair(first, second));
    if(field[first][second]=='.')field[first][second]=',';
    else field[first][second]='$';

    return;
}

int main(void)
{
    int  H, W;
    
    for(int j = 0; j < 402; ++j){
        for(int i = 0; i < 402; ++i){
            field[j][i] = '0';
        }
    }
    cin >> H >> W;
    for(int j = 1; j <= H; ++j){
        for(int i = 1; i <= W; ++i){
            cin >> field[j][i];
        }
    }
    long int ans = 0;
    for(int j = 1; j <= H; ++j){
        for(int i = 1; i <= W; ++i){
            if(field[j][i]=='.' || field[j][i]=='#'){
                syori(j, i);
                long int b = 0, w = 0;
                while(!q.empty()){
                    pair<int,int> a = q.front();
                    q.pop();
                    if(field[a.first][a.second] == '$'){
                        b++;
                        field[a.first][a.second] = '0';
                        if(field[a.first - 1][a.second] == '.')syori(a.first - 1, a.second);
                        if(field[a.first + 1][a.second] == '.')syori(a.first + 1, a.second);
                        if(field[a.first][a.second - 1] == '.')syori(a.first, a.second - 1);
                        if(field[a.first][a.second + 1] == '.')syori(a.first, a.second + 1);
                    }else if(field[a.first][a.second] == ','){
                        w++;
                        field[a.first][a.second] = '0';
                        if(field[a.first - 1][a.second] == '#')syori(a.first - 1, a.second);
                        if(field[a.first + 1][a.second] == '#')syori(a.first + 1, a.second);
                        if(field[a.first][a.second - 1] == '#')syori(a.first, a.second - 1);
                        if(field[a.first][a.second + 1] == '#')syori(a.first, a.second + 1);
                    }
                }
                ans += b * w;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {

	int W, H, N, x, y, a;
	std::cin >> W >> H >> N;
	std::vector<std::vector<int>> black(W + 1, std::vector<int>(H + 1, 0));

	for (int I = 0; I < N; I++) {

		std::cin >> x >> y >> a;

		if (a == 1) {
			for (int i = 1; i <= x; i++) {
				for (int j = 1; j <= H; j++)black[i][j] = 1;
			}
		}

		if (a == 2 && x < W) {
			for (int i = x + 1; i <= W; i++) {
				for (int j = 1; j <= H; j++)black[i][j] = 1;
			}
		}

		if (a == 3) {
			for (int i = 1; i <= W; i++) {
				for (int j = 1; j <= y; j++)black[i][j] = 1;
			}
		}

		if (a == 4 && y < H) {
			for (int i = 1; i <= W; i++) {
				for (int j = y + 1; j <= H; j++)black[i][j] = 1;
			}
		}

	}

	int res = 0;//黒の面積

	for (int i = 1; i <= W; i++) {
		for (int j = 1; j <= H; j++) {
			if (black[i][j])res++;
		}
	}

	std::cout << H * W - res << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

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

    int count = 0;
    for (int i = 1; i < n - 1; i++)
    {
        vector<int> a(3);
        for (int j = 0; j <= 2; j++)
        {
            a[j] = v[i - 1 + j];
        }
        sort(a.begin(), a.end());
        if (a[1] == v[i])
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int &x : a) cin >> x;
    int ans = 1e9;
    for (int x = -100; x <= 100; x++) {
        int cur = 0;
        for (int i = 0; i < n; i++) cur += (a[i] - x) * (a[i] - x);
        ans = min(ans, cur);
    }
    cout << ans << '\n';
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

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

int kuraiwa(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

bool kaibun(int n) {
	int a[5];
	for (int i = 0; i < 5; i++) {
		a[i] = n % 10;
		n /= 10;
	}
	if (a[0] == a[4] && a[1] == a[3]) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	llint a, b;
	cin >> a >> b;
	if (a%b == 0){
		cout << -1 << endl;
	}
	else{
		int cnt = 2 * a;
		while (1){
			if (cnt%b != 0){
				cout << cnt << endl;
				return 0;
			}
			cnt += a;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
  IOS();
  ll x,y;
  cin >> x >> y;
  ll ans = 0;
  while (x <= y) {
    ans++;
    x *= 2;
  }
  cout << ans << endl;
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			int c = 0;
			while(a%2==0){
				a/=2;
				c++;
			}
			if(c<min)
				min = c;
		}
		
		System.out.println(min);
	}

}


Measured memory_bytes: 21972