akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,u,v;
vector<vector<int>> G;
void input(){
    fast_io();
    cin >> N >> u >> v;
    u--,v--;
    G.resize(N);
    for (int i = 0; i < N-1; i++)
    {
        int a,b; cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }   
}

void bfs(int s, vector<int> &dp){
    queue<int> q;
    q.push(s);
    dp[s] = 0;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(auto v:G[u]){
            if(dp[v]>=0) continue;
            dp[v] = dp[u]+1;
            q.push(v);
        }
    }
}

int solve(){
    vector<int> A(N,-1),T(N,-1);
    bfs(u,T);
    bfs(v,A);
    int ans = 0;
    int m = N+1;
    for (int i = 0; i < N; i++)
    {
        if(T[i]==A[i]) m = min(m,T[i]);
    }
    if(m==N+1) m = 0;
    ans = m;
    for (int i = 0; i < N; i++)
    {
        if(T[i]>=A[i]) continue;
        int tmp = T[i];
        int d = A[i]-T[i]-1;
        ans = max(ans,tmp+d);
    }
    cout << ans << endl;
    return 0;
}   

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

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


n = int(input())
node = {key: Node(-1, -1, -1) for key in range(n)} 
for i in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] != -1:
        node[tmp[0]].left = tmp[1]
        node[tmp[1]].parent = tmp[0]
    if tmp[2] != -1:
        node[tmp[0]].right = tmp[2]
        node[tmp[2]].parent = tmp[0]

def get_depth(node, D, u, d):
    D[u] = d
    if node[u].left != -1:
        get_depth(node, D, node[u].left, d+1)
    if node[u].right != -1:
        get_depth(node, D, node[u].right, d+1)


def get_height(node, H, u):
    h_l = 0   
    h_r = 0
    if node[u].left != -1:
        h_l = get_height(node, H, node[u].left) + 1
    if node[u].right != -1:
        h_r = get_height(node, H, node[u].right) + 1
    ans = max(h_l, h_r)
    H[u] = ans
    return ans

def get_sibling(node, u):
    parent = node[u].parent
    if parent is -1:
        return -1
    if node[parent].left != -1 and node[parent].left != u:
        ans = node[parent].left
    elif node[parent].right != -1 and node[parent].right != u:
        ans = node[parent].right
    else :
        ans = -1
    return ans

def get_degree(node, u):
    deg = 0
    if node[u].left != -1:
        deg +=1
    if node[u].right != -1:
        deg +=1
    return deg

for k, v in node.items():
    if v.parent is -1:
        root = k

D = {}
get_depth(node, D, root, 0)
H = {}
get_height(node, H, root)

def print_for_a_node(u):
    parent = node[u].parent
    sib = get_sibling(node, u)
    deg = get_degree(node, u)

    node_type = 'internal node' if deg != 0 else 'leaf'
    if parent == -1:
        node_type = 'root'

    print(f'node {u}: parent = {parent}, sibling = {sib}, degree = {deg}, depth = {D[u]}, height = {H[u]}, {node_type}')


for i in range(n):
    print_for_a_node(i)



Measured memory_bytes: 5636
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int n,a,b;

int k[10000010];

int main()
{
	int ans=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i)
	{
		cin>>k[i];
		if(k[i]<a||k[i]>=b) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

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

const int MAX = 2e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, M, Q;
int L[MAX], R[MAX];
int p[MAX], q[MAX];
int sum[510][510];

int main() {
  // 入力
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) scanf("%d %d", L + i, R + i);
  for (int i = 0; i < Q; i++) scanf("%d %d", p + i, q + i);

  for (int i = 0; i < M; i++) sum[L[i]][R[i]]++;
  // 累積和をとる
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      sum[i][j] += sum[i-1][j];
      sum[i][j] += sum[i][j-1];
      sum[i][j] -= sum[i-1][j-1];
    }
  }

  for (int i = 0; i < Q; i++) {
    cout << sum[q[i]][q[i]] - sum[p[i]-1][q[i]] - sum[q[i]][p[i]-1] + sum[p[i]-1][p[i]-1] << endl;
  }
  return 0;
}


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

int main() {
  int a,b;
  cin>>a;
  b = 0;
  
  for(int i=1;i<=a;i++){
  	//cout<<i;
    
    if(i>=0&&i<10){
    	b++;
      //cout<<"W";
    }
    
    if(i>=100&&i<1000){
    	b++;
      //cout<<"E";
    }
   
    if(i>=10000&&i<100000){
    	b++;
    }
    
  }
  
  
  cout<<b<<endl;
  return 0;
}
  

