akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ll n;
    cin>>n;
    ll arr[100001][3];
    for(ll i=0; i<n; i++)
    {
        for(ll j=0; j<3; j++)
        {
            cin>>arr[i][j];
        }
    }
    ll dp[100001][3]={0};
    for(ll i=0; i<n; i++)
    {
        dp[i][0]=max(arr[i][0]+dp[i-1][1], arr[i][0]+dp[i-1][2]);
        dp[i][1]=max(arr[i][1]+dp[i-1][0], arr[i][1]+dp[i-1][2]);
        dp[i][2]=max(arr[i][2]+dp[i-1][0], arr[i][2]+dp[i-1][1]);
    }
    
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
	return 0;
}

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

int main() {
  int N,L;
  cin >> N >> L; 
  
  int T1 = 0;
  for(int i = 0; i < N; i++){
    T1 += L + i+1 -1; //味の総和求める
  }

 
  
  vector<int> vec(N);
  
    for(int i = 0; i < N; i++){
    vec[i] = abs(L + i+1 -1);//N個のリンゴの味の絶対値の配列作成
  }

  
   sort(vec.begin(), vec.end());//リンゴの味の絶対値の配列を小さい順に並べる
     
  int T2;
  if(T1 < 0){
  T2 = T1 + vec[0];
  }
  else{
    T2 = T1 - vec[0];
  }
  cout << T2 << endl;
 
}

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

using namespace std;
typedef long long LL;
const int N = 200001;
const int mod = 924844033;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

struct edge {
	int x, y, next;
} e[2 * N]; int len, last[N];
int tot[N], ans[N], jc[N], inv[N];
int A[N << 2], B[N << 2], R[N << 2];

void ins(int x, int y) {
	e[++len].x = x, e[len].y = y;
	e[len].next = last[x], last[x] = len;
}

int pow_mod(int a, int k) {
	int ans = 1;
	while(k) {
		if(k & 1) ans = (LL)ans * a % mod;
		a = (LL)a * a % mod, k /= 2;
	} return ans;
}

int add(int x, int y) {
	x += y;
	return x >= mod ? x - mod : x;
}

int dec(int x, int y) {
	x -= y;
	return x < 0 ? x + mod : x;
}

int C(int n, int m) {return (LL)jc[n] * inv[m] % mod * inv[n - m] % mod;}

void NTT(int y[], int len, int on) {
	for(int i = 1; i < len; i++) if(i < R[i]) swap(y[i], y[R[i]]);
	for(int i = 1; i < len; i <<= 1) {
		int wn = pow_mod(5, (mod - 1) / (i << 1));
		if(on == -1) wn = pow_mod(wn, mod - 2);
		for(int j = 0; j < len; j += i << 1) {
			int w = 1;
			for(int k = 0; k < i; k++, w = (LL)w * wn % mod) {
				int u = y[j + k], v = (LL)y[j + k + i] * w % mod;
				y[j + k] = add(u, v), y[j + k + i] = dec(u, v);
			}
		}
	} if(on == -1) {
		int hh = pow_mod(len, mod - 2);
		for(int i = 0; i < len; i++) y[i] = (LL)y[i] * hh % mod;
	}
}

void dfs(int x, int fa) {
	tot[x] = 1;
	for(int k = last[x]; k; k = e[k].next) {
		int y = e[k].y;
		if(y != fa) dfs(y, x), tot[x] += tot[y];
	}
}

int main() {
	int n = read();
	for(int i = 1; i < n; i++) {
		int x = read(), y = read();
		ins(x, y), ins(y, x);
	} dfs(1, 0);
	jc[0] = 1; for(int i = 1; i <= n; i++) jc[i] = (LL)jc[i - 1] * i % mod;
	inv[n] = pow_mod(jc[n], mod - 2); for(int i = n; i >= 1; i--) inv[i - 1] = (LL)inv[i] * i % mod;
	for(int i = 1; i <= n; i++) ans[i] = (LL)C(n, i) * n % mod;
	int len; for(len = 1; len <= 2 * n; len <<= 1);
	for(int i = 1; i < len; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) * (len >> 1));
	for(int i = 2; i <= n; i++) A[tot[i]]++;
	for(int i = 2; i <= n; i++) A[n - tot[i]]++;
	for(int i = 1; i <= n; i++) A[i] = (LL)A[i] * jc[i] % mod;
	for(int i = 0; i <= n; i++) B[(len - i) % len] = inv[i];
	NTT(A, len, 1), NTT(B, len, 1);
	for(int i = 0; i < len; i++) A[i] = (LL)A[i] * B[i] % mod;
	NTT(A, len, -1);
	for(int i = 1; i <= n; i++) ans[i] = dec(ans[i], (LL)A[i] * inv[i] % mod), put(ans[i]), puts("");
	return 0;
}

