akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[3005];
ll dp[3005];
ll sdp[3005];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    scanf("%s", str);

    int i,j;
    int curr = 0;
    int prev = 1;
    for(i=0; i<n; i++) {
        for(j=0; j<n-i; j++) {
            if(i==0) {
                dp[j]=1;
            }
            else if(str[i-1]=='<') {
                dp[j]=sdp[j+1];
            }
            else {
                dp[j]=(sdp[n-i+1]-sdp[j+1]+MOD)%MOD;
            }
        }

        sdp[0]=0;
        for(j=0; j<n-i; j++) {
            sdp[j+1]=(sdp[j]+dp[j])%MOD;
        }
    }
    printf("%lld\n", dp[0]);

    return 0;
}



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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i) a[i] += a[i-1];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    if (i) b[i] += b[i-1];
  }
  int ans(0);
  for (int i = 0; i < n && a[i] <= k; ++i) {
    int d = distance(b.begin(), upper_bound(b.begin(), b.end(), k - a[i]));
    ans = max(d + i + 1, ans);
  }
  for (int i = 0; i < m && b[i] <= k; ++i) {
    int d = distance(a.begin(), upper_bound(a.begin(), a.end(), k - b[i]));
    ans = max(d + i + 1, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, num = 0;
    cin >> N;

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1); 

    for(int i = 0; i < N; i++) cin >> A.at(i);
    for(int i = 0; i < N; i++) cin >> B.at(i);
    for(int i = 0; i < N - 1; i++) cin >> C.at(i);

    for(int i = 0; i < N; i++){
        num += B.at(A.at(i) - 1); 
        if(i != 0 && A.at(i - 1) + 1 == A.at(i)) num += C.at(A.at(i) - 2); 
    }   

    cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  string S;cin>>S;
  vector<int> schedule(4,0);
  REP(i,0,S.size()){
    if(S.at(i)=='N')schedule[0]=1;
    if(S.at(i)=='W')schedule[1]=1;
    if(S.at(i)=='S')schedule[2]=1;
    if(S.at(i)=='E')schedule[3]=1;
  }
  if((schedule[0]^schedule[2])||(schedule[1]^schedule[3]))print("No");
  else print("Yes");

}


Measured memory_bytes: 256
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

r=I()
if r<1200:
    print("ABC")
elif r<2800:
    print("ARC")
else:
    print("AGC")

Measured memory_bytes: 3316
/*  -*- coding: utf-8 -*-
 *
 * 2890.cc: Pivots
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

struct Node {
  int v;
  Node *lpt, *rpt, *ppt;
  Node() {}

  void print() {
    printf("(%d:P%d,L%d,R%d)",
	   v, ppt ? ppt->v : -1, lpt ? lpt->v : -1, rpt ? rpt->v : -1);
  }
};

/* global variables */

int as[MAX_N];
Node buf[MAX_N];

/* subroutines */

Node *maketree(int i0, int i1) {
  if (i0 >= i1) return NULL;
  int im = (i0 + i1) / 2;
  Node *npt = buf + as[im];
  npt->v = as[im];
  npt->ppt = NULL;
  if ((npt->lpt = maketree(i0, im)) != NULL) npt->lpt->ppt = npt;
  if ((npt->rpt = maketree(im + 1, i1)) != NULL) npt->rpt->ppt = npt;
  return npt;
}

void traverse(vi &v, Node *npt) {
  if (npt->lpt != NULL) traverse(v, npt->lpt);
  v.push_back(npt->v);
  if (npt->rpt != NULL) traverse(v, npt->rpt);
}

void printtree(Node *npt) {
  vi v;
  traverse(v, npt);
  //printf("root=%d: ", npt->v);
 for (int i = 0; i < v.size(); i++) {
    if (i) putchar(' ');
    printf("%d", v[i] + 1);
    //buf[v[i]].print();
  }
  putchar('\n');
}

Node *rot_l(Node *npt0) {
  if (npt0 == NULL || npt0->rpt == NULL) return npt0;
  Node *npt1 = npt0->rpt;
  npt0->rpt = npt1->lpt;
  if (npt1->lpt) npt1->lpt->ppt = npt0;
  npt1->lpt = npt0;
  npt1->ppt = npt0->ppt; npt0->ppt = npt1;
  if (npt1->ppt) {
    if (npt1->ppt->lpt == npt0) npt1->ppt->lpt = npt1;
    else npt1->ppt->rpt = npt1;
  }
  return npt1;
}