Measured memory_bytes: 256
var
	N,i:Longint;
	A,B:Array[1..100000]of int64;
	sum,all,k:int64;
begin
	read(N);
	for i:=1 to N do begin
		read(A[i]);
		inc(sum,A[i]);
		if i>1 then B[i-1]:=A[i]-A[i-1];
	end;
	B[N]:=A[1]-A[N];
	all:=(N+1)*N div 2;
	if sum mod all<>0 then begin
		writeln('NO');
		exit;
	end;
	K:=sum div all;
	for i:=1 to N do begin
		dec(B[i],K);
		if(B[i]>0)or(B[i]mod N<>0)then begin
			writeln('NO');
			exit;
		end;
	end;
	writeln('YES');
end.


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	int B[N];
	B[0] = A[0];
	int posneg = -1;
	for(int i = 1; i < N; i++){
		B[i] = B[i-1] + posneg*A[i];
		posneg *= -1;
	}
	int ansdiv2[N];
	ansdiv2[0] = B[N-1]/2;
	posneg = 1;
	for(int i = 1; i < N; i++){
		ansdiv2[i] = posneg*(B[i-1]-ansdiv2[0]);
		posneg *= -1;
	}
	cout << ansdiv2[0]*2;
	for(int i = 1; i < N; i++){
		cout << " " << ansdiv2[i]*2;
	}
	cout << "\n";
}


Measured memory_bytes: 2432
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()
    A.sort()

    # Aがあるサイズ以上であればその色にできる
    # 自分より小さいやつを全部吸収した後で、自分より大きいやつを全部吸収できるか
    A_cum = [0] * (N + 1)
    for i in range(N):
        A_cum[i+1] = A_cum[i] + A[i]

    l = [A_cum[i] * 2 >= A[i] for i in range(1, N)]
    l.reverse()
    if False in l:
        print(l.index(False) + 1)
    else:
        print(N)

if __name__ == '__main__':
    resolve()


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

using namespace std;

bool is_753_num(int num, int limit) {
    if (num > limit) {
        return false;
    }

    int q = num;
    int mod = 0;
    int num_of_3 = 0;
    int num_of_5 = 0;
    int num_of_7 = 0;

    while (q != 0) {
        mod = q % 10;
        switch (mod) {
        case 3:
            num_of_3++;
            break;
        case 5:
            num_of_5++;
            break;
        case 7:
            num_of_7++;
            break;
        }
        q /= 10;
    }

    if (num_of_3 >= 1 && num_of_5 >= 1 && num_of_7 >= 1) {
        return true;
    }    
    return false;
}

int traverse_tree_by_dfs(int64_t sum, int limit) {
    int answer = 0;

    if (sum > limit) {
        return answer;
    }

    if (is_753_num(sum, limit)) {
        answer++;
    }

    answer += traverse_tree_by_dfs(3 + (10 * sum), limit);
    answer += traverse_tree_by_dfs(5 + (10 * sum), limit);
    answer += traverse_tree_by_dfs(7 + (10 * sum), limit);

    return answer;
}

int main(int argc, char *argv[]) {
    int N;
    cin >> N;

    cout << traverse_tree_by_dfs(0, N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int ans[12000];

void add(int nu,int de){ // 答えに nu/de を加算
	rep(i,12000){
		ans[i]+=nu/de;
		nu%=de;
		nu*=10;
	}
}

int main(){
	for(int n,m,r;scanf("%d%*d%d%d",&n,&m,&r),n;){
		rep(i,12000) ans[i]=0;

		if(m==0){
			add(1,n);
		}
		else{
			add(1,n);
			rep(i,n-1) add(1,(i+1)*n);
		}

		for(int i=11999;i>0;i--) if(ans[i]>=10) {
			int d=ans[i]/10;
			ans[i]-=d*10;
			ans[i-1]+=d;
		}

		printf("%d.",ans[0]);
		rep(i,r) putchar('0'+ans[i+1]);
		puts("");
	}

	return 0;
}

// code for guessing answer
/*
#include<stack>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n,k;

int simu(const int *a){
	stack<int> S[100];
	rep(i,n) rep(j,k) S[i].push(a[i*k+j]);

	int ans=0,len=0;
	while(1){
		ans++;
		int i;
		for(i=0;S[i].empty();i++);
		while(!S[i].empty()){
			int tmp=i;
			i=S[i].top(); S[tmp].pop();
			len++;
		}
		if(len==k*n) return ans;
	}
}

int main(){
	while(~scanf("%d%d",&n,&k)){
		int de=0,nu=0;
		int p[100];
		rep(i,n) rep(j,k) p[i*k+j]=i;
		do{
			int res=simu(p);
			if(res==1) nu++;
			// if(res<=2) nu++;
			de++;
		}while(next_permutation(p,p+k*n));
		printf("%d/%d\n",nu,de);
	}

	return 0;
}
*/

Measured memory_bytes: 1088
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  int N,A[100];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  int cnt(0);
  int now(A[0]);
  int cnti(1);
  for (int i(1);i<N;i++){
    if (A[i]==now){
      cnti++;
    }else{
      //cout << cnti << endl;
      cnt+=cnti/2;
      cnti = 1;
      now = A[i];
    }
  }
  cnt+=cnti/2;
  cout << cnt << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < 500000; i++) {
            if ((int) (i * 1.08) == N) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(":(");
    }

}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    for(cin>>N;N;--N){
        int t,x,y;
        cin>>t>>x>>y;
        if(t<x+y||(t-x-y)&1)return cout<<"No",0;
    }
    return cout<<"Yes",0;
}