Measured memory_bytes: 28032
n,m = map(int,input().split())
py = []
for i in range(m):
    num = i+1
    p,y = map(int,input().split())
    py.append([num,p,y])
py = sorted(py, key = lambda x:x[1]*10**10+x[2])
x = 0
b = '000000'
ans = []
for pyi in py:
    if pyi[1] != x:
        x = pyi[1]
        cnt = 1
    else:
        cnt += 1
    ans.append([pyi[0], (b+str(pyi[1]))[-6:], (b+str(cnt))[-6:]])
ans = sorted(ans, key = lambda x: x[0])
for ansi in ans:
    print(ansi[1]+ansi[2])

Measured memory_bytes: 46936
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

char c;

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> c;
   if ('A' <= c && c <= 'Z') cout << 'A';
   else cout << 'a';
}               
 
signed main () {                                       
   #ifdef QWERTY
      freopen("input", "r", stdin);
   #endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
vector<int> f(int n, int x, vector<vector<int>> &t) {
	vector<int> d(n), vis(n);
	queue<int> q;
	q.push(x);
	vis[x] = 1;
	while(!q.empty()) {
		int now = q.front();
		q.pop();
		for(int i = 0; i < t[now].size(); i++) {
			int nxt = t[now][i];
			if(vis[nxt]) continue;
			vis[nxt] = 1;
			d[nxt] = d[now] + 1;
			q.push(nxt);
		}
	}
	return d;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n; cin >> n;
	vector<vector<int>> t(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		t[a].push_back(b);
		t[b].push_back(a);
	}
	vector<int> b = f(n, 0, t), w = f(n, n - 1, t);
	int res = 0;
	for(int i = 0; i < n; i++) {
		if(b[i] <= w[i]) res++;
		else res--;
	}
	cout << (res > 0 ? "Fennec" : "Snuke") << endl;
	return 0;	
}


Measured memory_bytes: 6924
# coding: utf-8
import numpy as np
N,P = list(map(int, input().split()))
S = '0'+input()

#N=200000
#P=9893
#S= '0'+'1234567890' * 20000

if (P==2)|(P==5):
    sum=0
    for i in range(N, 0, -1):
        if int(S[i]) % P == 0:
            sum+= i
    print(sum)


else:
    dp1 = np.zeros(N + 1)
    dp2 = np.zeros(N + 1)
    dp3 = np.zeros(P)
    dp1[N] = int(S[N]) % P
    dp3[int(dp1[N])] += 1
    k = 1
    for i in range(N - 1, 0, -1):
        dp1[i] = (dp1[i + 1] + (int(S[i]) * 10 * k)) % P
        dp3[int(dp1[i])] += 1
        k = (k * 10) % P

    sum = 0

    for i in range(P):
        if i == 0:
            sum += (dp3[i] * (dp3[i] - 1)) // 2 + dp3[i]
            continue
        if dp3[i] == 0: continue
        sum += (dp3[i] * (dp3[i] - 1)) // 2
    print(int(sum))


Measured memory_bytes: 14320
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int N, K; cin >> N >> K;
  vi h(N);
  REP(i, N) cin >> h[i];
  int ans = 0;
  REP(i, N) {
    if(h[i]>=K) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;


int getGcd(int a, int b) {
	//cout << a << ":" << b << endl;
	if (a%b == 0) {
		return b;
	}

	return getGcd(b, a%b);
}

int main() {
	int w, h, c, gcd;

	cin >> w >> h >> c;
	gcd = getGcd(w, h);
	//cout << gcd << endl;
	cout << c*w*h / gcd / gcd << endl;
	
	return 0;
}



Measured memory_bytes: 3100
n,w = map(int,input().split())
item = [list(map(int,input().split())) for i in range(n)]

dp = [[float('inf')]*(10**5+1) for i in range(n+1)]
dp[0][0] = 0

for i in range(1,n+1):
    for j in range(10**5+1):
        if j >= item[i-1][1]:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-item[i-1][1]]+item[i-1][0])
        else:
            dp[i][j] = dp[i-1][j]
