akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;


int main() {
	int l,m,n,r,p,s=2019;
	cin >> l >> m;
	n = m % 2019; r = l % 2019;
	if (((m-l)>2019 )||( n<r)) {
		s = 0;
	}
	else 
	{
		for (int a = r; a <= n; a++) 
		{
			for (int b = a+1; b <= n; b++)
			{
				p=((a * b) % 2019);
				if (p < s)
				{
					s = p;
				}
			}
		}
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
    ll a, b;
    cin >> a >> b;
    bitset<32> a_bit(a);
    bitset<32> b_bit(b);
    cout << (a_bit & b_bit) << endl;
    cout << (a_bit | b_bit) << endl;
    cout << (a_bit ^ b_bit) << endl;
}



Measured memory_bytes: 3152
x = int(input())
if x <= 6:
    print(1)
elif x <= 11:
    print(2)
else:
    if 1 <= x%11 <= 6:
        print(x//11*2+1)
    elif x%11 == 0:
        print(x//11*2)
    else:
        print(2+x//11*2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int mod = 2019;

int main(){
  string s;
  cin >> s;
  map<int, int> mp;
  mp[0] = 1;
  reverse(ALL(s));
  int now = 0;
  vector<int> power(s.size());
  int p = 1;
  rep(i, power.size()){
    power.at(i) = p;
    p *= 10;
    p %= mod;
  }
  rep(i, s.size()){
    int add = (s.at(i) - '0') * power.at(i);
    now += add;
    now %= mod;
    mp[now]++;
  }
  ll ans = 0;
  for(auto p : mp){
    ans += (ll)p.second*(p.second-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4332
while True:
    n,k=map(int,input().split())
    a=[]
    if n==0 and k==0:
        break
    for _ in range(n):
        a.append(int(input()))
    
    s=[0 for _ in range(n+1)]
    for i in range(n):
        s[i+1]=s[i]+a[i]
    ans=0
    for i in range(n-k):
        ans=max(ans,s[i+k]-s[i])
    print(ans)


Measured memory_bytes: 13420
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void B_task();

int main()
{
	B_task();
	
	fflush(stdout);
	return 0;
}

static void B_task()
{
	int N, X;
	scanf(" %d %d", &N, &X);

	auto Dn = new int[N + 1];
	Dn[0] = 0;

	int L = 0;
	for (int i = 0; i < N; i++) {
		if(i) Dn[i] = Dn[i - 1] + L;
		scanf(" %d", &L);
	}
	Dn[N] = Dn[N - 1] + L;

	int i;
	for (i = 0; i <= N; i++) {
		if (Dn[i] > X) {
			break;
		}
	}

	printf("%d\n", i);

	delete[] Dn;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll A,B;
  cin >> A >> B;
  if(B==1) {
    cout << 0;
    return 0;
  }
  cout << 1 + (B-2)/(A-1);
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    int z = n%10;
    if (z == 3) cout << "bon" << '\n';
    else if (z == 0 || z == 1 || z == 6 || z == 8) cout << "pon" << '\n';
    else cout << "hon" << '\n';
}

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

    solve();

    return 0;
}


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

int main()
{
	int a,b,c,d,sum=0;
	string s,t;

    cin>>s>>t;
    char j=t[2];
    t[2]=t[0];
    t[0]=j;
    if(s==t)
        cout<<"YES"<<endl;
    else
    {
        cout<<"NO"<<endl;
    }
    

	
	
	return 0;
}
	

Measured memory_bytes: 256
///usr/bin/g++ -O2 -std=c++14 -DTr___ $0 -o $0.run; exec $0.run; exit
#include <bits/stdc++.h>
#define llint long long
#define fi first
#define se second
#define BIT(x, i) (((x)>>(i))&1ll)
#define MASK(i) (1ll<<(i))
#define db(x) cout << #x << " = " << (x) << endl;
#define mini(x) ((x)>(y)?(x)=(y),1:0)
#define maxi(x) ((x)<(y)?(x)=(y),1:0)
using namespace std;

void openFile() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef Tr___
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
#else
    //freopen("tname.inp", "r", stdin);
    //freopen("tname.out", "w", stdout);
#endif
}

const int maxn = (int) 1e5 + 5;
const int maxm = (int) 1e6 + 5;
const llint inf = (llint) 1e9 + 7;

int N;
string s;

void enter() {
    cin >> s;
}

void solve() {
    int tot = 0;
    for (int i = 0; i < s.size(); ++i) {
        tot = tot + (s[i] - '0');
    }
    cout << max(tot, (int) (s.size() - 1) * 9 + (s[0] - '0') - 1) << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

/* 二分累乗法 */
ll bipow(ll a, ll b) {
    ll res = 1;
    for (; b; a = a * a , b >>= 1){
        if (b & 1) res = res * a;
    }
    return res;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N;
    cin >> N;
    ll rei = 0;
    ll leng = 0;
    for(int i = 1;;i++){
        rei += bipow(26,i);
        if(rei >= N){
            leng = i;
            break;
        }
    }
    N -= 26*(bipow(26,leng-1)-1)/25;
    N--;
    string S = "";
    REPS(i,leng){
        S += ('a' + (N%26));
        N/=26;
    }
    reverse(ALL(S));
    cout << S << "\n";
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void){
int r,i;
scanf("%d",&i);
int n[100];
for(r=0;r<i;r++){
scanf("%d",&n[r]);
}
for(r=i-1;r>=0;r--){
if(r!=0){
printf("%d ",n[r]);}else{
printf("%d\n",n[r]);}
}
return 0;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;


int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    rep(i, n) {
        ll ma = a + i * d - (n - 1 - i) * c;
        ll mi = a + i * c - (n - 1 - i) * d;

        if (mi <= b && b <= ma) {
            cout << "YES" << endl;
            ret();
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
n,m = gets.chomp.split.map(&:to_i)
arr = Array.new(m)
nood = Array.new(n+1,0)

m.times do
  arr = gets.chomp.split.map(&:to_i)
  nood[arr[0]] += 1
  nood[arr[1]] += 1
end

judge = 'YES'
for i in 1..n
  if nood[i]%2 != 0
    judge = 'NO'
    break
  end
end
puts judge

Measured memory_bytes: 3324
N,M,C=map(int,input().split())
li=[]
while True:
    try:
        li.append(list(map(int,input().split())))

    except:
        break;
      
ans=0
a=0
for i in range(N):
  for j in range(M):
    a=a+li[0][j]*li[i+1][j]
  a=a+C
  if a>0:
    ans=ans+1
  a=0 
print(ans)

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

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}           
const int N = 2001;
bitset <N*N/2> sums;

int n;

int main() 
{
  Read_rap ();
  cin >> n; 
  int S = 0;
  sums[0] = 1;

  for (int i = 1; i <= n; i++) {
  	int x; cin >> x;
  	sums |= (sums << x);
  	S += x;
 	}                         
 	for (int i = 1; ; i++) {
 		if (sums[i] && 2*i >= S) {
 			cout << i;
 			break;
 		}
 	}

  return 0;
} 










// Coded by Z..


Measured memory_bytes: 1152
def main():
    n = int(input())
    a, b = [None]*n, [None]*n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    a.sort()
    b.sort()
    if n & 1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2-1]-a[n//2]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25496
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string allA(string a) {
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '?') {
			a[i] = 'a';
		}
	}
	return a;
}

string allZ(string a) {
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '?') {
			a[i] = 'z';
		}
	}
	return a;
}

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	string t;
	cin >> t;
	int low = 0;
	int high = 0;
	for (int i = 0; i < n; i++) {
		if (allA(s[i]) <= allZ(t)) {
			high++;
		}
		if (allZ(s[i]) < allA(t)) {
			low++;
		}
	}
	for (int i = low; i <= high; i++) {
		if (i != low) {
			cout << ' ';
		}
		cout << i + 1;
	}
	cout << endl;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)




int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m);
    vector<vector<int>> a(n,vector<int>(m));
    int ans=0;
    int tmp=0;
    rep(i,m){
        cin>>b[i];
    }
    rep(i,n){
        rep(j,m){
            cin>>a[i][j];
            tmp+=b[j]*a[i][j];
        }
        if(tmp+c>0)ans++;
        tmp=0;
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    int ans = 0;
    cin >> n >> k;
    int l[55] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l, l + n, greater<int>());
    for (int i = 0; i < k; i++)
    {
        ans += l[i];
    }
    cout << ans << endl;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  long int H[N+1];
  long long int dp[N+1];
  for(int i=1; i<=N; ++i) cin>>H[i];
  for(int i=1; i<=N; ++i) dp[i]=100000000000;
  dp[1]=0;
  for(int i=1; i<N; ++i){
    for(int j=max(1,i-K+1); j<=i; ++j){
      dp[i+1]=min(dp[i+1],dp[j]+abs(H[i+1]-H[j]));
    }
  }
  cout<<dp[N]<<endl;
}


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

long long dp[69][69][69][49];
long long power2[69];
long long power3[69];
long long power5[69];

void init() {
	power2[0] = 1; for (int i = 1; i <= 62; i++) power2[i] = (2LL * power2[i - 1]);
	power3[0] = 1; for (int i = 1; i <= 62; i++) power3[i] = (3LL * power3[i - 1]);
	power5[0] = 1; for (int i = 1; i <= 62; i++) power5[i] = (5LL * power5[i - 1]);
}

long long solve(long long N, long long A, long long B, long long C, long long D) {
	for (int i = 0; i <= 62; i++) {
		for (int j = 0; j <= 62; j++) {
			for (int k = 0; k <= 62; k++) {
				for (int l = 0; l <= 40; l++) dp[i][j][k][l] = (1LL << 60);
			}
		}
	}

	dp[0][0][0][20] = 0;
	for (int i = 0; i <= 61; i++) {
		for (int j = 0; j <= 61; j++) {
			for (int k = 0; k <= 61; k++) {
				double I = 0.3010 * i + 0.4771 * j + 0.6990 * k;
				if (I >= 18.7) break;
				long long val = power2[i] * power3[j] * power5[k];

				for (int l = 0; l <= 39; l++) dp[i][j][k][l + 1] = min(dp[i][j][k][l + 1], dp[i][j][k][l] + D);
				for (int l = 39; l >= 0; l--) dp[i][j][k][l] = min(dp[i][j][k][l], dp[i][j][k][l + 1] + D);
				
				// 2 倍にする
				long long A1 = (N / val) % 2LL;
				for (int l = -20; l <= 20; l++) {
					int p = 20 + 2 * l - A1;
					if (0 <= p && p <= 40) dp[i + 1][j][k][20 + l] = min(dp[i + 1][j][k][20 + l], dp[i][j][k][p] + A);
				}

				// 3 倍にする
				long long B1 = (N / val) % 3LL;
				for (int l = -20; l <= 20; l++) {
					int p = 20 + 3 * l - B1;
					if (0 <= p && p <= 40) dp[i][j + 1][k][20 + l] = min(dp[i][j + 1][k][20 + l], dp[i][j][k][p] + B);
				}

				// 5 倍にする
				long long C1 = (N / val) % 5LL;
				for (int l = -20; l <= 20; l++) {
					int p = 20 + 5 * l - C1;
					if (0 <= p && p <= 40) dp[i][j][k + 1][20 + l] = min(dp[i][j][k + 1][20 + l], dp[i][j][k][p] + C);
				}
			}
		}
	}
	
	long long Answer = (1LL << 60);
	for (int i = 0; i <= 62; i++) {
		for (int j = 0; j <= 62; j++) {
			for (int k = 0; k <= 62; k++) {
				double I = 0.3010 * i + 0.4771 * j + 0.6990 * k;
				if (I >= 18.7) break;
				long long val = power2[i] * power3[j] * power5[k];

				for (int l = 0; l <= 40; l++) {
					long long base = abs((N / val) + (l - 20));
					if (base >= 1 && (1LL << 61) / base < D) continue;
					Answer = min(Answer, dp[i][j][k][l] + base * D);
				}
			}
		}
	}
	return Answer;
}

int main() {
	long long T, N, A, B, C, D; init();
	cin >> T;
	for (int i = 1; i <= T; i++) {
		cin >> N >> A >> B >> C >> D;
		cout << solve(N, A, B, C, D) << endl;
	}
	return 0;
}

Measured memory_bytes: 108548
e1, e2, e3, e4=map(int, input().split())
if e1 == e2 and e3 == e4:
  print("yes")
elif e1 == e3 and e2 == e4:
  print("yes")
elif e1 == e4 and e2 == e3:
  print("yes")
else:
  print("no")


Measured memory_bytes: 5596
// Created by AboAbdoMC
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int A,B;
    cin >> A >> B;
    int cnt = 1;
    int ans = 0;
    while(cnt < B) {cnt += A-1;ans++;}
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        mut c: Chars,
    }

    let mut count = 0;
    let mut l = 0;
    let mut r = n - 1;
    while l < r {
        while c[l] == 'R' && l < r {
            l += 1;
        }
        while c[r] == 'W' && l < r {
            r -= 1;
        }
        if l >= r {
            break;
        }
        count += 1;
        c[l] = 'R';
        c[r] = 'W';
        l += 1;
        r -= 1;
    }

    l = 0;
    while l < n && c[l] == 'R' {
        l += 1;
    }
    l += 1;
    if l != n {
        for i in l..n {
            if c[i] == 'R' {
                c[i] = 'W';
                count += 1;
            }
        }
    }

    println!("{}", count);
}


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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var B = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var A = new int[N];

        A[0] = B[0];
        for (int i = 1; i < N - 1; i++)
        {
            A[i] = Math.Min(B[i - 1], B[i]);
        }
        A[N - 1] = B[N - 2];

        Console.WriteLine(A.Sum());
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll jum=0,n;
	map<ll,ll>m;
	cin >> n;
	for(int i=1; i<=n; i++){
		ll x;
		cin >> x;
		jum+=x;
		m[x]++;
	}
	ll q,a,b;
	cin >> q;
	while(q--){
		cin >> a >> b;
		cout << jum-a*m[a]+b*m[a] << endl;
		jum=jum-a*m[a]+b*m[a];
		m[b]+=m[a];
		m[a]=0;
	}
}