Measured memory_bytes: 256
import sys
count=[0]*4
for i in range(3):
    a,b=map(int,input().split())
    if a==1 or b==1:
        count[0]+=1
    if a==2 or b==2:
        count[1]+=1
    if a==3 or b==3:
        count[2]+=1
    if a==4 or b==4:
        count[3]+=1
for i in range(4):
    if count[i]>2:
        print('NO')
        sys.exit(0)
else:
    print('YES')

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

int main() {
  double N, K;
  cin >> N >> K;
  double res = 0;
  if (N >= K) {
    res = (N-K)/N;
  }
  for (int i = 1; i <= min(N, K); i++) {
    int tmp = i;
    double memo = 1/N;
    while (tmp < K) {
      tmp *= 2;
      memo /= 2;
    }
    res += memo;
  }
  cout << fixed << setprecision(10);
  cout << res << endl;
}


Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    vector<ll> pre(n+1,0);
    for(ll i=1;i<=n;i++)
    {
        pre[i] = (pre[i-1]+v[i])%k;//-1];
    }
    for(ll i=1;i<=n;i++)
    {
        pre[i] = (pre[i]-i+1000*k)%k;
    }
    map<ll,ll> mp;
    ll cs = 0;
    ll ans = 0;
    mp[0]=1;
    for(ll i=1;i<=n;i++)
    {
//        cout<<ans<<endl;
        if(i>=k)
        {
            mp[pre[i-k]]--;
        }
        ll z = pre[i];
        ans += mp[z];
        mp[z]++;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 15872
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
long bignum = 1_000_000_007;
alias Restaurant = Tuple!(string, "shop", long, "point", long, "id");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto guide = new Restaurant[](n);
    foreach (i; 0 .. n)
    {
        string shop;
        long point;
        scan(shop, point);
        guide[i] = Restaurant(shop, point, i + 1);
    }
    guide.sort!"a.shop == b.shop ? a.point > b.point : a.shop < b.shop"();
    foreach (e; guide)
    {
        e.id.writeln();
    }
}

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