for j in range(10**5+1):
    if dp[n][j] <= w:
        ans = j

print(ans)

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

int main()
{
	int N;
	int A[200];
	int count = 0;
	bool flag = true;

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

	while (true)
	{
		for (int i = 0; i < N; i++)
		{
			if (A[i] % 2 != 0)
			{
				flag = false;
				break;
			}
			else
			{
				A[i] /= 2;
			}
		}
		if (flag == true)
			count++;
		else
			break;
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n, tmp, ans, p[10000000];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> tmp;
    ans = max(ans, p[tmp] = p[tmp-1] + 1);
  }
  cout << n - ans << endl;
}

Measured memory_bytes: 2816
N=int(input())
S=[input()[0] for _ in range(N)]
A=[S.count(c) for c in "MARCH"]
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=A[i]*A[j]*A[k]
print(ans)


Measured memory_bytes: 9988
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
//        InputReader in = new InputReader(new FileInputStream("/Users/KeFA/projects/competitve/src/main/java/input.txt"));
        PrintWriter out = new PrintWriter(System.out);

        while (in.ready()) {
            long n = in.nextLong();
            int i;
            for (i = 0; i * i <= n; i++);

            System.out.println((i - 1) * (i - 1));
        }
        out.flush();
        out.close();
    }

    private static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}


Measured memory_bytes: 23252
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	vll cnt(26,INF) ;
	ll n ; cin >> n ;
	for(int i=0;i<n;i++){
		string s ; cin >> s ;
		vll sub(26,0) ;
		for(int j=0;j<s.size();j++) sub.at(s.at(j)-'a')++ ;
		for(int j=0;j<26;j++) cnt.at(j) = min(cnt.at(j),sub.at(j)) ;
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<cnt.at(i);j++) cout << (char)('a'+i) ;
	}
	cout << endl ;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int f(int x) {
  if (x == 0) return 0;
  return f( x % __builtin_popcount(x) ) + 1;
}

int main() {
  IOS;
  int n; cin >> n;
  string s; cin >> s;
  vector<int> x(n);
  REP(i,n) x[i] = s[i]-'0';
  int pc = 0; // popcount
  REP(i,n) pc += x[i];
  vector<int> ans(n);

  REP(b,2) {
    int npc = b == 0 ? pc+1 : pc-1;
    if (npc <= 0) continue;

    int r0 = 0;
    // 2進数から10進数整数を算出
    REP(i,n) {
      r0 = (r0*2)%npc;
      r0 += x[i];
    }

    int k = 1;
    for (int i = n-1; i>=0; i--) {
      if (x[i] == b) {
        int r = r0;
        if (b == 0) r = (r+k)%npc;
        else r = (r-k+npc)%npc;
        ans[i] = f(r)+1;
      }
      k = (k*2)%npc;
    }
  }

  REP(i,n) COUT(ans[i]);
  return 0;
}

Measured memory_bytes: 5136
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main()
{
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int r, g, b;
	cin >> r >> g >> b;

	if ((r * 100 + g * 10 + b) % 4 == 0)
	{
		cout << "YES\n";
	}
	else
	{
		cout << "NO\n";
	}

	return 0;
}



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

struct Point {
    double x, y;
};

