akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 1000000007;

static const ll INF = 1e15;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
	vector<ll> fac;
	vector<ll> ifac;
public:

	Factorial(ll N) {
		fac.push_back(1);
		for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
		ifac.resize(N + 1);
		ifac[N] = inv_mod(fac[N]);
		for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
	}

	ll fact(ll a) { return fac[a]; }
	ll ifact(ll a) { return ifac[a]; }

	ll cmb(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		ll tmp = ifact(a - b) * ifact(b) % mod;
		return tmp * fac[a] % mod;
	}
	ll per(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		return fac[a] * ifac[a - b] % mod;
	}
};


int main(void)
{
	ll n,k;
	cin >> n >> k;
	Factorial f(n);
	ll sum = 0;
	rep(i, min(k,n)+1) {
		ll nci = f.cmb(n, i) % mod;
		ll take = f.cmb(n - 1, n - i - 1) % mod;
		sum += nci * take;
		sum %= mod;
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3440
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    char A;
    cin>>A;
    cout<<(('a'<=A && A<='z')?('a'):('A'))<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3788
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP Vacation
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
#define mx 100005
using namespace std;
int n, memo[mx][3];
int a[mx][3];

int dp(int day, int prevActivity)
{
    if (day >= n)
        return 0;
    if (memo[day][prevActivity])
        return memo[day][prevActivity];
    int res = 0;
    for (int i = 0; i < 3; i++)
        if (i != prevActivity)
            res = max(res, a[day][i] + dp(day + 1, i));
    return memo[day][prevActivity] = res;
}

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            cin >> a[i][j];
    cout << dp(0, -1) << endl;
}


Measured memory_bytes: 13716
function Main(input) {

  var input = input.split("\n");
  var input = input[0].split(" ").map(val => parseInt(val, 10)).slice(0, 2);
  var n = input[0];
  var l = input[1];
  var count = 0;
  var diff = new Array();
  var index = 0;

  var apples = new Array();
  for(var i=1; i<=n;i++){
    var azi = l + i - 1;
    apples.push(azi);
    count = count + azi;
  }
  apples.forEach(function(val, g) {
    diff[g] = Math.abs(0 - val);
    index = (diff[index] < diff[g]) ? index : g;
  });

  var val = apples[index];
  console.log(count - val);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	string s, t;
	cin >> s >> t;
	int st[26], tt[26];
	REP(i, 26){
		st[i] = -1;
		tt[i] = -1;
	}
	tmp = 0;
	REP(i, s.size()){
		if(st[s[i] - 'a'] == -1){
			st[s[i] - 'a'] = tmp;
			tmp++;
		}
		s[i] = st[s[i] - 'a'] + 'a';
	}
	tmp = 0;
	REP(i, t.size()){
		if(tt[t[i] - 'a'] == -1){
			tt[t[i] - 'a'] = tmp;
			tmp++;
		}
		t[i] = tt[t[i] - 'a'] + 'a';
	}
	if (s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	//cout << ans << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
#define MAXN 100005
ll dp[MAXN][3];
void solve(vector< vector<ll> > &a, int n)
{
    forn(i,MAXN)
    {
        forn(j,3)
        {
            dp[i][j]=(pow(10,9)+5)*(ll)(-1);
        }
    }
    dp[0][0]=a[0][0], dp[0][1]=a[0][1], dp[0][2]=a[0][2];
    forr(i,1,n)
    {
        forn(j,3)
        {
            forn(k,3)
            {
                if(j==k)
                {
                    continue;
                }
                else dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }
 
    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << "\n";
}
 
int main() {
    FIN;
    int n;
    cin >> n;
    vector< vector<ll> > arreglo(n);
    forn(i,n) arreglo[i].resize(3);
    forn(i,n)
    {
        forn(j,3) cin >> arreglo[i][j];
    }
    solve(arreglo, n);
    return 0;
}

Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint a(n);
    ll sum = 0;
    int cnt = 0;
    int mn = INF;
    rep(i, n) {
        cin >> a[i];
        if (a[i] < 0) {
            a[i] *= -1;
            cnt++;
        }
        mn = min(mn, a[i]);
        sum += a[i];
    }

    ll ans = sum;
    if (cnt % 2 == 1) ans -= mn*2;

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

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


int main(){
    int a,cou=0,n,num=1;
    vector<int> vec;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        vec.push_back(a);
    }
    for(int j=0;j<2*n;j++){
        num=vec[num-1];
        cou++;
        if(num==2){
            cout<<cou<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll answer = 0;
	if(k % 2 == 0){
		answer = a - b;
	}else{
		answer = b - a;
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256
<?php
/**
 * ABC119
 * B - Digital Gifts
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%f %s", $x[$i], $u[$i]);
    if ($u[$i] === 'BTC') {
        $x[$i] *= 380000;
    }
}

echo array_sum($x), PHP_EOL;


Measured memory_bytes: 4728
def divisor(num)
    result = []
    i = 1
    while i <= num**(0.5) do
      remainder = num % i
      if remainder == 0
        result << i
      end 
      i += 1
    end
    return result
end

num = gets.to_i
divisions = divisor(num)

distance_lists = []

for d in divisions do
  width_count = (d - 1)
  vertical_count = (num / d - 1)
  distance_lists << width_count + vertical_count
end

ans = distance_lists.min 
puts(ans)

Measured memory_bytes: 14556
n=int(input())
A=list(map(int,input().split()))
right=0
s=0
ans=0
for left in range(n):
    while right<=n-1 and (s+A[right])==(s^A[right]):
        s+=A[right]
        right+=1
    ans+=right-left
    if left==right:
        right+=1
    else:
        s-=A[left]
print(ans)

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

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=109;

int n,g[2][N],f[2][N];

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	n=read();
	for(int i=1;i<=n;i++)
		g[0][i]=read();
	for(int i=1;i<=n;i++)
		g[1][i]=read();
	f[0][1]=g[0][1];
	for(int i=2;i<=n;i++)
		f[0][i]=f[0][i-1]+g[0][i];
	f[1][1]=f[0][1]+g[1][1];
	for(int i=2;i<=n;i++)
		f[1][i]=max(f[0][i],f[1][i-1])+g[1][i];
	printf("%d\n",f[1][n]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <iostream> 
// #include <sstream> 
// #define int unsigned long long int
using namespace std;
 
 
 
// // bool prime[1000001]; 
 
// // void SieveOfEratosthenes(int n) 
// // { 
// //     // Create a boolean array "prime[0..n]" and initialize 
// //     // all entries it as true. A value in prime[i] will 
// //     // finally be false if i is Not a prime, else true. 
    
// //     memset(prime, true, sizeof(prime)); 
  
// //     for (int p=2; p*p<=n; p++) 
// //     { 
// //         // If prime[p] is not changed, then it is a prime 
// //         if (prime[p] == true) 
// //         { 
// //             // Update all multiples of p greater than or  
// //             // equal to the square of it 
// //             // numbers which are multiple of p and are 
// //             // less than p^2 are already been marked.  
// //             for (int i=p*p; i<=n; i += p) 
// //                 prime[i] = false; 
// //         } 
// //     } 
  
// // }

long long int mod = 1000000007;

unordered_map<int,std::vector<int>> grp;

void f(vector<pair<int,int>>& dp, int src, int par){
	bool ch = false;
	long long int w = 1;
	long long int b = 1;

	for(auto dest: grp[src]){
		if(dest==par)continue;
		ch = true;
		f(dp,dest,src);
		long long int cw = dp[dest].first;
		long long int cb = dp[dest].second;
		b = (b* cw%mod)%mod;
		w = (w* (cw+cb)%mod)%mod;
	}

	dp[src].first = w%mod;
	dp[src].second = b%mod;
	return;
}

int main()
{
	 long long int t;

	 long long int mod = 1000000007;
	 t=1;
	for( long long int ts=1; ts<=t; ts++){
		long long int n;
		cin>>n;
		std::vector<pair<int,int>> dp(n);
		for(int i=0;i<n-1;i++){
			int x,y;
			cin>>x>>y;
			x--;
			y--;
			grp[x].push_back(y);
			grp[y].push_back(x);
		}

		f(dp, 0, -1);
		cout<<((dp[0].first + dp[0].second)%mod)<<endl;
	}
	return 0;
}
 
 
 
 

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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

string s, f;
map<char, int> q;

int main(){

cin >> s;

ll n = s.size();
ll ans = n * (n - 1) / 2 + 1;

for(int i = 0; i < n; i++){
    q[s[i]]++;
}

for(auto i : q){
    if(i.second >= 2){
        ll k = i.second;
        ans -= k * (k - 1) / 2;
    }
}

cout << ans << '\n';


return 0;

}


Measured memory_bytes: 640
// https://atcoder.jp/contests/abc049/tasks/arc065_a

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int pos = 0, find = 0;
    string s, w[] = {"dream", "dreamer", "erase", "eraser"};
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;

    // 逆順にしてから探す
    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; i++) {
        reverse(w[i].begin(), w[i].end());
    }

    while (pos < s.length()) {
        find = 0;
        for (int i = 0; i < 4; i++) {
            if (s.substr(pos, w[i].length()) == w[i]) {
                pos += w[i].length();
                find = 1;
                break;
            }
        }
        if (find == 0) {
            break;
        }
    }

    if (pos == s.length()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static ArrayList<Integer[]> list=new ArrayList<>();
static ArrayList<Integer[]> set=new ArrayList<>();


	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

   String nyuA=sc.nextLine();
   String nyuB=sc.nextLine();
 
    String[] s=sc.nextLine().split(" ");
//     String[] e=sc.nextLine().split(" ");

//int N=Integer.parseInt(nyuA);

int N=Integer.parseInt(nyuA);
int K=Integer.parseInt(nyuB);


int[] num=new int[s.length];
for(int i=0;i<s.length;i++){
num[i]=Integer.parseInt(s[i]);
//System.out.println(num[i]+"-2");
}
int res=0;
for(int i=0;i<N;i++){
int tem=Math.min(K-num[i],num[i])*2;
//System.out.println(K-num[i]+"---"+num[i]+"-3");

res+=tem;
}

System.out.println(res);



	}

}

Measured memory_bytes: 23764
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    int n = readln().chomp().to!int;
    real ans;
    ans = 0;
    for(int i=0;i<n;i++){
	ans += readln().chomp().to!real / to!real(n);
    }
    writeln(to!int(ans));

}

Measured memory_bytes: 2448
#include <iostream>
using namespace std;
int main(){
 int n;
 cin>>n;
 for(int i=1;i<=n;i++){

    if(i%3==0){
       cout<<" "<<i;
     }
   else {
	   int x=i;
	   while(x>0){
		   if(x%10==3){
			   cout<<" "<<i;
			   break;
		   }
		   x/=10;
	   }
   }

 }
cout<<endl;
return 0;
}

Measured memory_bytes: 1160
#include <map>
#include <list>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,m,x,xx,a[105],ans1,ans2;
int main()
{
	fast; 
	cin>>n>>m>>x;
	for (int i=1;i<=m;i++)
	{
		cin>>xx;
		a[xx]=1;
	}
	
	for (int i=x;i>=0;i--)
	   ans1+=a[i];
	for (int i=x;i<=n;i++)
	   ans2+=a[i];
	cout<<min(ans1,ans2);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>

#define MOD 1000000007
#define REP(i,n) for ((i)=0;i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define LL long long
#define ULL unsigned long long

int compare_ll(const void *a, const void *b){
	return *(ULL*)b - *(ULL*)a;
}



int main(void) {
	int N,K,i;
	ULL ans;
	scanf("%d %d", &N, &K);

	ans = K;
	K--;
	for(i=1;i<N;i++){
		ans *= K;
	}
	printf("%lld", ans);


	return 0;
}

/* 最後の改行忘れるな！！ */


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
  
  int r;
 
scanf("%d",&r);
  if(r<1200){
    printf("ABC\n");
  }
  else  if(r<2800){
      printf("ARC\n");
  }
else {
  printf("AGC\n");
}
 
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 305
#define mod 1000000007
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,a[maxn*2];
int f[maxn*2][maxn][maxn],cnt1,cnt2;
int book[maxn*2],vis[maxn*2];
int b[maxn*2],m;
void add(int &x,int y)
{
    x+=y;
    if(x>=mod)  x-=mod;
}
int main()
{
    n=read();
    for(int i=1;i<=2*n;i++)   a[i]=read();
    for(int i=1;i<=2*n;i+=2)
    {
        if(a[i]==-1&&a[i+1]==-1)  cnt1++;
        else if(a[i]==-1||a[i+1]==-1){
            cnt2++;
            if(a[i]==-1)  book[a[i+1]]=1;
            else          book[a[i]]=1; 
        }
        else  vis[a[i]]=vis[a[i+1]]=1;
    }
    for(int i=2*n;i>=1;i--)
      if(!vis[i])  b[++m]=i;
    f[0][0][0]=1;
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<=min(i,cnt1+cnt2);j++)
        {
            for(int k=0;k<=min(i,cnt2);k++)
            {
                if(!f[i-1][j][k])  continue;
                if(book[b[i]])
                {
                    add(f[i][j][k+1],f[i-1][j][k]);
                    if(j)  add(f[i][j-1][k],f[i-1][j][k]);
                }
                else{
                    add(f[i][j+1][k],f[i-1][j][k]);
                    if(j)  add(f[i][j-1][k],f[i-1][j][k]);
                    if(k)  add(f[i][j][k-1],1ll*f[i-1][j][k]*k%mod);
                }
            }
        }
    }
    int ans=f[m][0][0];
    for(int i=1;i<=cnt1;i++)  ans=1ll*ans*i%mod;
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long

using namespace std;

ll a[1000009];
ll vis[1000009];
map<ll,ll>mp;
vector<ll>v;
int main()
{
    ll n,k,q,ok=0;
    cin>>n>>k>>q;
    ll cur=k-q;

    if(cur<=0)cur=fabs(k-q);

    else  ok=1;
    for(int i=1; i<=q; i++) {
        cin>>a[i];

        mp[a[i]]++;

        if(mp[a[i]]>cur&&vis[a[i]]==0){v.push_back(a[i]);vis[a[i]]=1;}
    }
    if(ok==1){
        for(int i=1;i<=n;i++)cout<<"Yes"<<endl;
    }
    else{

        ll ln=v.size();
        if(ln==0){
            for(int i=1;i<=n;i++)cout<<"No"<<endl;
        }
        else{
        sort(v.begin(),v.end());

        for(int i=1,j=0;i<=n;i++){
            if(i==v[j]){cout<<"Yes"<<endl;j++;}
            else cout<<"No"<<endl;
        }
        }
    }
}


Measured memory_bytes: 8704
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
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)*}
    };
}
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        S: String
    }
    println!("{}", S.replace(",", " "));
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>

typedef struct treeNode{
  int key;
  struct treeNode *right;
  struct treeNode *left;
  struct treeNode *parent;
}Node;

void printPreorder(Node *);
void printInorder(Node *);
void insert(Node *);

Node *T = NULL;


int main(){
  int i,in,root,k;
  Node *temp;
  char s[10];

  scanf("%d", &in);


  for(i=0 ; i<in ; i++){
    scanf("%s", s);

    if(s[0]=='i'){
      temp =malloc(sizeof(Node));
      scanf("%d",&(temp->key));
      temp->left = NULL;
      temp->right = NULL;
      insert(temp);
    }
    else{
      printInorder(T);
      printf("\n");
      printPreorder(T);
      printf("\n");
    }
  }

  return 0;

}

void printPreorder(Node *N){
  printf(" %d",N->key);

  if(N->left != NULL){
    printPreorder(N->left);
  }

  if(N->right != NULL){
    printPreorder(N->right);
  }

}


void printInorder(Node *N){

  if(N->left != NULL){
    printInorder(N->left);
  }

  printf(" %d",N->key);


  if(N->right != NULL){
    printInorder(N->right);
  }

}

void insert(Node *n){
  Node *x,*y;

  y = NULL;
  x = T;

  while(x != NULL){
    y = x;
    if(n->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  n->parent = y;

  if(y == NULL){
    T = n;
  }
  else if(n->key < y->key){
    y->left = n;
  }
  else{
    y->right = n;
  }

}

Measured memory_bytes: 24040
//ex7_3
//TKC001

#include<stdio.h>
#include<stdlib.h>

int main(void){
    //row_memo[i] = 1のときptr[i][]を消さない。col_memo[j] = 1のときptr[][j]を消さない
    int height, width, i, j, *row_memo, *col_memo;
    char **ptr;
    scanf("%d %d", &height, &width);

    //row_memoの動的確保
    row_memo = (int*)calloc(height, sizeof(int));
    if(row_memo == NULL){
        exit(1);
    }
    //col_memoの動的確保
    col_memo = (int*)calloc(width, sizeof(int));
    if(col_memo == NULL){
        exit(1);
    }
    //配列の先頭をheight個確保
    ptr = (char**)calloc(height, sizeof(char*));
    if(ptr == NULL){
        exit(1);
    }

    //大きさwidthの配列をheight個確保
    for(i = 0; i < height; i++){
        ptr[i] = (char*)calloc(width+1, sizeof(char));
        if(ptr[i] == NULL){
            exit(1);
        }
    }

    //入力
    for(i = 0; i < height; i++){
        scanf("%s", ptr[i]);
    }

    //黒があった行と列でrow_memoとcol_memoを1にする。
    for(i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            if(ptr[i][j] == '#'){
                row_memo[i] = 1;
                col_memo[j] = 1;
            }
        }   
    }

    //row_memoとcol_memoが0である行と列は省いて出力
    for(i = 0; i < height; i++){
        if (row_memo[i] == 0){
            continue;
        }
        for(j = 0; j < width; j++){
            if(col_memo[j] == 0){
                continue;
            }
            printf("%c", ptr[i][j]);
        }
        printf("\n");
    }
    
    free(row_memo);
    free(col_memo);
    for ( i = 0; i < height; i++)
    {
        free(ptr[i]);
    }

    free(ptr);
    
    return 0;
}

Measured memory_bytes: 1628
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;

void adder(string&ans,int freq,char x){
    string temp(freq,x);
    ans = ans + temp;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int verti = abs(sy-ty);
    int hori = abs(sx-tx);
    string ans = "";
    adder(ans,verti,'U');
    adder(ans,hori,'R');
    adder(ans,verti,'D');
    adder(ans,hori,'L');
    adder(ans,1,'L');
    adder(ans,verti+1,'U');
    adder(ans,hori+1,'R');
    adder(ans,1,'D');
    adder(ans,1,'R');
    adder(ans,verti+1,'D');
    adder(ans,hori+1,'L');
    adder(ans,1,'U');
    cout<<ans<<endl;








    }




















Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<int,int>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 














//int ct[100005][2];
const int N=100005;
int n;
int a[N],b[N],c[N];
int dp[N][3];
int main()
{
     cin>>n;
     for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
     for(int i=0;i<n;i++)
     {
          dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i];
          dp[i+1][1]=max(dp[i][0],dp[i][2])+b[i];
          dp[i+1][2]=max(dp[i][1],dp[i][0])+c[i];
     }
     cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}
























 

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

ll Fact(int n)//n階乗を求める関数 オーバーフローするのでnが小さい値しか使えないよ
{
  if(n==0) return 1;
  return n * Fact(n-1);
}

double get_distance(int x1, int y1, int x2, int y2)//2点間の距離を求める関数
{
  double distance;
  distance = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
  return sqrt(distance);
}

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  for(int i = 0; i<N; i++) 
  {
    cin >> x.at(i);
    cin >> y.at(i);
  }
  
  double ans = 0;
  for(ll i=0; i<N; i++)//各町間の道路の長さを2回ずつ足す
  {
    for(ll j=0; j<N; j++){
      if(i==j) continue;
      ans += get_distance(x.at(i), y.at(i), x.at(j), y.at(j));
    }    
  }
  //ll n_fact = Fact(N);
  //cout << "Fact("<<N<<") : "<< n_fact << endl;
  ans = ans / N;
  cout << fixed;//小数点を確実に8桁で表示するためのもの
  cout << setprecision(8) <<ans << endl; 
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

    int a,b,c,d;

    cin >> a >> b >> c >> d;

    if(a + b > c + d){
        cout << "Left" << endl;
    }else if(a + b == c + d){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll tmp=0;
    while(tmp*10+9<=n)  tmp=tmp*10+9;
    ll t=tmp;
    for(int i=0;i<10;++i)
    {
        if(t+(tmp+1)<=n)    t=t+tmp+1;
        else break;
    }
    int ans=0;
    while(t)
    {
        ans+=(t%10);
        t/=10ll;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  long long int a;
  long long int b;
 
  while(cin >> a >> b){
    int ans;
    bool p[1001001];
    int num[1001001];

    for(int i=0;i<=2*b;i++){
      if(a-b+i<2)num[i] = 0;
      else num[i] = 1<<30;
    }

    int N = (int)sqrt(a+b) + 1;
    for(int i=2;i<=N;i++)p[i] = true;
    p[0] = false;
    p[1] = false;
    
    int c = 2;
    while(c<=N){
      for(int i=2*c;i<=N;i+=c)p[i] = false;

      int s = (c - (a-b)%c)%c;
      for(int j=s;j<=2*b;j+=c){
	long long int tmp = a-b+j;
	if(num[j]){

	  int cnt = 0;
	  while(!(tmp%c)){
	    tmp /= c;
	    cnt++;
	  }

	  if(cnt){
	    if(num[j] < cnt)num[j] = 0;
	    else num[j] = cnt;
	  }
	}
      }

      while(!p[++c]);
    }

    ans = 0;
    for(int i=0;i<=2*b;i++){
      if(num[i])ans++;
    }

    printf("%d\n",ans);
  }
}

Measured memory_bytes: 5712
pub struct Scanner {
	handle: std::io::Stdin,
	buffer: std::collections::VecDeque<String>
}

impl Scanner {
	pub fn new() -> Scanner {
		Scanner {
			handle: std::io::stdin(),
			buffer: std::collections::VecDeque::new()
		}
	}
	pub fn next<T: std::str::FromStr>(&mut self) -> Result<T, T::Err> {
		if self.buffer.len() == 0 {
			loop {
				let mut available = String::new();
				self.handle.read_line(&mut available).unwrap();
				self.buffer = available.split_whitespace().map(String::from).collect();
				if self.buffer.len() > 0 {
					break;
				}
			}
		}
		T::from_str(&self.buffer.pop_front().unwrap())
	}
}

fn main() {
	let mut scanner = Scanner::new();
	let n: i32 = scanner.next().unwrap();
	let m: i32 = scanner.next().unwrap();
	let mut p = vec![0; n as usize];
	let mut connected = vec![std::collections::HashSet::<i32>::new(); n as usize];
	for _ in 0..m {
		let a: i32 = scanner.next().unwrap();
		let b: i32 = scanner.next().unwrap();
		connected[a as usize -1].insert(b);
		connected[b as usize -1].insert(a);
	}
	// rank[0] = 0;
	// // println!("{:?} {:?}", rank, connected);
	// for _ in 0..n {
	// 	let mut next_rank = rank.clone();
	// 	for j in 0..n {
	// 		let mut min = n;
	// 		let c = &mut connected[j as usize];
	// 		for room in c.iter() {
	// 			min = std::cmp::min(min, rank[*room as usize - 1]);
	// 		}
	// 		next_rank[j as usize] = std::cmp::min(min + 1, next_rank[j as usize]);
	// 		if next_rank[j as usize] < n {
	// 			c.retain(|room| next_rank[j as usize] == rank[*room as usize - 1] + 1);
	// 		}
	// 	}
	// 	rank = next_rank;
	// 	// println!("{:?} {:?}", rank, connected);
	// }
	let mut q = std::collections::VecDeque::<i32>::new();
	q.push_back(1);
	while !q.is_empty() {
		let room = q.pop_front().unwrap();
		// println!("{:?}", p);
		for neighbor in connected[room as usize - 1].iter() {
			if p[*neighbor as usize - 1] == 0 {
				p[*neighbor as usize - 1] = room;
				q.push_back(*neighbor);
				// println!("{:?}", q);
			}
		}
	}
	for r in q.iter() {
		if *r == 0 {
			println!("No");
			return;
		}
	}
	println!("Yes");
	for i in 1..n as usize {
		println!("{}", p[i]);
	}
}


Measured memory_bytes: 15200
#include<iostream>
#define N 8
#define NA 1
#define NIL 0
using namespace std;
void printBoard(void);
void putQueen(int);
int M[N][N],row[N],col[N],dneg[2*N-1],dpos[2*N-1];
int main(){
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      M[i][j] = 0;
    }
    col[i] = row[i] = dneg[i] = dpos[i] = NIL;
  }
  for(int i=N; i<(N*2-1); i++){
    dneg[i] = dpos[i] = NIL;
  }
  int k;
  cin >> k;
  for(int i=0,r,c; i<k; i++){
    cin >> r >> c;
    M[r][c] = 1;
  }
  putQueen(0);
  return 0;
}
void printBoard(void){
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(M[i][j] && row[i] != j) return;
    }
  }
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cout << (row[i] == j ? "Q" : ".");
    }
    cout << endl;
  }
}
void putQueen(int i){
  if(i == N){
    printBoard();
    return;
  }
  for(int j=0; j<N; j++){
    if(col[j] == NA || dpos[i+j] == NA || dneg[i-j+N-1] == NA) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NA;
    putQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = NIL;
  }
}
// 入力例 1                                                                     