Measured memory_bytes: 9416
/**
 *COYG, 14 FA Cups we are back baby
 */
#include <bits/stdc++.h>
using namespace std;
#define mod 		1000000007
#define ll 		long long
#define mp 		make_pair
#define pb 		push_back
#define forn(i,n) 	for(int i=0;i<n;i++)
#define for1(i,n) 	for(int i=1;i<n;i++)
#define ford(i,n) 	for(int i=n-1;i>=0;i--)
#define vi 		vector<int>
#define vl 		vector<ll>
#define pii 		pair<int,int>
#define pll 		pair<ll,ll>
#define vpi 		vector<pair<int,int> >
#define vpl		vector<pair<ll,ll> >
#define vvi 		vector<vector<int> >
#define vvl 		vector<vector<ll> >
#define ull 		unsigned long long
#define IOS 		ios_base::sync_with_stdio(false);
#define PI 		3.1415926535897932384626
#define ff 		first
#define ss 		second
#define char2Int(c) 	(c-'0')
#define FOREACH(i,t) 	for (auto i=t.begin(); i!=t.end(); i++)
#define clr(a,x) 	memset(a,x,sizeof(a)) //set elements of array to some value
#define all(x)		(x).begin(),(x).end()//cout<<"Case #"<<zzz<<": ";
#define plll pair<ll,pll >
ll n;int a[22][22];
ll dp[21][(1<<21)+1];
ll getans(ll m,ll f)
{
    if(m>=n)return 1;
    if(dp[m][f]!=-1)return dp[m][f];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if(!(f&(1<<i))&&a[m][i]==1)
        {
            ans=(ans+getans(m+1,f|(1<<i)))%mod;
        }
    }
    dp[m][f]=ans;
    return ans;
}
void solve()
{
    cin>>n;
    forn(i,n)forn(j,n)cin>>a[i][j];
    forn(i,n)forn(j,1<<n)dp[i][j]=-1;
    cout<<getans(0,0)<<endl;
}
int main()
{
    IOS;cin.tie(NULL);
    ll zz;zz=1;
    //cin>>zz;
    for(int zzz=1;zzz<=zz;zzz++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 347676
from collections import Counter

N = int(input())

strings = [input() for i in range(N)]

string_set = list(map(set,strings))
count_set = list(map(Counter, strings))

common_letter = string_set[0]

for s in string_set:
    common_letter = common_letter & s

common_letter_nums = {}

for l in common_letter:
    common_letter_nums.setdefault(l, [])
    for c in count_set:
        common_letter_nums[l].append(c[l])

output_letter = ''
for k, v in common_letter_nums.items():
    output_letter += k * min(v)

print(''.join(sorted(output_letter)))

Measured memory_bytes: 3444
using System;
using System.Text;

namespace _084_SearchEngine
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr = Console.ReadLine ();
			StringBuilder output = new StringBuilder (inputStr.Length);
			char[] separator = { ' ', '.', ',' };

			foreach (var item in inputStr.Split (separator, StringSplitOptions.RemoveEmptyEntries))
			{
				if (2 < item.Length && item.Length < 7)
				{
					output.Append (item);
					output.Append (" ");
				}
			}

			output.Remove (output.Length - 1, 1);

			Console.WriteLine (output);
		}
	}
}