void koch(int n, Point a, Point b) {
    if (n == 0) {
        return;
    }

    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

int main() {
    Point a, b;
    int n;
    cin >> n;
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
using ll =  long long;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
ll C[55][55];
void comb(){
    for(int i=0;i<55;++i){
        for(int j=0;j<=i;++j){
            if(i == 0 || i == j) C[i][j] = 1;
            else C[i][j] = C[i-1][j-1] + C[i-1][j];
        }
    }
}
ll MOD=1e9+7;
int main() {
    int n,a,b;
    cin>>n>>a>>b;
    vector<ll> v(n);
    for(auto & t : v) cin>>t;
    double maximum = 0.0;
    sort(v.rbegin(),v.rend());
    for(int i=0;i<a;++i)maximum += v[i];
    maximum /= a;
    comb();
    int x = 0;
    int num = 0;
    REP(i,n){
        if(v[i] == v[a-1]){num++;if(i<a)x++;}
    }
    ll ret = 0LL;
    if(x == a){
        for(int x=a;x<=b;++x)ret += C[num][x];
    }else ret += C[num][x];
    cout << fixed;
    cout << setprecision(20);
    cout << maximum << endl;
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nmax 1<<19
using namespace std;
int n,v[nmax];
bool viz[nmax];
vector <int> a;

int main() 
{

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

    sort(v, v + (1 << n));
    reverse(v, v + (1 << n));

    a.push_back(v[0]);
    viz[0] = 1;
    for (int i = 0; i < n; i++) {
        int k = 1;
        for (int j = 0; j < (1 << i); j++) {

            while (k < (1 << n) && (v[k] >= a[j] || viz[k]))
                k++;

            if (k == (1 << n)) {
                cout << "No";
                return 0;
            }
            viz[k] = 1;
            a.push_back(v[k]);
        }
        sort(a.begin(), a.end());
        reverse(a.begin(), a.end());
    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int n,k,a[200010];
void solve()
{
    cin>>n;
    int ans=0,cur=1;
    while(n)
    {
        ans+=cur;
        n/=2;
        cur*=2;
    }
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n,k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans=(n-1)%(k-1)==0?(n-1)/(k-1):(n-1)/(k-1)+1;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define INF (ll)(1e12)

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

    ll n, w;
    cin >> n >> w;

    ll weight[n], val[n];
    for (int i = 0; i < n; i++)
        cin >> weight[i] >> val[i];
    
    ll dp[n + 1][w + 1];

    for (int i = 0; i < w + 1; i++)
        dp[0][i] = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            ll ans = -INF;
            if (j - weight[i - 1] >= 0)
                ans = dp[i - 1][j - weight[i - 1]] + val[i - 1];

            ans = max(ans, dp[i - 1][j]);

            dp[i][j] = ans;
        }
    }

    ll maxi = 0;
    for (int i = 0; i <= w; i++)
        maxi = max(maxi, dp[n][i]);
    
    cout << maxi << "\n";
}


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


int main(){
	string S;
	cin >> S;
	for(int i = 0; i < S.size()-1;i++){
		if(S[i] != S[i+1]){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

ll gcd(ll a, ll b){
  if(b == 0) return a;
  else return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;
  n++;
  ll ans = 0;
  rep(i, 1, n)rep(j, 1, n)rep(k, 1, n){
    ll ab = gcd(i, j);
    ans += gcd(ab, k);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <cstring>
#include <iostream>
#define M 1000000007
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    long long dp[2][n+2];
    memset(dp, 0, sizeof(dp));
    int cur = 0, prev = 1;
    dp[prev][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[cur][j] = 2 * dp[prev][j] + 2 * dp[prev][j+1];
            if (j > 0) dp[cur][j] += dp[prev][j-1] - 2 * dp[prev][j];
            else dp[cur][j] += dp[prev][j] - 2 * dp[prev][j+1];
            dp[cur][j] = (dp[cur][j] % M + M) % M;
        }
        swap(cur, prev);
    }
    cout << ((dp[prev][s.size()] - 2 * dp[prev][s.size()+1]) % M + M) % M << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main(){
 int S,W;
 cin>>S>>W;
 if(S>W){
   cout<<"safe"<<endl;
 }else{
   cout<<"unsafe"<<endl;
 }
}

Measured memory_bytes: 3044
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var dx = new bool[n];
        var dy = new bool[n];
        var a = new int[n];
        var b = new int[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]) - 1;
            var y = int.Parse(line[1]) - 1;
            a[x] = y;
            b[y] = x;
            if (dx[x]) { Console.WriteLine(-1); goto exit; }
            else dx[x] = true;
            if (dy[y]) { Console.WriteLine(-1); goto exit; }
            else dy[y] = true;
        }
        getAns(n, a, b);
    exit:;
    }
    static void getAns(int n, int[] a, int[] b)
    {
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] == i) continue;
            else
            {
                var t = b[i];
                var t2 = a[i];
                b[i] = i;
                b[t2] = t;
                a[i] = a[t];
                a[t] = t2;
                count++;
            }
        }
        Console.WriteLine(count);
    }
}