Node *rot_r(Node *npt0) {
  if (npt0 == NULL || npt0->lpt == NULL) return npt0;
  Node *npt1 = npt0->lpt;
  npt0->lpt = npt1->rpt;
  if (npt1->rpt) npt1->rpt->ppt = npt0;
  npt1->rpt = npt0;
  npt1->ppt = npt0->ppt; npt0->ppt = npt1;
  if (npt1->ppt) {
    if (npt1->ppt->lpt == npt0) npt1->ppt->lpt = npt1;
    else npt1->ppt->rpt = npt1;
  }
  return npt1;
}

Node *maketop(Node *npt) {
  while (npt->ppt != NULL) {
    Node *npt0 = npt->ppt;
    if (npt0->lpt == npt) rot_r(npt0);
    else rot_l(npt0);
  }
  return npt;
}

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);
  for (int i = 0; i < n; i++)
    scanf("%d", as + i), as[i]--;

  Node *root = maketree(0, n);
  //printtree(root);

  while (qn--) {
    int ai;
    scanf("%d", &ai);
    ai--;

    root = maketop(&buf[ai]);
    swap(root->lpt, root->rpt);
    //printtree(root);
  }

  printtree(root);
  return 0;
}



Measured memory_bytes: 6984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	sort(all(s));
	int k = count(all(s), s.back());
	int m = count(all(s), s.front());
	if (k == 2 && m == 2) puts("Yes");
	else puts("No");
 	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){

	int n;
	cin >> n;

	if( n == 0 || n == 2) {
		cout << 1 << endl;
	} else if( n == 1 ) {
		cout << 2 << endl;
	} else {
		cout << 0 << endl;
	}

    return 0;
}

Measured memory_bytes: 1164
def inner_product(a1, a2, b1, b2)
  a1 * b1 + a2 * b2
end

while line = gets
  xA, yA, xB, yB, xC, yC, xD, yD = line.chomp.split.map(&:to_f)
  puts inner_product(xA - xB, yA - yB, xC - xD, yC - yD).abs < 1e-12 ? :YES : :NO
end

Measured memory_bytes: 8556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
#define MODSIZE 1000000007