Measured memory_bytes: 8820
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool operator==(const mint& a, const mint& b) { return a.x == b.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<pair<char, int>> cnt;
    cnt.emplace_back(s[0], 0);
    rep(i, n) {
        if (s[i] == cnt.back().fi) cnt.back().se++;
        else cnt.emplace_back(s[i], 1);
    }
    mint ans = 1;
    rep(i, sz(cnt)) {
        int x = cnt[i].se;
        if (i == 0) {
            if (x == 1) {
                ans *= 3;
            } else {
                ans *= 3 * 2;
            }
        } else {
            int p = cnt[i-1].se;
            if (p == 1) {
                ans *= 2;
            } else {
                if (x == 1) {
                    ans *= 1;
                } else {
                    ans *= 3;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long N, A[200009], cnt;
multiset<long long> S;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	for (int i = N - 1; i >= 0; i--) {
		bool flag = false;
		for (int j = 0; j < 32; j++) {
			long long ret = (1LL << j) - A[i];
			if (A[i] > ret) continue;
			auto itr = S.lower_bound(ret);
			if (itr != S.end() && *itr == ret) {
				S.erase(itr);
				cnt++;
				flag = true;
				break;
			}
		}
		if (flag == false) {
			S.insert(A[i]);
		}
	}
	cout << cnt << endl;
}

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

int main() {
    string s;
    getline(cin,s);
    if(s[2]==s[3] && s[4] == s[5])
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextLong();
			if(a[i]==0){
				System.out.println(0);
				return;
			}
		}
		long sum=1;
		for(int i=0; i<n; i++){
			try{
				sum=Math.multiplyExact(sum,a[i]);
				if(sum>1000000000000000000L){
					System.out.println(-1);
					return;
				}
			}catch(ArithmeticException e){
				System.out.println(-1);
				return;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 61152
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = A[0] - 1
    mn = 2
    for a in A[1:]:
        use = (a - 1) // mn
        if use == 0:
            mn = max(mn, a+1)
        ans += use
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50648
#include<bits/stdc++.h>
using namespace std;
#define MOD 1e9+7
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
int minthis(int a, int b){
if(a < b){
return a;
}
return b;
}
int maxthis(int a, int b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
}  


void solve(){		
	int n;
	cin >> n;
	vector<int> arr(n);
	ll ans = 0;
	for(int i = 0 ; i < n ; i++){
		cin >> arr[i];
	}
	sort(arr.rbegin(), arr.rend());
	vector<int> b;
	for(int i = 0 ; i < n ; i++) {
		b.push_back(arr[i]);
		if(i){
			b.push_back(arr[i]);
		}
	}
	for(int i = 0 ; i < n-1 ; i++){
		ans += b[i];
	}
	cout << ans << endl;
}
  
int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;    
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}


Measured memory_bytes: 6084
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	auto f = [&](LL v) { return v*v*v*v*v; };
	IN(LL, x);
	incII(i, -120, +120) {
	incII(j, -120, +120) {
		if(f(i) - f(j) == x) { OUT(i, j); exit(0); }
	}
	}
	UR;
}


Measured memory_bytes: 3636
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<cmath>
#define mod 1000000007
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

char mp[110][110][110];
int vis[110][110][110];
int dir[6][3]={-1,0,0,1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};

int arr[1000000];
int brr[1000000];
int f[1000000]={0};

int main()
{

	int h,n;
	cin >>h>>n;
	for(int i=0;i<=h;i++){
		f[i] = 2e9;
	}
	for(int i=0;i<n;i++)  
	{
		cin >>arr[i]>>brr[i];
	}
	f[0] =0 ;
	for(int i=0;i<n;i++){
		for(int j= 0;j<=h;j++){
			int nj = min(j+arr[i],h);
			f[nj] = min(f[nj],f[j]+brr[i]);
		//	cout<<f[nj]<<endl;
		}
	}
	cout<<f[h]<<endl;
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

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

    for (int i = 0; i < N.size(); i++) {
        if (N[i] == '1') {
            N[i] = '9';
        } else if (N[i] == '9') {
            N[i] = '1';
        }

    }

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
         h,w = map(int,input().split())
         if h == 0 and w == 0:
                  break
         for i in range(h):
                  if i % 2 == 0:
                           for j in range(w):
                                    if j %2 == 0:
                                             print("#",end="")
                                    else:
                                             print(".",end="")
                           print()
                  else:
                           for j in range(w):
                                    if j %2 == 0:
                                             print(".",end="")
                                    else:
                                             print("#",end="")
                           print()
         print()



Measured memory_bytes: 7004
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
/*        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
//        int a = int.Parse(input[2]);
//        int b = int.Parse(input[3]);*/
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
//        int b = int.Parse(ReadLine());
//        int c = int.Parse(ReadLine());
//        int d = int.Parse(ReadLine());
        string a = ReadLine();
//        string b = ReadLine();
//        string c = ReadLine();
//        string ko = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string b = "CODEFESTIVAL2016";
        int count = 0;
        for(int i=0;i<a.Length;i++){
            if(a[i] != b[i]){
                count++;
            }
        }
            WriteLine(count);
    }
}

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

int main()
{
    char s[3];

    int i, count=0;
    std::cin >> s;
    for ( i = 0 ; i < 3 ; i++)
    {
        if(s[i] == '1')
        {
            count++;
        }
    }
    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
int a,b,c,d;
bool i[100];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >>a>>b;
  i[a]=i[b]=true;
  for(int n=1;n<=3;n++){
    if(!i[n]) cout <<n<<'\n';
  }
  
  return (0);
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
relations = {}
for _ in range(m):
  a, b = list(map(int, input().split()))
  a -= 1
  b -= 1
  if relations.get(a):
     relations[a].append(b)
  else:
    relations[a] = [b]
  if relations.get(b):
    relations[b].append(a)
  else: 
    relations[b] = [a]

from collections import deque
visited = [False for i in range(n)]

groups = 0
def bfs(n, visited):
  global groups
  queue = deque([n])
  group_len = 0
  while queue:
    current = queue.popleft()
    if not visited[current]:
      visited[current] = True
      if relations.get(current):
        for neighbor in relations[current]:
          queue.append(neighbor)
        group_len += 1

  groups = max(groups, group_len)
    

if m == 0:
  print(1)
else:
  for i in range(n):
    if not visited[i]:
      bfs(i, visited)

  print(groups)

Measured memory_bytes: 55804
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hashmap = new HashMap<>();
        int n = sc.nextInt();
        for (int i=0;i<n;i++){
            hashmap.put(sc.next(),1);
        }
        if (hashmap.size()==4){
            System.out.println("Four");
        }else {
            System.out.println("Three");
        }
    }
}


Measured memory_bytes: 35548
#include <iostream>
typedef long long ll;

int main()
{
    ll N;
    std::cin >> N;

    if (N % 2 != 0)
    {
        std::cout << 0 << std::endl;
    }
    else
    {
        ll K = N / 2;
        ll cnt = 0;
        while (K != 0)
        {
            cnt += K / 5;
            K /= 5;
        }
        std::cout << cnt << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;

int n, k;
int64_t a[maxN];

int64_t fwt[maxN];

void upd(int idx, int val) {
    for(; idx < maxN; idx += idx & -idx)
        fwt[idx] += val;
}

int64_t sum(int idx) {
    int64_t total = 0;
    for(; idx > 0; idx -= idx & -idx)
        total += fwt[idx];
    return total;
}

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

    cin >> n >> k;

    vector<int64_t> vv;
    vv.push_back(0);

    for(int i = 1; i <= n; i++) {
        int x;  cin >> x;
        a[i] = a[i - 1] + (x - k);
        vv.push_back(a[i]);
    }

    sort(vv.begin(), vv.end());
    int L = unique(vv.begin(), vv.end()) - vv.begin();
    vv.resize(L);

    map<int64_t, int> pos;
    int counter = 0;

    for(auto x : vv)
        pos[x] = ++counter;

    upd(pos[0], 1);

    int64_t ans = 0;

    for(int i = 1; i <= n; i++) {
        a[i] = pos[a[i]];
        ans += sum(a[i]);
        upd(a[i], 1);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 20472
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll r;
 cin>>r;
 cout<< r*r <<endl;
}

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

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

    if(S.size() <= K ){
        cout << S << endl;
    }
    else{
        for (int i=0; i < K; ++i){
            cout << S[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3140
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto x = readln.chomp.to!long;
  long money = 100;
  long cnt;
  while (x > money) {
    money = (money * 1.01).to!long;
    cnt++;
  }
  cnt.writeln;
}


Measured memory_bytes: 2640
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(S)R(W);
  P(S<=W?"unsafe":"safe");
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

int A[N], B[N], C[N];

int main(){
	fastio;
	int x, y; cin>>x>>y;
	int a,b,c; cin>>a>>b>>c;
	For(i,0,a) cin>>A[i];
	For(i,0,b) cin>>B[i];
	For(i,0,c) cin>>C[i];
	sort(A,A+a); reverse(A,A+a);
	sort(B,B+b); reverse(B,B+b);
	sort(C,C+c); reverse(C,C+c);
	priority_queue<int, vi, greater<int> > pq;
	For(i,0,x) pq.push(A[i]);
	For(i,0,y) pq.push(B[i]);
	For(i,0,c) if(C[i]>pq.top()){
		pq.pop();
		pq.push(C[i]);
	}else break;
	ll acum=0;
	while(!pq.empty()){
		acum+=pq.top();
		pq.pop();
	}
	cout << acum << endl;
	return 0;
}


Measured memory_bytes: 10996
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    long m = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        m += x - 1;
    }
    cout << m << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 998244353
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
    int N;
    cin >> N;
    vector<int> D;
    int A[N + 1];
    fill(A, A + N + 1, 0);
    int ans = 1;
    rep(i, N)
    {
        int a;
        cin >> a;
        D.push_back(a);
    }
    if (D[0] != 0)
    {
        cout << "0" << endl;
        return 0;
    }
    sort(D.begin(), D.end());
    if (D[1] == 0)
    {
        cout << "0" << endl;
        return 0;
    }
    for (int i = 0; i < N; i++)
    {
        A[D[i]]++;
    }
    for (int i = 1; i <= N; i++)
    {
        int calc = 1;
        for (int j = 1; j <= A[i]; j++)
        {
            calc = (calc * A[i - 1]) % INF;
        }
        ans = (ans * calc) % INF;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2168
import java.math.BigInteger;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N];
		BigInteger a = new BigInteger("0");
		int b = 0;
		
		for(int i=0; i<N; i++) {
			A[i] = in.nextInt();
		}
		
		for(int i=0; i<N; i++) {
			if(!(i == 0) && A[i-1] > A[i]){
				b = A[i-1] - A[i];
				A[i] += b;
				a = a.add(BigInteger.valueOf(b));
				b = 0;
			}
		}
		
		System.out.println(a);
	}
}


Measured memory_bytes: 60096
#include <iostream>
#include <vector>
#include <deque>
#include <utility>

int main() {
    int h, w, white = 0;
    std::cin >> h >> w;
    std::vector<std::vector<int>> v(h, std::vector<int>(w));
    std::string s;

    for (int i = 0; i < h; i++) {
        std::cin >> s;
        for (int j = 0; j < w; j++) {
            v[i][j] = ((s[j] == '.') ? (white++, 1) : 0);
        }
    }

    std::vector<std::vector<int>> visited(h, std::vector<int>(w, 0));
    std::deque<std::pair<int, int>> q;
    q.push_back(std::make_pair(0,0));
    visited[0][0] = 1;

    bool flg = false;

    while(!q.empty()) {
        auto& next = q.front();
        if (next.first > 0 && v[next.first - 1][next.second] == 1 && visited[next.first - 1][next.second] == 0) {
            q.push_back(std::make_pair(next.first - 1, next.second));
            visited[next.first - 1][next.second] = visited[next.first][next.second] + 1;
        }
        if (next.first < h - 1 && v[next.first + 1][next.second] == 1 && visited[next.first + 1][next.second] == 0) {
            q.push_back(std::make_pair(next.first + 1, next.second));
            visited[next.first + 1][next.second] = visited[next.first][next.second] + 1;

            if (next.first + 1 == h - 1 && next.second == w - 1) {
                flg = true;
                break;
            }
        }
        if (next.second > 0 && v[next.first][next.second - 1] == 1 && visited[next.first][next.second - 1] == 0) {
            q.push_back(std::make_pair(next.first, next.second - 1));
            visited[next.first][next.second - 1] = visited[next.first][next.second] + 1;
        }
        if (next.second < w - 1 && v[next.first][next.second + 1] == 1 && visited[next.first][next.second + 1] == 0) {
            q.push_back(std::make_pair(next.first, next.second + 1));
            visited[next.first][next.second + 1] = visited[next.first][next.second] + 1;

            if (next.first == h - 1 && next.second + 1 == w - 1) {
                flg = true;
                break;
            }
        }
        q.pop_front();
    }

    std::cout << (flg ? white - visited[h-1][w-1] : -1) << std::endl;

    return 0;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(a[0]):
  b[i]=(b[i]+1)/2
c=0
for i in range(a[1]):
  c+=b[i]
c=[c]
for i in range(1,a[0]-a[1]+1):
  d=c[i-1]
  d+=b[i+a[1]-1]-b[i-1]
  c.append(d)
print(max(c))
  

Measured memory_bytes: 25060
s = input()
a = s.count("a")
b = s.count("b")
c = s.count("c")
k = (a > 0) + (b > 0) + (c > 0)
if k == 1:
  if len(s) >= 2:
    print("NO")
  else:
    print("YES")
  exit()
if k == 2:
  if len(s) == 2:
    print("YES")
  else:
    print("NO")
  exit()
minabc = sorted([a, b, c])[0]
a = max(0, a - minabc)
b = max(0, b - minabc)
c = max(0, c - minabc)
# print(a, b, c, k)
if a <= 1 and b <= 1 and c <= 1:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int i,j,k;
        Scanner sc= new Scanner(System.in);

        while(true){
            int n= sc.nextInt();
            int x=sc.nextInt(); 

            if(n==0&&x==0){
                break;
            }

            int time=0;

            for(i=2;i<n;i++){
                for(j=1;j<i;j++){
                    for(k=0;k<j;k++){
                        if(x==i+j+k+3){
                            time++;
                        }
                    }
                }
            }
            System.out.println(time);
        }
    }    
}


Measured memory_bytes: 26684
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;
//与えられたキーをもつノードを探し、そのポインタを返す
NodePointer listSearch(int key){
    /* your code */
    NodePointer *x;
    x=&nil->next;
    while((*x)!=nil && (*x)->key!=key){
        x=&(*x)->next;
    }
    return *x;
}
//双方向連結リストの初期化
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
//ポインタを繋ぎかえることで指定されたノードを削除する
void deleteNode(NodePointer t){
  /* your code */
  if(t==nil){
      return;
  }
  t->prev->next=t->next;
  t->next->prev=t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
//それぞれのノードのprevとnextが指すノードを削除する
void deleteLast(){
  /* your code */
  deleteNode(nil->prev);
}
//削除するキーが指定される、検索したノードの削除

void delete(int key){
  /* your code */
deleteNode(listSearch(key));
}

//与えられたキーをもつノードを生成しリストの先頭に追加する
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* your code */
  //ni->nextが次のノードを指す
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 36108
using System;
using System.Linq;
using static System.Math;

namespace abc126A
{
    class Program
    {
        static void Main(string[] args)
        {
            
            //string a = Console.ReadLine;
            //int a = int.Parse(Console.ReadLine());
            //for (int i = 0; i < N; i++){}
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] b = new long[4] { a[0] * a[2], a[0] * a[3], a[1] * a[2], a[1] * a[3] };
            Array.Sort(b);
            Console.WriteLine(b[3]);
        }
    }
}


Measured memory_bytes: 28212
a,b = map(int, input().split())
s = input()

s1 = s[:a]
s2 = s[a]
s3 = s[-b:]

if s2 != '-':
    print('No')
    quit()
try:
    i1 = int(s1)
    i2 = int(s3)
except:
    print('No')
    quit()
print('Yes')

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

int main() {
  int n;
  cin >> n;
  long A[n+1], B[n], ans=0.0;
  rep(i,0,n+1) cin >> A[i];
  rep(i,0,n) cin >> B[i];

  rep(i,0,n) {
  int left=min(A[i],B[i]);
  A[i] -= left;
  B[i] -= left;
  ans += left;

  int right=min(A[i+1], B[i]);
  B[i] -= right;
  A[i+1] -= right;
  ans += right;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792