Measured memory_bytes: 20496
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int x = a % b;
    int y = b - x;
    cout<<min(x,y)<<endl;
    return 0;
    
}



Measured memory_bytes: 256
n = int(input())
W = [input() for i in range(n)]
word = W[0]
words = [word]
for i in range(1,n):
  if W[i] in words or word[-1] != W[i][0]:
    print("No")
    break
  word = W[i]
  words.append(word)
else:
  print("Yes")

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

int main()
{
	int a, b, S, L;
	
	cin >> a >> b;
	
	S = a*b;
	L = 2*(a+b);
	
	cout << S << ' ' << L << endl;
	
	return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>

void insertion();
void show();
void bubble();

int count = 0;

int main(void){
	int size, i;
	scanf("%d",&size);
	int a[size];

	for(i = 0; i < size; i++)
		scanf("%d",&a[i]);

	//insertion(a, size);
	bubble(a, size);
	show(a, size);
	printf("%d\n",count);
	return 0;
}

void insertion(int x[], int len){
	int i, j, v;
	for(i = 1; i < len; i++){
		v = x[i];
		for(j = i - 1; j >= 0; j--){
			if(x[j] > v){
				x[j+1] = x[j];
			} else break;
		}
		x[j+1] = v;
		show(x, len);
	}
}

void bubble(int x[], int len){
	int flag = 1, j, temp;
	while(flag){
		flag = 0;
		for(j = len-1; j > 0; j--){
			if(x[j] < x[j-1]){
				temp = x[j];
				x[j] = x[j-1];
				x[j-1] = temp;
				flag = 1;
				count++;
			}
		}
	}
}

void show(int x[], int len){
	int i;
	printf("%d",x[0]);
	for(i = 1; i < len; i++){
		printf(" %d",x[i]);
	}
	printf("\n");
}

Measured memory_bytes: 1772
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int N = cin.nextInt();
			int ans=0;
			if(N==-1){
				break;
			}
			if(N<=10){
				ans=1150;
			}
			else if(N<=20){
				ans+=1150;
				N-=10;
				ans+=N*125;
			}
			else if(N<=30){
				ans+=1150;
				ans+=10*125;
				N-=20;
				ans+=N*140;
			}
			else{
				ans+=1150;
				ans+=10*125;
				ans+=10*140;
				N-=30;
				ans+=N*160;
			}
			System.out.println(4280-ans);
		}

	}

}

Measured memory_bytes: 12000
import java.util.Scanner;

public class  Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); //台形の面積を求める
        int a = sc.nextInt(); //ペンキa
        int b = sc.nextInt(); //ペンキb
        int c = sc.nextInt(); //ペンキc
        
        if(a == b && b == c){
            System.out.println(1);
        }
        else if(a != b && b != c && a != c){
            System.out.println(3);
        }
        else{
            System.out.println(2);
        }
    }     
}