// 2                                                                            
// 2 2                                                                          
// 5 3                                                                          

// 出力例 1                                                                     

// ......Q.                                                                     
// Q.......                                                                     
// ..Q.....                                                                     
// .......Q                                                                     
// .....Q..                                                                     
// ...Q....                                                                     
// .Q......                                                                     
// ....Q...                                                 



Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<cctype>
#include<string>

using namespace std;
string shu(string retu,int h){
    string start = retu.substr(0,h);
    string end = retu.substr(h,retu.size()-h);
    return end + start;
}
int main(){
    string card;
    int i,m,h;
    while(1){
        cin >> card;
        if(card=="-")break;
        cin >> m;
        for(i=0; i<m; i++){
            cin >>h;
            card=shu(card,h);
        }
        cout << card << endl;
    }
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        var subStrs = new HashSet<char>() { 'A', 'C', 'G', 'T' };

        int maxLen = 0;
        for (int i = 0; i < S.Length; i++)
        {
            for(int subLen = S.Length - i; i < subLen ; subLen--)
            {
                var sub = S.Substring(i, subLen);
                int count = 0;
                foreach (var ch in sub)
                {
                    if (subStrs.Contains(ch))
                    {
                        count++;
                        if(maxLen < count)
                        {
                            maxLen = count;
                        }
                    }
                    else
                    {
                        count = 0;
                        continue;
                    }
                }

            }
        }

        Console.WriteLine(maxLen);
    }
}



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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  if (N > K) {
    cout << K * X + (N - K) * Y << endl;
  }
  else {
    cout << N * X << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007

#define ARRAY_MAX 105

vector<vector<int> > G(ARRAY_MAX);
bool visited[ARRAY_MAX];

int v,e;


bool dfs(int now,int terminal){
    //現在位置、終点(=始点)
    if(visited[now] == true){
        //cout << "k" << endl;
        if(now == terminal){
            //すでにnowを訪れており、終点がnowの場合、閉路があった
            return true;
        }else{
            //既に訪れていたが始点ではなかった
            return false;
        }
    }
    visited[now] = true;//今いる場所をチェック
    bool flag = false;
    REP(i,G[now].size()){
        if(dfs(G[now][i],terminal)){
            flag = true;
            break;
        }
    }

    if(flag){
        return true;
    }else{
        return false;
    }
}

int main(){

    cin >> v >> e;
    REP(i,e){
        int s,t;
        cin >> s >> t;
        G[s].push_back(t);
    }
    //隣接リスト完成

    REP(i,v){
        //cout << "i= " << i << endl;
        REP(j,ARRAY_MAX){
            //初期化
            visited[j] = false;
        }
        if(dfs(i,i)){
            //cout << "ok i= " << i << endl;
            cout << "1" << endl;
            return 0;
        }
    }
    cout << "0" << endl;

    return 0;
}


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

int ans, k;

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

    cin >> k;

    int num = 7 % k;
    for (int i = 1; i <= k; i++) {
        if (num == 0) {
            cout << i << '\n';
            return 0;
        }

        num = (num * 10 + 7) % k;
    }

    cout << "-1\n";

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;


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

const ll MOD = 1000000007;
const ll INF = 1000000000;

int h[105];
ll ans = 0;



int main(void){
    int n, k;
    int h[100010];
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h, h + n);
    int ans = INF;
    for (int i = 0; i <= n - k; i++) ans = min(ans, h[i + k - 1] - h[i]);
    cout << ans << endl;

}



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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        switch(s.at(0)) {
            case 'A':
                a += 1;
                break;
            case 'W' :
                b += 1;
                break;
            case 'T':
                c += 1;
                break;
            case 'R':
                d += 1;
                break;
            default :
                break;
        }
    }
        cout << "AC" << " x " << a << "\n";
        cout << "WA" << " x " << b << "\n";
        cout << "TLE" << " x " << c << "\n";
        cout << "RE" << " x " << d << "\n";
    
}