int main(){
  char a[14],b[14],c[14];
  int na,nb,nc;
  int cnt[27] = {0};

  scanf("%s %s %s", a, b, c);
  na = strlen(a);
  nb = strlen(b);
  nc = strlen(c);

  if(a[na - 1] == b[0] && b[nb - 1] == c[0]) printf("YES\n");

  else printf("NO\n");

  return 0;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;



bool get(int a, int b, int c, int k)
{
	if ( a < b and b < c) return 1;
	if (k == 0) return 0;
	int a1 = get(a, 2 * b, c, k - 1), a2 = get(a, b, 2 * c, k - 1);

	return a1 | a2;
}
void solve()
{
	int a, b, c;
	int k;
	cin >> a >> b >> c;
	cin >> k;
	bool a1 =  get(a, b, c, k );
	if (a1) cout << "Yes" << endl;
	else cout << "No" << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





















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

void rotate_s(int (*dice)[4]){
	swap(dice[0][1], dice[1][1]);
	swap(dice[0][1], dice[2][1]);
	swap(dice[0][1], dice[1][3]);
}

void rotate_n (int (*dice)[4]){
	swap(dice[0][1], dice[1][1]);
	swap(dice[1][1], dice[2][1]);
	swap(dice[2][1], dice[1][3]);
}

void rotate_e (int (*dice)[4]){
	swap(dice[0][1], dice[1][0]);
	swap(dice[1][2], dice[2][1]);
	swap(dice[1][0], dice[1][2]);
}

void rotate_w (int (*dice)[4]){
	swap(dice[0][1], dice[1][2]);
	swap(dice[1][0], dice[2][1]);
	swap(dice[1][0], dice[1][2]);
}

bool compare_dice(int (*dice1)[4], int (*dice2)[4]){
    if(dice1[0][1] == dice2[0][1] && dice1[1][1] == dice2[1][1] && dice1[1][2] == dice2[1][2] && dice1[1][0] == dice2[1][0] && dice1[1][3] == dice2[1][3] && dice1[2][1] == dice2[2][1]){
        return true;
    }
    return false;
}

bool judge(int (*dice1)[4], int (*dice2)[4]){
    string command = "NSNNNWNNNWNNNENNNENNNWNNN";
    bool hit = false;

    for(int i = 0; i < command.size(); i++){
		switch (command[i])
		{
		case 'E':
			rotate_e(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		case 'W':
			rotate_w(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		case 'N':
			rotate_n(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		case 'S':
			rotate_s(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		default:
			break;
		}
        if(hit) return true;
	}
    return false;
}

int main() {
	int dice1[3][4] = {{}};
    int dice2[3][4] = {{}};

    cin.tie(0);
    ios::sync_with_stdio(0);

	cin >> dice1[0][1] >> dice1[1][1] >> dice1[1][2] >> dice1[1][0] >> dice1[1][3] >> dice1[2][1];
	cin >> dice2[0][1] >> dice2[1][1] >> dice2[1][2] >> dice2[1][0] >> dice2[1][3] >> dice2[2][1];

    if(judge(dice1, dice2)) cout << "Yes" << endl;
    else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <string>
#include <limits.h>
#include <iomanip>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <set>
#include <bitset>
#include <unordered_map>
#include <string.h>
#define fastIo                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MOD 1000000007

using namespace std;
int main()
{
    fastIo;
    ll n;
    cin>>n;

    ll arr[n];
    ll sum = 0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
        sum%=MOD;
    }
    ll ans = 0;

    for(int i=0;i<n;i++)
    {
        sum-=arr[i];
        sum = (sum+MOD)%MOD;

        ans = (ans+(arr[i]*sum)%MOD)%MOD;
    }

    cout<<ans<<endl;
    
    

   
    return 0;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

vin leader;//大きのが前

bool judge(int x,int a){
  return leader[x]<a;
}



int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           vin a(n);
           rep(i,0,n)cin>>a[i];
           int ans=0;
           //cout<<ans<<endl;
           //二分探索で更新していくO(nlogn)
           leader.resize(0);
           int mn=inf;
           rep(i,0,n){
             if(mn>=a[i]){
              mn=a[i];
               leader.pb(a[i]);
               ans++;
             }
             else{//mn<a[i]
               //leader[x]<a[i]なる最小のxを探す
               int ng=-1;
               int ok=leader.size()-1;
               while(ok-ng>1){
                int mid=(ng-ok)/2+ok;
                 if(judge(mid,a[i]))ok=mid;
                 else ng=mid;
               }
               leader[ok]=a[i];
               if(ok==leader.size()-1)mn=a[i];
             }
           }
			cout<<ans<<endl;
}

Measured memory_bytes: 4256
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        A: [u64; N]
    }

    let mut ans = 0;
    let mut pre = 0;
    for a in A {
        if pre > a {
            ans += pre - a;
        } else {
            pre = a;
        }
    }

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


Measured memory_bytes: 5540
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
  long long n, res, ans;
  int p[65001], j[65001];

  while(true){
    scanf("%lld", &n);
    if(!n) break;
    res = 0;
    for(int i = 0;i < n; i++) scanf("%d", p + i);
    for(int i = 0;i < n - 1; i++) scanf("%d", j + i);
    
    sort(j, j + n - 1);

    for(int i = 0;i < n - 1; i++) res += p[i] + j[i];
    res += p[n - 1];
    ans = res;

    for(int i = 0;i < n - 1; i++){
      res -= j[i];
      if(ans > res * (i + 2))
	break;
      ans = max(ans, res * (i + 2));
    }
    
    printf("%lld\n", ans);
  }
}


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

typedef pair<int,int> P;

#define fr first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define pb push_back

const int N=20002;

int n,x[N],y[N];
vector<int> vs;
bitset<N> G[N],rG[N],al,nex,c,mask;
void dfs(int v){
	if(!al[v])return;
	al[v]=0;
	while(1){
		nex=al&G[v];
		int x=nex._Find_first();
		if(x==N)break;
		dfs(x);
	}
	vs.pb(v);
}
void scc(int v){
	if(!al[v])return;
	al[v]=0;
	while(1){
		nex=al&rG[v];
		int x=nex._Find_first();
		if(x==N)break;
		scc(x);
	}
	c[v]=1;
}
bool f(int d){
	vector<P> vec;
	rep(i,n){
		vec.pb(P(x[i],2*i));
		vec.pb(P(y[i],2*i+1));
	}
	sort(vec.begin(),vec.end());
	
	bitset<N> a,b;
	int l=0,r=0;
	for(P p: vec){
		while(r<2*n&&vec[r].fr<p.fr+d){
			a[vec[r].sc^1]=1;
			b[vec[r].sc]=1;
			r++;
		}
		while(l<2*n&&vec[l].fr<=p.fr-d){
			a[vec[l].sc^1]=0;
			b[vec[l].sc]=0;
			l++;
		}
		G[p.sc]=a;
		G[p.sc][p.sc^1]=0;
		rG[p.sc^1]=b;
		rG[p.sc^1][p.sc]=0;
	}
	
	vs.clear();
	al.set();
	rep(i,2*n){
		if(al[i])dfs(i);
	}
	reverse(vs.begin(),vs.end());
	al.set();
	for(int x: vs){
		c.reset();
		scc(x);
		c&=c<<1;
		c&=mask;
		if(c.any())return 0;
	}
	return 1;
}
int main(){
	rep(i,N)mask[i]=i&1;
	cin>>n;
	rep(i,n)cin>>x[i]>>y[i];
	int l=0,r=1e+9;
	while(l<r){
		int m=(l+r+1)/2;
		if(f(m))l=m;
		else r=m-1;
	}
	cout<<l<<endl;
}



Measured memory_bytes: 148956
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> s;
  char c = s[0];
  FOR(i, 0, s.length()) {
	if (c != s[i]) {
	  ans++;
	  c = s[i];
	}
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
from itertools import permutations, islice


def window(seq, n):
    it = iter(seq)
    result = tuple(islice(it, n))
    if len(result) == n:
        yield result
    for elem in it:
        result = result[1:] + (elem,)
        yield result


N, M, *ab = map(int, open(0).read().split())
g = [[0] * N for _ in range(N)]
for a, b in zip(*[iter(ab)] * 2):
    g[a - 1][b - 1] = 1
    g[b - 1][a - 1] = 1

ans = 0
for path in permutations(range(1, N)):
    path = [0] + list(path)
    if all(g[v][nv] for v, nv in window(path, 2)):
        ans += 1
print(ans)


Measured memory_bytes: 9324
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")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize
    }
    let ans = if a <= 5 {
        0
    } else if a <= 12 {
        b / 2
    } else {
        b
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

struct UnionFind{
    // 頂点数(1-indexed)
    const int V;
    // par[x]:=xのroot
    vector<int> par;
    // sz[x]:=xを含む集合のサイズ
    vector<int> sz;
    UnionFind(const int V):V(V){
        par.resize(V+1);
        for(int i=0;i<=V;i++) par[i]=i;
        sz.resize(V+1,1);
    }
    bool unite(int x,int y){
        x=root(x),y=root(y);
        if(same(x,y)) return false;
        if(y<x) swap(x,y);
        par[y]=x;
        sz[x]+=sz[y];
        return true;
    }
    int root(int x){
    	if(par[x]==x) return x; // xはroot
    	return (par[x]=root(par[x])); // xの親のroot
    }
    bool same(int x,int y){
    	return (root(x)==root(y));
    }
    int size(int x){
        return sz[root(x)];
    }
};

int main() {
	const int MAX = 100010;
	int n; cin>>n;
	UnionFind ufX(MAX),ufY(MAX);
	int x[n],y[n];
	int px[MAX],py[MAX]; rep(i,MAX) px[i]=py[i]=-1;
	rep(i,n){
		cin>>x[i]>>y[i];
		if(px[x[i]]!=-1){
			ufY.unite(y[i], y[px[x[i]]]);
		}
		if(py[y[i]]!=-1){
			ufX.unite(x[i], x[py[y[i]]]);
		}
		px[x[i]]=i;
		py[y[i]]=i;
	}
	bool usedX[MAX],usedY[MAX];
	int64_t ans=-n;
	rep(i,n){
		if(usedX[ufX.root(x[i])] || usedY[ufY.root(y[i])]) continue;
		ans+=(int64_t)(ufX.size(x[i]))*(int64_t)(ufY.size(y[i]));
		usedX[ufX.root(x[i])] = 1;
		usedY[ufY.root(y[i])] = 1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3456
N = int(input())
x = input().strip()
cnt = 0
for i in range(N):
    if x[i]=="R":
        cnt += 1
if cnt==0 or cnt==N:
    print(0)
else:
    ans = 0
    for i in range(cnt):
        if x[i]=="W":
            ans += 1
    print(ans)

Measured memory_bytes: 66120
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

char s[105];

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  cin >> s;
  int len = strlen(s);
  for (RI i = 0; i < len; i += 2)
    if (s[i] == 'h' && s[i + 1] == 'i') continue;
    else return puts("No"), 0;
  puts("Yes");

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();
    int count = 0;
    for (int i = 0; i <= a; i++) {
      for (int j = 0; j <= b; j++) {
        int sum = i * 500 + j * 100;
        if (sum > x) break;
        if ((x - sum) % 50 == 0 && (x - sum) <= 50 * c) {
          count++;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 35656
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;


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

    int n, a, b;

    cin >> n;

    cin >> a >> b;

    cout << (n + a + b >= 22 ? "bust" : "win");

    return 0;
}


Measured memory_bytes: 892
import fractions

def lcm(x,y):
    return (x*y) // fractions.gcd(x, y)
    
x, y = map(int, input().split())
s = input()
t = input()

lc = lcm(x,y)

s_l = lc//x
t_l = lc//y

for i in range(y):
    if i%s_l == 0:
        if t[i] == s[i*t_l//s_l]:
            continue
        else:
            print(-1)
            break
else:
    print(lc)



Measured memory_bytes: 5344
/* Created on 2019/8/13 10:58:55*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define max(a,b) ((a)<(b))?(a):(b)
#define min(a,b) ((a)<(b))?(a):(b)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
const int maxn = 550, inf = 0x3f3f3f3f;
int is = 0;
char p[maxn], q[maxn];
bool cmp(char a,char b) {return a < b;}
bool cmp1(char a, char b) {return a > b;}
int main() {
	ios::sync_with_stdio;
	cin.tie(0), cout.tie(0);
	gets(p), gets(q);
	sort(p, p + strlen(p), cmp);
	sort(q, q + strlen(q), cmp1);
	if (strcmp(p, q) < 0)cout << "Yes" << "\n";
	else cout << "No" << "\n";
	//cout << "Time : " << 1.0*clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var S = Console.ReadLine();

            var output = "";
            foreach (var i in Enumerable.Range(0, N))
            {
                if (i == K - 1)
                {
                    output += new string(new[] { S[i] }).ToLower()[0];
                }
                else
                {
                    output += S[i];
                }
            }

            Console.WriteLine(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 11348
x, y = map(int, input().split())
A = set([1, 3, 5, 7, 8, 10, 12])
B = set([4, 6, 9, 11])
C = set([2])

for S in [A, B, C]:
    if x in S and y in S:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

int main() {
#ifdef HIRO
  string file_path(QUIZ);
  ifstream cin(file_path + "/input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  // int n;
  // int m;
  // cin >> n;
  // cin >> m;
  string s;
  cin >> s;
  int n = s.size();
  while(n--)
    cout << "x";
  


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



Measured memory_bytes: 256
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;

    int money;

    if (a >= 13) {
        money = b;
    } else if (a >= 6) {
        money = b / 2;
    } else {
        money = 0;
    }

    std::cout << money << std::endl;
}

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

constexpr int64_t mod = 1e9 + 7;

int64_t pow_mod(int64_t n, int64_t k) {
    if(k == 1)     return n % mod;
    if(k % 2 == 0) return pow_mod(n * n % mod, k / 2) % mod;
    else           return pow_mod(n * n % mod, k / 2) * n % mod;
}

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;
    
    int64_t rmv1 = 1;
    int64_t n1 = 1, k1 = 1;
    for(int i = 0; i < a; i++) {
        n1 *= n - i;
        n1 %= mod;
        k1 *= i + 1;
        k1 %= mod;
    }
    rmv1 = n1 * pow_mod(k1, mod - 2) % mod;
    
    int64_t rmv2 = 1;
    int64_t n2 = 1, k2 = 1;
    for(int i = 0; i < b; i++) {
        n2 *= n - i;
        n2 %= mod;
        k2 *= i + 1;
        k2 %= mod;
    }
    rmv2 = n2 * pow_mod(k2, mod - 2) % mod;

    int64_t total = pow_mod(2, n) - 1;
    int64_t rmv = (rmv1 + rmv2) % mod;

    // cout << rmv1 << endl;
    // cout << rmv2 << endl;

    cout << (total + mod - rmv) % mod << endl;

    return 0;
}

Measured memory_bytes: 256
r, c=(int(x) for x in input().split())
graph=[[int(x) for x in input().split()] for i in range(r)]
for i in range(r):
    sum=0
    for j in range(c):
        sum+=graph[i][j]
    graph[i].append(sum)
new=[]
for i in range(c+1):
    sum=0
    for j in range(r):
        sum+=graph[j][i]
    new.append(sum)
graph.append(new)
for i in range(r+1):
    for j in range(c+1):
        if j!=c:
            print(graph[i][j], end=" ")
        else:
            print(graph[i][j])


Measured memory_bytes: 6256
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
  #define MOD 1000000007
   
   long long int power(long long int x,long long int n){
       long long int res = 1;
       while(n!=0){
           if(n%2 == 1){
               res =( (res % MOD) * (x % MOD) )% MOD;
               n--;
           }else if(n%2 == 0){
               x = ((x % MOD) * (x % MOD)) % MOD;
               n = n/2;
           }
       }
          return res;
   }
int main(){
    
    long long int n,i,j;
    
    cin >> n;
    
    if(n<=1) cout << 0 << endl;
    else{
        cout << (((((((power(10,n) - power(9,n))% MOD + MOD) % MOD) - power(9,n)) % MOD + MOD)%MOD) + (power(8,n) % MOD))%MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import itertools

N=int(input())
list_P=list(map( int, input().split() ))
list_Q=list(map( int, input().split() ))

#-----
list_all=list(itertools.permutations(range(1,N+1)))


def check_order(list_X,list_all):
  check=""
  less_num=0
  
  for L_all in list_all:
    for i in range(N):
      if list_X[i] > L_all[i] :
        check="true"
        break
      elif list_X[i] < L_all[i]:
        break
    
    if check=="true":
      less_num += 1
      check=""
  return less_num + 1
  

a=check_order(list_P, list_all)
b=check_order(list_Q, list_all)

print(abs(a-b))


Measured memory_bytes: 8052
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

char letter();
string str();
string chipher();

string S;
int p;

char letter() {
  char ret;
  if(S[p] == '+') {
    p++;
    ret = letter();
    if('A' <= ret && ret <= 'Z') ret = ((ret - 'A') + 1) % 26 + 'A';
  } else if(S[p] == '-') {
    p++;
    ret = letter();
    if('A' <= ret && ret <= 'Z') ret = ((ret - 'A') + 25) % 26 + 'A';
  } else {
    ret = S[p++];
  }
  return ret;
}

string str() {
  string ret = "";
  if(S[p] == '[') {
    p++;
    ret = chipher();
    reverse(ret.begin(), ret.end());
    p++;
  } else {
    ret += letter();
  }
  return ret;
}

string chipher() {
  string ret = "";
  while(p < S.length() && S[p] != ']') ret += str();
  return ret;
}

int main(void) {
  while(cin >> S, S != ".") {
    p = 0;
    string ans = chipher();
    REP(i, 0, S.length()) if(ans[i] == '?') ans[i] = 'A';
    cout << ans << endl;
  }
}

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

int main(){
	int n;
	int h[100];
	int i, j;
	int max;
	int count = 0;

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

	max = h[0];
	for (i = 0; i < n; i++){
		if (max <= h[i]){
			count++;
			max = h[i];
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())

p=list(map(int,input().split()))
score=list(map(int,input().split()))

group_score=[]
checked=[0]*n

for i in range(n):
    if checked[i]==0:
        tmp_group=[]
        tmp=i
        while checked[tmp]==0:
            checked[tmp]=1
            tmp_group.append(score[tmp])
            tmp=p[tmp]-1
        group_score.append(tmp_group)



#aryの中から連続するk個選択するときの最大
def calc(k):
    if k==0:
        return 0
    global group
    ans="INF"
    for i in range(len(group)):
        tmp=0
        for j in range(k):
            tmp+=group[(i+j)%len(group)]
            if ans=="INF":
                ans=tmp
            else:
                if ans<tmp:
                    ans=tmp
    return ans

ans=score[0]
for group in group_score:
    #一周以上する場合
    if len(group)<k:
        cycle=sum(group)
        if cycle>0:
            cycle_sum=cycle*(k//len(group))
            tmp=calc(k%len(group))
            ans=max(ans,cycle_sum+tmp)

            if k//len(group)>=2:
                cycle_sum=cycle*(k//len(group)-1)
                tmp=calc(len(group))
                ans=max(ans,cycle_sum+tmp)
          

        tmp=calc(len(group))
        ans=max(ans,tmp)



    #一周しない場合k)
    else:
        tmp=calc(k)
        ans=max(ans,tmp)

print(ans)

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

public class Main {

	void solve() {
		int r = in.nextInt(), c = in.nextInt();
		int[] cnt = new int[26];
		for (int i = 0; i < r; i++) {
			for (char ch : in.nextToken().toCharArray()){ 
				cnt[ch - 'a']++;
			}
		}
		
		int cnt4 = (r / 2) * (c / 2);
		int cnt2 = (r / 2) * (c % 2) + (c / 2) * (r % 2);
		int cnt1 = (r % 2) * (c % 2);
		
		for (int i = 0; i < 26; i++) {
			while (cnt[i] >= 4 && cnt4 > 0) {
				cnt[i] -= 4;
				cnt4--;
			}
		}
		for (int i = 0; i < 26; i++) {
			while (cnt[i] >= 2 && cnt2 > 0) {
				cnt[i] -= 2;
				cnt2--;
			}
		}
		for (int i = 0; i < 26; i++) {
			while (cnt[i] >= 1 && cnt1 > 0) {
				cnt[i] -= 1;
				cnt1--;
			}
		}
		out.println((cnt1 == 0 && cnt2 == 0 && cnt4 == 0) ? "Yes" : "No");
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

struct UnionFind
{
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}

  int root(int x)
  {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  bool isSame(int x, int y)
  {
    return root(x) == root(y);
  }

  bool merge(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x)
  {
    return -par[root(x)];
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  Graph G(N);
  vector<int> Z(M);
  vector<bool> checked(N, false);
  for (int i = 0; i < M; i++)
  {
    int x, y;
    cin >> x >> y >> Z[i];
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
    if (uf.isSame(x, y))
      continue;
    uf.merge(x, y);
  }
  set<int> cnt;
  for (int i = 0; i < N; i++)
  {
    cnt.insert(uf.root(i));
  }
  cout << cnt.size() << endl;
  return 0;
}


Measured memory_bytes: 9088
function main(input) {
    const ALL = input.split('\n');
    const A = parseInt(ALL[0], 10),
          B = parseInt(ALL[1], 10),
          C = parseInt(ALL[2], 10),
          X = parseInt(ALL[3], 10);

    var count = 0;

    for(var a=0;a<=A;++a){
        for(var b=0;b<=B;++b){
            for(var c=0;c<=C;++c){
                var sum = (a*500)+(b*100)+(c*50);
                if(sum===X)++count;
            }
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int N,K;
  cin>>N>>K;
  if (N%K==0) cout << "0" << endl;
  else cout << "1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1e9 + 7;

int ans = 1e18;
int n;
VI l;
void dfs(VI& a, VI& used, int acc) {
  if (a.size() == 0) {
    ans = min(ans, acc); return;
  }
  VI aa = a;
  aa.erase(aa.begin());
  REP (bit, 1LL << n) {
    VI next = used;
    int tmp = 0;
    int cnt = 0;
    REP (i, n) {
      if (bit >> i & 1 && !next[i]) {
        next[i] = true;
        tmp += l[i];
        cnt++;
      }
    }
    if (tmp == 0) continue;
    dfs(aa, next, acc + abs(a[0] - tmp) + 10 * (cnt - 1));
  }
}
signed main() {
  cin >> n;
  VI a(3); REP (i, 3) cin >> a[i];
  l = VI(n); REP (i, n) cin >> l[i];
  VI used(n);
  dfs(a, used, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort(reverse=True)

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]
  ans_list+=lc[:(x+y)]

  ans_list.sort(reverse=True)


  # print(ans_list)
  return sum(ans_list[:x+y])

# main()
print(main())


Measured memory_bytes: 123240
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b)){
        cout<<"A"<<endl;
    }else{
         cout<<"B"<<endl;
    }
    return 0;
}


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

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

  string T = "ATCG";

  int ans = 0;
  for(int i = 0;i < S.size();i++){
    //iは開始地点
    int now = 0;
    for(int j = i;j < S.size();j++){
      //j文字目まではATCGであるかチェック
      bool ok = false;
      for(int k = 0;k < T.size();k++){
        if(S[j] == T[k])ok = true;
      }

      if(ok){
        //j文字目がATCGなら続く可能性があるのでnow++.
        now++;
        ans = max(ans,now);
      }
      else break;//j文字目がATCGでないのでiを移動させる.

    }

  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll h, w;
ll a, b, c;
ll mn = 4e18;

ll abs2(ll p){return p > 0 ? p : -p;}

int main()
{
    scanf("%lld%lld", &h, &w);
    for(ll i = 0; i <= h; i++)
    {
        a = w * i;
        b = (h - i) * (w / 2);
        c = w * h - a - b;
        mn = min(mn, max(abs2(a - b), max(abs2(b - c), abs2(c - a))));
    }
    if(h % 3 == 0) mn = 0;
    else mn = min(mn, w);
    swap(h, w);
    for(ll i = 0; i <= h; i++)
    {
        a = w * i;
        b = (h - i) * (w / 2);
        c = w * h - a - b;
        mn = min(mn, max(abs2(a - b), max(abs2(b - c), abs2(c - a))));
    }
    if(h % 3 == 0) mn = 0;
    else mn = min(mn, w);
    printf("%lld", mn);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 101

int main(){
  int A[N][N] = {0};
  int num, inum, jnum, count, i, j;

  scanf("%d", &num);
  //printf("num = %d\n",num);
  for(i = 1; i <= num; i++){

    //printf("i = %d\n",i);
      
    scanf("%d %d", &inum, &count);
    
    for(j = 1; j <= count; j++){
      //printf("j = %d\n",j);
      
      scanf("%d", &jnum);

      A[inum][jnum] = 1;
    }
  }
  
  for(i = 1; i <= num; i++){
    for(j = 1; j < num; j++){
      printf("%d ", A[i][j]);
    }
    printf("%d\n",A[i][j]);
  }
    
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int n,i,j,a[200005],s1,s2;
set<int> s;
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",a+i);
	sort(a+1,a+n+1);
	s.clear();
	for (i=1;i<=n;i++){
		if (i==n){
			set<int>::iterator it=s.upper_bound(a[i]/2);
			int x=-10,y=-10;
			if (it!=s.end()){
				x=*it;
			}
			if (it!=s.begin()){
				it--;
				y=*it;
			}
			if (abs(x-a[i]/2.0)>abs(y-a[i]/2.0)) swap(x,y);
			s1=a[i];
			s2=x;
		}
		s.insert(a[i]);
		//for (set<int>::iterator it=s.begin();it!=s.end();it++) cout<<*it<<' ';cout<<endl;
	}
	printf("%d %d\n",s1,s2);
	return 0;
}

Measured memory_bytes: 5376
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

long long M = 1000000007;

int n;
vector<long long> dp;
vector<vector<bool>> a;

long long solve(int i, int b){
    if(dp[b] != -1)return dp[b];
    if(i == n)return 1;
    long long res = 0;
    for(int k=0;k<n;++k){
        if(((b | (1<<(k))) != b) && a[i][k]){
            res += solve(i+1,(b | (1<<(k))));
            res %= M;
        }
    }
    dp[b] = res;
    return res;
}

int main(int argc, char const *argv[]) {
    cin>>n;
    a = vector<vector<bool>>(n,vector<bool>(n));
    dp = vector<long long>(1<<(n),-1);
    for(int i=0;i<n;++i){
        for(int k=0;k<n;++k){
            bool tmp;
            cin>>tmp;
            a[i][k] = tmp;
        }
    }
    cout<<solve(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define DS       pair<LL, LL>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

LL bigMod(LL b, LL p, LL m) {
    LL ret = 1, cur = b % m;
    while (p) {
        if (p & 1) ret = (ret * cur) % m;
        cur = (cur * cur) % m;
        p = p >> 1;
    }
    return ret;
}

LL calcNcr(LL n, LL r) {
    LL up = 1, down = 1;
    for (LL i = 1; i <= r; i++) {
        down *= i; down %= MOD;
        up *= (n - i + 1); up %= MOD;
    }
    return (up * bigMod(down, MOD - 2, MOD)) % MOD;
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    LL n, a, b;
    cin >> n >> a >> b;
    LL tot = bigMod(2, n, MOD);
    a = calcNcr(n, a);
    b = calcNcr(n, b);
    tot -= a;
    tot += MOD; tot %= MOD;
    tot -= b;
    tot += MOD; tot %= MOD;
    tot -= 1;
    tot += MOD; tot %= MOD;
    cout << tot << '\n';
    return 0;
}


Measured memory_bytes: 256