int main() {
  long n,q,t,u,v;
  cin >> n >> q;
  dsu d(n);
  for(long i=0;i<q;i++) {
    cin >> t >> u >> v;
    if(t==0) d.merge(u,v);
    else if(d.same(u,v)) cout << 1 << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 3940
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int ans=INF;
  for(int i=a[0];i<=a[n-1];i++){
    int temp=0;
    for(int j=0;j<n;j++){
      temp+=pow((a[j]-i),2);
    }
    if(temp<ans)ans=temp;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int n,k,s;
signed main(){
    cin>>n>>k;
    if(n==k){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#define ll long long
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	int c=a+b;
	if(c<a-b){
		c=a-b;
	} 
	if(c<a*b){
		c=a*b;
	}
	cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
# N = gets.chomp.to_i
# H = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars # array of chars
K = gets.chomp.to_i

cnts = [] # <<chr, cnt>>
cnt = 1
chr = S[0]
1.upto(S.size-1).each do |i|
  if S[i] == S[i-1]
    cnt += 1
  else
    cnts << [chr, cnt]
    chr = S[i]
    cnt = 1
  end
end
cnts << [chr, cnt]

# p cnts

if cnts.size == 1
  p (cnts[0][1] * K) / 2
else
  if cnts[0][0] == cnts[-1][0] # the char of pre and sub are same
    ans = 0
    ans += cnts[0][1] / 2
    ans += cnts[-1][1] / 2
    ans += (cnts[0][1] + cnts[-1][1]) / 2 * (K-1)  # united
    cnts[1..-2].each do |(chr, cnt)|
      ans += cnt / 2 * K
    end
    p ans
  else
    ans = 0
    cnts.each do |(chr, cnt)|
      if cnt > 1
        ans += cnt / 2
      end
    end
    p ans * K
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste
// #include "UnionFind.h"
// #include "power.h"


signed main() {
    int N;
    cin >> N;
    int odd = 0;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] % 2 == 1) ++odd;
    }
    int even = N - odd;
    if (odd % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t h, w, k;
    cin >> h >> w >> k;

    vector<vector<bool>> m(h, vector<bool>(w));
    vector<int64_t> nums(h);
    for (auto i : irange(0L, h)) {
        string s;
        cin >> s;
        for (auto j : irange(0L, w)) {
            m[i][j] = (s[j] == '#');
            nums[i] += (m[i][j] ? 1 : 0);
        }
    }

    int64_t idx = 1;
    vector<vector<int64_t>> ans(h, vector<int64_t>(w));
    int64_t i0 = 0;
    while (nums[i0] == 0) {
        ++i0;
    }
    for (auto i : irange(i0, h)) {
        if (nums[i] > 0) {
            for (auto j : irange(0L, w)) {
                ans[i][j] = idx;
                if (m[i][j] && idx < ans[i][0] + nums[i] - 1) {
                    ++idx;
                }
                ++j;
            }
            ++idx;
        } else {
            for (auto j : irange(0L, w)) {
                ans[i][j] = ans[i - 1][j];
            }
        }
    }

    for (auto i : irange(0L, i0)) {
        for (auto j : irange(0L, w)) {
            ans[i][j] = ans[i0][j];
        }
    }

    for (auto i : irange(0L, h)) {
        const auto* delim = "";
        for (auto j : irange(0L, w)) {
            cout << delim << ans[i][j];
            delim = " ";
        }
        cout << "\n";
    }
}

Measured memory_bytes: 1536
#include<cstdio>
#include<algorithm>
const int Mod=1e9+7;
const int inv2=(Mod+1)/2;
typedef long long ll;
int n,deg[5100];
ll fac[5100],inv[5100],f[5100][5100][2],ans;
int main(){
    scanf("%d",&n); bool flag=1;
    fac[0]=1; for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%Mod;
	inv[1]=1; for (int i=2;i<=n;i++) inv[i]=(Mod-Mod/i)*inv[Mod%i]%Mod;
	inv[0]=1; for (int i=1;i<=n;i++) inv[i]=inv[i-1]*inv[i]%Mod;
    for (int i=1;i<=n;i++){
    	scanf("%d",&deg[i]);
		flag=flag&&(deg[i]==2);
	}
    if (flag){
		printf("%lld\n",fac[n-1]*inv2%Mod);
		return 0;
	}
    f[0][0][0]=1;
    for (int i=0;i<n;i++)
        for (int j=0;j<=i;j++)
            for (int k=0;k<2;k++){
                if (deg[i+1]>0) f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k]*inv[deg[i+1]-1])%Mod;
                if (deg[i+1]>1) f[i+1][j+1][k]=(f[i+1][j+1][k]+f[i][j][k]*inv[deg[i+1]-2])%Mod;
                if (deg[i+1]>2&&!k) f[i+1][j+1][1]=(f[i+1][j+1][1]+f[i][j][k]*inv[deg[i+1]-3])%Mod;
            }
    for (int i=3;i<n;i++) ans=(ans+f[n][i][1]*fac[n-i-1]%Mod*fac[i-1]%Mod*inv2)%Mod;
	printf("%lld\n",ans);
    return 0;
}

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

int main() {
  int N;
  scanf("%d",&N);
  int d[N];
  for (int i=0; i<N; i++) {
    scanf("%d",&d[i]);
  }
  sort(d,d+N);
  int max=1;
  for (int i=0; i<N-1; i++) {
    if (d[i]<d[i+1]) {
      max++;
    }
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

int bit[20000010];

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];  
  vector<ll> ans;
  
  ROF(i,n-1,0){
    //cerr << i << endl;
    //bit on
    if(a[i] == 1){
      if(bit[i+1]%2==0){
	bit[i+1]++;      
	ans.push_back(i+1);
	vector<ll> primes = divisor((ll)(i+1));
	//cerr << "num: " << i+1 << endl;
	for(ll j=0; j<primes.size(); j++){
	  //cerr << "j: " << j << " elm: " << primes[j] << endl;
	  bit[primes[j]]++;
	}
      }
    }else {
      //奇数
      if(bit[i+1]%2!=0){
	bit[i+1]++;
	ans.push_back(i+1);
	vector<ll> primes = divisor((ll)(i+1));
	for(ll j=0; j<primes.size(); j++){
	  //cerr << "j: " << j << " elm: " << primes[j] << endl;
	  bit[primes[j]]++;
	}	
      }
    }
    /*
    for(int j=0; j<=n; j++){
      cerr << bit[j] << " ";
    }
    cerr << endl;
    */
  }
  cout << ans.size() << endl;
  for(auto &e: ans) cout << e << endl;
  return 0;
}


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

typedef long long ll;

int V, E, src, snk;
vector<int> la, nxt, oppo;
vector<ll> capa;
void init() {
    E = 0;
    la.clear(); nxt.clear(); oppo.clear(); capa.clear();
    la = vector<int>(V, -1);
}
void add(int u, int v, ll c) {
    nxt.push_back(la[u]);
    la[u] = E++;
    oppo.push_back(v);
    capa.push_back(c);
}
vector<int> dist;
queue<int> q;
bool bfs() {
    dist = vector<int>(V, -1);
    q.push(src);
    dist[src] = 0;
    while(!q.empty()) {
        int u = q.front(); q.pop();

        for(int i = la[u]; i != -1; i = nxt[i]) {
            int v = oppo[i];
            if(capa[i] && dist[v] == -1) {
                q.push(v);
                dist[v] = dist[u] + 1;
            }
        }
    }
    return dist[snk] != -1;
}
vector<int> laa;
ll dfs(int u, ll f) {
    if(u == snk) return f;
    for(int i = laa[u]; i != -1; i = nxt[i]) {
        laa[u] = i;
        int v = oppo[i];
        if(capa[i] && dist[v] == dist[u] + 1) {
            if(ll tmp = dfs(v, min(f, capa[i]))) {
                capa[i] -= tmp;
                capa[i^1] += tmp;
                return tmp;
            }
        }
    }
    return 0;
}
ll dinic() {
    ll tf = 0;
    while(bfs()) {
        laa = la;
        while(ll tmp = dfs(src, 1e18)) tf += tmp;
    }
    return tf;
}

int N;
vector<int> arr;

int main() {
    scanf("%d", &N);

    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }

    V = N + 2, src = V - 2, snk = V - 1;
    init();

    ll sum = 0;
    for(int i = 0; i < N; i++) {
        if(arr[i] < 0) {
            add(src, i, -arr[i]);
            add(i, src, 0);
        }
        else {
            add(i, snk, arr[i]);
            add(snk, i, 0);
            sum += arr[i];
        }
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 2*i; j <= N; j += i) {
            add(i - 1, j - 1, 1e18);
            add(j - 1, i - 1, 0);
        }
    }

    cout << sum - dinic();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		int k;
		cin >> n >> k;
		int a[n+1];
		rep(i,1,n+1) cin >> a[i];
		double cur = 0;
		rep(i,1,k+1) cur += ((a[i]*(a[i]+1))*1.0)/(2*a[i]);
		double ans = cur;
		rep(i,1,n-k+1){
			cur -= ((a[i]*(a[i]+1))*1.0)/(2*a[i]);
			cur += ((a[i+k]*(a[i+k]+1))*1.0)/(2*a[i+k]);
			ans = max(ans,cur);
		}
		cout<<fixed<<setprecision(10)<<ans;
	}
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    int L, R;
    cin >> L >> R;

    for(int i = 1; i < M; i++){
        int LL, RR;
        cin >> LL >> RR;
        if(L < LL)
            L = LL;
        if(R > RR)
            R = RR;
    }
    cout << ((R >= L) ? R - L + 1: 0) << endl;


}