Measured memory_bytes: 3648
#!/usr/bin/env python

while True:
    n = input()
    if n == 0:
        break
    lst = []
    for i in range(n):
        S = raw_input()
        hoge = S.split(':')
        hoge[1] = hoge[1][:-1].split(',')
        lst.append(hoge)
    mp = {}
    m = {}
    m[lst[0][0]] = 1
    for i in range(200):
        for l in lst:
            if l[0] in m:
                mp[l[0]] = 1
                for S in l[1]:
                    m[S] = 1
    
    print len(m) - len(mp)


Measured memory_bytes: 4756
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back
#define lp (p << 1)
#define rp (p << 1|1)

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
const int mod = (int)(1e9 + 7);

int N;
int A[20];

int main(){
	scanf("%d",&N);
	int sum = 1,s = 1;
	for(int i = 1; i <= N; ++i){
		scanf("%d",&A[i]);
		sum *= 3;
		int t = 0;
		if((A[i] - 1) % 2) t++;
		if((A[i] + 1) % 2) t++;
		if(A[i] % 2) t++;
		s *= t;
	}
	printf("%d\n",sum - s);
	return 0;
}

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

using namespace std;

int main()
{	
	char str[110];
	int flag;

	cin >> str;
	int length = strlen(str);

	for (int i = 0; str[i] != '\0'; i++) {
	    flag = 0;
		int cnt = count(str, str + length,str[i]);
		if (cnt % 2 != 0) {
			flag = 1;
			break;
		}
	}
	if (flag) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

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

int main(){
	cin.sync_with_stdio(false);
	//while(true){
	ll W,H,w,h;
	cin>>H>>W>>h>>w;
    vector<vi> a(H,vi(W));
    ll sum = 0;
    rep(i,0,H)
        rep(j,0,W){
            if((i+1)%h==0&&(j+1)%w==0) a[i][j] = -1000*h*w+999;
            else a[i][j] = 1000;
            sum+=a[i][j];
        }
    if(sum>0){
        cout<<"Yes"<<endl;
        rep(i,0,H){
            rep(j,0,W) cout<<a[i][j]<<" ";
            cout<<endl;
        }
    }else cout<<"No"<<endl;//}
}


Measured memory_bytes: 3584
import std;

int binary_search(int[] a, int x) {
  int
    left = -1,
    right = (a.length.to!int);
  while (right-left > 1) {
    int cur = (right+left) / 2;
    if (a[cur] < x)
      left = cur;
    else
      right = cur;
  }
  return right;
}


void main() {
  int n = readln.chomp.to!int;
  int[] l = readln.split.map!(to!int).array;
  l.sort();
  int ans = 0;
  foreach (int a; 0 .. n)
    foreach (int b; a+1 .. n)
      ans += l.binary_search(l[a] + l[b]) - b - 1;
  ans.writeln;
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    int n;
        cin >> n;
        vec v(n);
        for(int i=0; i<n; i++)
            cin >> v[i];
        sort(v.begin(), v.end());
        int ans = v[v.size()/2]-v[v.size()/2-1];
        cout << ans << endl;
}
    



Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! tf {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

fn gcd(x: i64, y: i64) -> i64 {
    tf!(y==0, x, gcd(y, x%y))
}

fn sim(a: i64, b: i64, c: i64, d: i64, lim: i64) -> bool {
    assert!( a > 0 );
    assert!( b > 0 );
    assert!( c > 0 );
    assert!( d > 0 );
    let mut x = a;
    for _ in 0..lim {
        if x - b < 0 {
            return false;
        }
        x -= b;
        if x <= c {
            x += d;
        }
    }
    return true;
}

fn main() {
    let n = read_i64() as usize;
    for _ in 0..n {
        let xs = read_vec_i64();
        let (a,b,c,d) = (xs[0], xs[1], xs[2], xs[3]);
        let res = if a < b {
            false
        }
        else if b > d {
            false
        }
        else if b <= c {
            true
        }
        else {
            let g = gcd(b,d);
            c >= b-g+(a%g)
        };
        println!("{}", tf!(res, "Yes", "No"));
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
double dist(int i,int j);

int n;
vector<int> x,y;

int main(){
	// sengen
	// nyuryoku
	cin >> n;
	x.assign(n,0); y.assign(n,0);
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
	}
	// keisan
	int mati[n];
	int kaijo = 1;
	for(int i=0;i<n;i++){
		mati[i] = i;
		kaijo *= i+1;
	}
	double sum = 0;
	do{
		for(int i=0;i<n-1;i++){
			sum += dist(mati[i],mati[i+1]);
		}
	}while(next_permutation(mati,mati+n));
	// syutsuryoku
	cout << setprecision(10) << sum/kaijo;
}

double dist(int i,int j){
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx*dx + dy*dy,0.5);
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

long gepoch(int y, int m, int d) {
    y += 4800;
    if (m < 3) --y, m += 12;
    return 365L*y+y/4-y/100+y/400+(153*m-457)/5+d-32045;
}

int main()
{
	int y1, m1, d1, y2, m2, d2 ;
	while(cin>>y1>>m1>>d1>>y2>>m2>>d2,~y1){
		cout << (-gepoch(y1,m1,d1) + gepoch(y2,m2,d2)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160