Measured memory_bytes: 21588
/**
 * @jakestrj
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "bits/stdc++.h"
using namespace std;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define rep(i, j, k) for(int i=(j);i<(k);++i)
#define repi(i, j, k) for(int i=(j);i<=(k);++i)
#define per(i, j, k) for(int i=(j);i>(k);--i)
#define peri(i, j, k) for(int i=(j);i>=(k);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(), greater<int>()
#define mem(a, b) memset(a, (b), sizeof(a))
#define mem2(a, b) memset(a, (b), sizeof(a[0][0])*len(a)*len(a[0]))
#define sz(x) ((int)(x).size())
#define len(x) (int)(sizeof(x)/sizeof(x[0]))
#define endl "\n"
#define INF 1e18
#define EPS 1e-9
#define PI 2*acos(0)
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
typedef tuple<int, int, int> trio;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef map<int,int> mpii;
typedef set<int> si;

#define pli pair<ll, int>
struct C {
	void solve(std::istream& cin, std::ostream& cout) {
		int n; cin >> n;
		vector<pli > uns, X;
		repi(i, 1, n){
			 ll x; cin >> x;
			 X.eb(x, i); uns.eb(x, i);
		}
		sort(all(X), [&](pli a, pli b){
			return a.f < b.first;
		});
		int res[n+1];
		rep(i, 0, n){
			ll val = X[i].f; int idx = X[i].s;
			int l = ((n)>>1);
			res[idx] = X[l - (i>=l?1:0)].first;
		}
		repi(i, 1, n) cout << res[i] << endl;
	}
};


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


Measured memory_bytes: 11100
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if((a==5 && b==5 && c==7)||(a==5 && b==7 && c==5)||(a==7 && b==5 && c==5)){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 1e9
long double PI =3.14159265358979323846;
 
const ll M=1e12;
const ll inf=1e18;
const ll ms=10000000;
fast;
ll ans,n,m;
void solve()
{
    cin>>n;ll ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    sort(ar,ar+n);
    cout<<ar[n/2]-ar[n/2-1]<<endl;
    
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
w = list(map(int, input().split()))

for i in range(n):
    if sum(w[0:i+1]) == sum(w[i+1:n]):
        print(0)
        exit()

    elif sum(w[0:i+1]) > sum(w[i+1:n]):
        gap0 = sum(w[0:i+1])-sum(w[i+1:n])
        gap1 = sum(w[i:n])-sum(w[0:i])
        print(min(gap0,gap1))
        exit()

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) { a = b; return 1; }
    return 0;
}

template <class T> bool chmin(T &a, const T &b) {
    if (b < a) { a = b; return 1;}
    return 0;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x; 
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi b(n - 1);
    REP(i, n - 1) cin >> b[i];

    int ans = b[0];

    REP(i, n - 2) {
        ans += min(b[i], b[i + 1]);
        // xcout << min(b[i], b[i + 1]) << endl;
    }

    cout << ans + b.back() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define rep(i,a,n) for(int i =a;i<n;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	ios;
	string f,r;
	int c=0;
	cin>>f>>r;
	rep(i,0,3)
	{if(f[i]==r[i])
	{c++;
	}
	}
	cout<<c<<endl;
	return 0;
	
}


Measured memory_bytes: 256
def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w < h:
        h, w = w, h
    if h == 1:
        return 1
    min_diff = h * w
    vals = [0, 0, 0]
    for i in range(1, w // 2 + 1):
        vals[0] = i * h
        if h % 2 == 0:
            vals[1] = (w - i) * (h // 2)
            vals[2] = vals[1]
        else:
            vals[1] = (w - i) * (h // 2 + 1)
            vals[2] = (w - i) * (h // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
        if (w - i) % 2 == 0:
            vals[1] = h * ((w - i) // 2)
            vals[2] = vals[1]
        else:
            vals[1] = h * ((w - i) // 2 + 1)
            vals[2] = h * ((w - i) // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
    h, w = w, h
    for i in range(1, w // 2 + 1):
        vals[0] = i * h
        if h % 2 == 0:
            vals[1] = (w - i) * (h // 2)
            vals[2] = vals[1]
        else:
            vals[1] = (w - i) * (h // 2 + 1)
            vals[2] = (w - i) * (h // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
        if (w - i) % 2 == 0:
            vals[1] = h * ((w - i) // 2)
            vals[2] = vals[1]
        else:
            vals[1] = h * ((w - i) // 2 + 1)
            vals[2] = h * ((w - i) // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
    return min_diff

_h, _w = map(int, input().split())
print(solve(_h, _w))


Measured memory_bytes: 43100
s = input()

dp = [[0 for i in range(13)] for j in range(len(s)+1)]

mod = 10**9+7
mul = 1
dp[0][0] = 1

for i in reversed(range(len(s))):
    keta = len(s) - i - 1
    if s[i] == '?':
        for k in range(10):
            for j in range(13):
                amari = (j+k*(mul)) % 13
                #print(amari,i)
                dp[keta+1][amari] += dp[keta][j]
                dp[keta+1][amari] %= mod
    else:
        num = int(s[i])
        for j in range(13):
            amari = (j+(num*(mul))) % 13
            #print(keta,amari)
            dp[keta+1][amari] += dp[keta][j]
            dp[keta+1][amari] %= mod
    mul = mul * 10 % 13
            
print(dp[len(s)][5])
#print(dp[len(s)][5])

Measured memory_bytes: 66396
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<iomanip>
 
#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)
 
void c(int x, int y, int p[][10]){
	if(x >= 0 && x < 10){
		if(y >= 0 && y < 10){
			p[x][y]++;
		}
	}
}

int main(){
	int p[10][10] = {0};

	int x, y, size;

	while(scanf("%d,%d,%d", &x, &y, &size) != EOF){
		switch(size){
		case 1:
			for(int i = x-1; i <= x+1; i++){
				for(int j = y-1; j <= y+1; j++){
					int d = abs(i-x) + abs(j-y);
					if(d <= 1){
						c(i, j, p);
					}
				}
			}
			break;
		case 2:
			for(int i = x-1; i <= x+1; i++){
				for(int j = y-1; j <= y+1; j++){
					c(i, j, p);
				}
			}
			break;
		case 3:
			for(int i = x-2; i <= x+2; i++){
				for(int j = y-2; j <= y+2; j++){
					int d = abs(i-x) + abs(j-y);
					if(d <= 2){
						c(i, j, p);
					}
				}
			}			
		}
		//for(int i = 0; i < 10; i++){
		//	for(int j = 0; j < 10; j++){
		//		cout << p[j][i];
		//	}
		//	cout << endl;
		//}
	}

	int max = 0;
	int count = 0;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			if(p[i][j] > max){
				max = p[i][j];
			}
			if(p[i][j] == 0){
				count++;
			}
		}
	}

	cout << count << endl;
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    ll m;
    cin >> n >> m;
    vector<int> cnt(200001, 0), v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        cnt[v[i]]++;
    }
    vector<int> sum = cnt;
    for(int i = 100000-1; i >= 0; i--)  sum[i] += sum[i+1];
    auto f = [&](int mid)->ll{
        ll ret = 0;
        for(int i = 100000; i >= 0; i--)    ret += (ll)cnt[i]*sum[max(mid-i,0)];
        return ret;
    };
    int l = 0, r = 200001;
    while(r-l > 1){
        int mid = (l+r)/2;
        if(f(mid) < m)  r = mid;
        else            l = mid;
    }
    vector<ll> cum(200001, 0);
    for(int i = 100000; i >= 0; i--)    cum[i] = cum[i+1]+(ll)i*cnt[i];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += (ll)v[i]*sum[max(0,l-v[i])] + cum[max(0,l-v[i])];
    }
    ans -= l*(f(l)-m);
    cout << ans << endl;
    return 0;
}

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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;
const int MAX_N = 1e5;
int dist[MAX_N] = {};

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

	vector<int> d(n);
	rep(i, n){
		cin >> d[i];
		dist[d[i]]++;
	}

	if(d[0] != 0 || dist[0] != 1){
		co(0);
		return 0;
	}
	rep(i, n){
		if(!dist[i]){
			FOR(j, i, n){
				if(dist[j]){
					co(0);
					return 0;
				}
			}
			break;
		}
	}
	
	ll ans = 1;
	repn(i, n-1){
		if(!dist[i]) break;
		rep(j, dist[i]){
			ans *= dist[i-1];
			ans %= MOD;
		}
	}

	co(ans);

	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
import itertools
from math import sqrt, factorial

def main():
    n = int(input().strip())
    x = [0] * n
    y = [0] * n
    for i in range(n):
        x[i], y[i] = map(int, input().strip().split())
    s = [0] * factorial(n)
    for k, perm in enumerate(itertools.permutations(range(n), n)):
        s[k] = 0
        for ind, i in enumerate(perm):
            if ind == 0:
                px, py = x[i], y[i]
                continue
            s[k] += sqrt((x[i] - px)**2 + (y[i] - py) ** 2)
            px, py = x[i], y[i]
    print(sum(s) / len(s))


if __name__ == '__main__':
    main()


Measured memory_bytes: 44124
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 int N;
 cin>>N;
 vector<int>a(N);
 int64_t r=0;
 for(int i=0;i<N;i++){
   cin>>a[i];
   r+=a[i];
 }
 int64_t l=0;
 int64_t ans=9999999999;
 for(int i=0;i<N-1;i++){
  l+=a[i];r-=a[i];
  ans=min(ans,abs(l-r));
 }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 4060
// fahadmd16(IIEST Shibpur)
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll, ll>
#define ALL(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define forab(i,a,b) for(ll i=a;i<b;i++)
#define clr(x) memset(x, 0, sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define endl "\n"
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define eps 1e-10
#define nedl endl
const ll sz = 1001;
const ll mod = 1e9 + 7;
typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;

ll power(ll n, ll k, ll m) {
    ll ans = 1;
    while (k) {
        if (k & 1)ans = (ans * n) % m;
        k /= 2;
        n = (n * n) % m;
    }
    return ans;
}



int main() {
    IOS;

    ll T = 1; //cin >> T;
    while (T--) {
        ll n,k;cin>>n>>k;
        ll ans=n%k;
        if(ans > abs(ans-k))
			ans=abs(ans-k);
		cout<<ans<<endl;
		

		
		
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
vector<int> g[111111];
int n,x,y,po,ans[111111],cnt,ccnt;
void dfs1(int i,int cur,int fa)
{
	ans[cur]=i;
	if (i==n)
	{
		po=ans[cur-(cur-1)/2];
		return;
	}
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j];
		if (to==fa) continue;
		dfs1(to,cur+1,i);
	}
}
void dfs2(int i,int fa,bool f)
{
	bool tmp;
	if (i==po) tmp=1;
	else tmp=f;
	if (tmp) cnt++;
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j];
		if (to==fa) continue;
		dfs2(to,i,tmp);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);  
	}
	dfs1(1,0,0);
	dfs2(1,0,0);
	ccnt=n-cnt;
	if (ccnt>cnt) cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

Measured memory_bytes: 12672
#include<queue>
#include<iostream>
using namespace std;
typedef long long LL;
priority_queue<LL>L;
priority_queue<LL,vector<LL>,greater<LL>>R;
LL tL,tR,ans;
int n,l[123456],r[114514];
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>l[i]>>r[i];
	L.push(l[1]),R.push(l[1]);
	for(int i=2;i<=n;++i){
		tL-=r[i]-l[i],tR+=r[i-1]-l[i-1];
		LL mnL=L.top()+tL,mnR=R.top()+tR;
		if(mnL<=l[i]&&l[i]<=mnR)L.push(l[i]-tL),R.push(l[i]-tR);else
		if(l[i]>mnR){
			ans+=l[i]-mnR,L.push(mnR-tL),R.pop();
			R.push(l[i]-tR),R.push(l[i]-tR);
		}else{
			ans+=mnL-l[i],R.push(mnL-tR),L.pop();
			L.push(l[i]-tL),L.push(l[i]-tL);
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 2804
import sys

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

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

def find(node, key):
    if node is None:
        return False
    elif node.key == key:
        return True
    elif node.key > key:
        return find(node.left, key)
    else:
        return find(node.right, key)

def delete(node, key):
    if node is not None:
        if node.key == key:
            reconstTree(node)
        elif node.key > key:
            delete(node.left, key)
        else:
            delete(node.right, key)

def reconstTree(node):
    if node.left is not None and node.right is not None:
        sib = node.right
        while sib.left is not None:
            sib = sib.left
        node.key = sib.key
        reconstTree(sib)
    else:
        parent = node.parent
        if node.left is not None:
            child = node.left
        elif node.right is not None:
            child = node.right
        else:
            child = None

        if parent.left == node:
            parent.left = child
        else:
            parent.right = child

        if child is not None:
            child.parent = parent

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "p":
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))
        else:
            com = line.split()
            if com[0][0] == "i":
                insert(Node(int(com[1])))
            elif com[0][0] == "f":
                if find(root, int(com[1])):
                    print "yes"
                else:
                    print "no"
            else:
                delete(root, int(com[1]))

Measured memory_bytes: 244284