Measured memory_bytes: 256
#include <stdio.h>

int func(int, int);

int main(void)
{
  int d, i;
  int sum = 0;
  while (scanf("%d", &d)!=EOF)
    {
      sum = 0;
      for (i=0; i<600/d; i++)
        {
          sum += func(d*i, d);
        }
      printf("%d\n", sum);
    }
  return 0;
}

int func(int x, int d) {
  return d * x * x;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
 
#define rep(i,n) for(int i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

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

    ll x,i=0,a = 100;
    cin >> x;
    while(1){
        i++;
        a *= 1.01;
        if(a >= x){ 
            cout << i << endl;
            break;
        }
        
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3664
import java.util.Scanner;
class Main {
	static String reverse(String target){
		String ret="";
		for(int i=target.length()-1;0<=i;i--){
			ret+=target.charAt(i);
		}
		return ret;
	}
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String str=scan.next();
		int q=scan.nextInt();
		String cmd;
		int a,b;
		for(int i=0;i<q;i++){
			cmd=scan.next();
			if(cmd.equals("replace")){
				a=scan.nextInt();
				b=scan.nextInt();
				cmd=scan.next();
				str=str.substring(0,a)+cmd+str.substring(b+1,str.length());
			}else if(cmd.equals("reverse")){
				a=scan.nextInt();
				b=scan.nextInt();
				String r=reverse(str.substring(a,b+1));
				cmd=str.substring(0,a);
				cmd+=r;
				cmd+=str.substring(b+1,str.length());
				str=cmd;
			}else{
				a=scan.nextInt();
				b=scan.nextInt();
				System.out.println(str.substring(a,b+1));
			}
		}
		scan.close();
	}

}

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

int main() {
  string s;
  cin >> s;
  if(((s.at(0) == s.at(1)) && (s.at(0) == s.at(2))) || ((s.at(1) == s.at(2)) && (s.at(1)== s.at(3)))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  char x, y; cin >> x >> y;
  if (x == y) cout << '=' << '\n';
  else cout << (x < y ? '<' : '>') << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int cnt = 0, n = s.size();
	rep(i,n) if(s.at(i) == 'g') cnt++;
	cout << (cnt * 2 - n) / 2 << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_7_C {
    class Node {
        public int Parent { get; set; }
        public int Left { get; set; }
        public int Right { get; set; }

        public Node() {
            Parent = -1;
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            var nodes = Enumerable.Range(0, n).ToDictionary(i => i, i => new Node());

            for (int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                int id = int.Parse(input[0]);
                int left = int.Parse(input[1]);
                int right = int.Parse(input[2]);

                nodes[id].Left = left;
                if (left != -1)
                    nodes[left].Parent = id;
                nodes[id].Right = right;
                if (right != -1)
                    nodes[right].Parent = id;
            }

            int root = SearchRoot(nodes);
            Console.WriteLine("Preorder");
            Preorder(nodes, root);
            Console.WriteLine();
            Console.WriteLine("Inorder");
            Inorder(nodes, root);
            Console.WriteLine();
            Console.WriteLine("Postorder");
            Postorder(nodes, root);
            Console.WriteLine();
        }

        static int SearchRoot(Dictionary<int, Node> nodes) {
            for (int i = 0; i < nodes.Count; i++)
                if (nodes[i].Parent == -1)
                    return i;
            return -1;
        }

        static void Preorder(Dictionary<int, Node> nodes, int id) {
            if (id == -1)
                return;
            Console.Write(" " + id);
            Preorder(nodes, nodes[id].Left);
            Preorder(nodes, nodes[id].Right);
        }

        static void Inorder(Dictionary<int, Node> nodes, int id) {
            if (id == -1)
                return;
            Inorder(nodes, nodes[id].Left);
            Console.Write(" " + id);
            Inorder(nodes, nodes[id].Right);
        }

        static void Postorder(Dictionary<int, Node> nodes, int id) {
            if (id == -1)
                return;
            Postorder(nodes, nodes[id].Left);
            Postorder(nodes, nodes[id].Right);
            Console.Write(" " + id);
        }
    }
}

Measured memory_bytes: 9868
#include <iostream>
#include <map>
#include <vector>
using namespace std;

using ll = long long;

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

	map<ll,ll> m;
	ll cur;

	for (ll i = 0; i < n; i++) {
		cin >> cur;
		m[cur]++;
	}
	ll s = m.size();
	if (s > 3 || s == 0) {
		cout << "No" << endl;
		return 0;
	}

	if (s == 1) {
		if (cur == 0) {
			cout << "Yes" << endl;			
		} else {
			cout << "No" << endl;						
		}
		return 0;
	}

	vector<ll> v;
	if (s == 2) {
		if (n % 3 != 0) {
			cout << "No" << endl;	
			return 0;		
		}
		for (auto value : m) {
			if (value.second == (n / 3) * 2) {
				v.push_back(value.first);
				v.push_back(value.first);
				continue;
			}
			if (value.second == n / 3) {
				v.push_back(value.first);
				continue;
			}
			cout << "No" << endl;
			return 0;
		}
	}
	if (s == 3) {
		for (auto value : m) {
			if (value.second != n / 3) {
				cout << "No" << endl;
				return 0;
			}
			v.push_back(value.first);
		}
	}
	if ((v[0] ^ v[2]) != v[1]) {
		cout << "No" << endl;	
		return 0;
	}
	if ((v[1] ^ v[0]) != v[2]) {
		cout << "No" << endl;
		return 0;	
	}
	if ((v[1] ^ v[2]) != v[0]) {
		cout << "No" << endl;
		return 0;	
	}
	cout << "Yes" << endl;	

	return 0;
}

Measured memory_bytes: 5120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();


    void solve()
    {
        var S = cin.scan;
        Console.WriteLine("A" + S[1][0] + "C");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}


Measured memory_bytes: 2648
#include <iostream>

using namespace std;

bool P[10001];

void eratos()
{
	for( int i = 0;i < 10001;i++ ) P[i] = true;
	P[0] = P[1] = false;
	for( int i = 2;i * i < 10001;i++ ){
		if( P[i] ) for( int j = 2;i * j < 10001;j++ ) P[i * j] = false;
	}
}

int main(int argc, char const* argv[])
{
	int n;

	eratos();
	while( cin >> n && n != 0 ){
		for( int i = n;i >= 0;i-- ){
			if( P[i] && P[i - 2] ){
				cout << i - 2 << " " << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 876
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        c: usize,
        v: chars
    }
    let mut fs = vec![];
    let mut ls = vec![];
    let mut i = 0;
    loop {
        while v[i] == 'x' {
            i += 1;
        }
        fs.push(i);
        if fs.len() == k {
            break;
        }
        i += c + 1;
    }
    i = n - 1;
    loop {
        while v[i] == 'x' {
            i -= 1;
        }
        ls.push(i);
        if ls.len() == k {
            break;
        }
        i -= c + 1;
    }
    ls.reverse();
    for i in 0..k {
        if fs[i] == ls[i] {
            println!("{}", fs[i] + 1);
        }
    }
}


Measured memory_bytes: 12052
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int factorial(int n)
{
	int a=1;

	if (n == 0)
		return 1;

	for (int i = 1; i <= n; i++)
		a *= i;

	return a;
}

int Con(int a, int b)
{
	return factorial(a) / (factorial(b) * factorial(a - b));
	
}

int a[20] = { 0 };

//int binary_search(int key)  
//{
//	int low, high, middle;
//
//	low = 0;
//	high = 20 - 1;
//
//
//
//	while (low <= high)
//	{
//		middle = (low + high) / 2;
//		if (key == a[middle])
//			return middle;
//		else if (key < a[middle])
//			high = middle - 1;
//		else if (key > a[middle])
//			low = middle + 1;
//	}
//	return INF;
//}

int binary_search(long long int key)
{
	long long int low = 0, high = 2000000000, middle;
	long long int p;

	while (low <= high)
	{
		middle = (low + high) / 2;
		//printf("%d    \n", middle);

		p = (middle * (middle + 1));

		if (p == key*2)
			return middle;
		else if (p >key*2)
			high = middle - 1;
		else
			low = middle + 1;
	}
	return 0;

}

int main()
{
	char S[200];

	scanf("%s", S);

	for (int i = 0; S[i] != '\0'; i++)
		printf("x");
}


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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

// vector<vector<int>> gen_A_vec(const vector<int>& prev_A, int min_n, int max_n, int len) {
//   if (prev_A.size() == len) {
//     return vector<vector<int>>{prev_A};
//   }

//   vector<vector<int>> retv;
//   for (int i = min_n; i <= max_n; i++) {
//     vector<int> now_A = prev_A;
//     now_A.push_back(i);

//     vector<vector<int>> next_A_vec = gen_A_vec(now_A, min_n, max_n, len);
//     for (auto A : next_A_vec) {
//       retv.push_back(A);
//     }
//   }
//   return retv;
// }

bool gen_next_A(vector<int>& A, int min, int max) {
  int N = A.size();
  for (int i = N - 1; i >= 0; --i) {
    if (A[i] < max) {
      int n = ++A[i];
      for (int j = i + 1; j < N; ++j) {
        A[j] = n;
      }
      return true;
    }
  }

  return false;
}

int calc_score(const vector<int>& A, const vector<int>& a, const vector<int>& b,
               const vector<int>& c, const vector<int>& d) {
  int score = 0;
  
  for (size_t i = 0; i < a.size(); ++i) {
    if (A[b[i]-1] - A[a[i]-1] == c[i]) {
      score += d[i];
    }
  }

  return score;
}



int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M, Q;
  cin >> N >> M >> Q;

  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (size_t i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  // main procedure
  vector<int> A = vector<int>(N, 1);

  int max_score = 0;
  
  int count = 0;
  
  while (true) {
    int score = calc_score(A, a, b, c, d);
    max_score = max(max_score, score);

    // for (auto x : A) {
    //   WRITE(x);
    //   WRITE(", ");
    // }
    // WRITE(": ");
    // WRITE_N(score);
    // if (++count > 20) break;

    bool is_next_A_exist = gen_next_A(A, 1, M);
    if (is_next_A_exist == false) {
      break;
    }
  }

  // output
  WRITE_N(max_score);

  return 0;
}


Measured memory_bytes: 3616
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
int main()
{
	int n;
	while(cin>>n&&n){
		while(n--){
			int a,b,c,d,e,f,g,h;
			cin>>a>>b>>c>>d>>e>>f>>g>>h;
			printf("%d %d %d %d\n",a*e-b*f-c*g-d*h,a*f+b*e+c*h-d*g,a*g-b*h+c*e+d*f,a*h+b*g-c*f+d*e);
		}
	}
    return 0;
}

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

ans = 0
count = 0
best = 0

for i in range(n, 0, -1):
    count = 0
    x = i
    while True:
        if x % 2 == 0:
            count += 1
            x = x / 2
        else:
            break
    if count > best:
        best = count
        ans = i
        
if ans == 0:
    ans = 1

print(ans)


Measured memory_bytes: 3060
import sys


input = sys.stdin.readline
k, s = map(int, input().split())

# min_num = s - k * 2
# if min_num <= 0:
min_num = 0

ans = 0

for x in range(min_num, k + 1):
    for y in range(min_num, k + 1):
        z = s - x - y
        if z > k or z < 0:
            continue
        else:
            ans += 1

print(ans)

Measured memory_bytes: 40684
N=int(raw_input())
A=[0 for i in range(N)]
s = raw_input().split()
for i in range(N):
    A[i] = int(s[i])

#print A

p = 0
n = 0
while (p < N):
    if A[p] == n+1:
        n = n+1
    p += 1

if n==0:
    print -1
else:
    print N-n


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << '+' << endl;
	} else if (a * b == 15) {
		cout << '*' << endl;
	} else {
		cout << 'x' << endl;
	}
}

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

#define INF -1

int x[100000];
int y[100000];
int sum[100000];
int MAX,MAX2;
int sum2=0;
int sum3=0;

int main(){
	string S;
	cin>>S;
	x[0]=10000;
	for(int i=0;i<S.size();i++){
		if(S[i]=='/'){
			x[i+1]=x[i]+1;
		}
		else if(S[i]=='_'){
			x[i+1]=x[i];
		}
		else{
			x[i+1]=x[i]-1;
		}
	}
	for(int i=0;i<=S.size();i++){
		MAX=INF;
		for(int j=i;j>=0;j--){
			MAX=max(MAX,x[j]);
		}
		MAX2=INF;
		for(int j=i;j<=S.size();j++){
			MAX2=max(MAX2,x[j]);
		}
		y[i]=min(MAX,MAX2);
	}
	for(int i=0;i<=S.size();i++){
		if(sum[sum2]>=1 && y[i]-x[i]==0){
			sum3 += sum[sum2];
			sum2++;
		}
		else{
			sum[sum2] += y[i]-x[i];
		}
	}
	cout<<sum3<<endl;
	cout<<sum2;
	for(int i=0;i<sum2;i++){
		cout<<' '<<sum[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    rep(i, n)
    {
        if (a[i] == b[i] && b[i] == c[i])
            continue;
        else if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i])
            ans++;
        else
            ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){	
	int a,b[100000],c[100000],d[100000],e=0;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b[i]>>c[i]>>d[i];
		if((c[i]+d[i]-b[i])%2==0 && c[i]+d[i]<=b[i]){
			e++;
		}

	}
	if(e==a){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 1408
import math
n = input()
x = map(float, raw_input().split())
y = map(float, raw_input().split())
d1 = 0.0
d2 = 0.0
d3 = 0.0
d4 = 0.0
for i in range(n):
    d1 += abs(x[i] - y[i])
    d2 += pow(abs(x[i] - y[i]),2)
    d3 += pow(abs(x[i] - y[i]),3)
    d4 = max(d4,abs(x[i] - y[i]))
d2 = math.sqrt(d2)
d3 = d3 ** (1.0 / 3.0)
print d1
print d2
print d3
print d4


Measured memory_bytes: 4828