akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#include<assert.h>
#include<bitset>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))
#define rson(x) ((x<<1)|1)
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1e5 + 5;
class node
{
public:
    int u, v, w;
    node(int a, int b, int c) :u(a), v(b), w(c) {};
};
int fa[maxn];
int getf(int i)
{
    return i == fa[i] ? i : fa[i] = getf(fa[i]);
}
vector<node>edge;
bool cmp(const node&a, const node&b)
{
    return a.w < b.w;
}
class T//这就是一个普通的类,不是模板类,妈的,你不写结构体,和结构体是一个德行,无非看的不顺眼了些
{
public:
    int value, id;
    bool operator<(const T &a)
    {
        return value < a.value;
    }
};
T sx[maxn], sy[maxn];//对象数组,也就是结构体数组
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i, j, k, m, n, ta, tb;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        fa[i] = i;
    for (int i = 1; i <= n; ++i)
    {
        cin >> sx[i].value >> sy[i].value;
        sx[i].id = sy[i].id = i;
    }
    sort(sx + 1, sx + n + 1);
    sort(sy + 1, sy + 1 + n);
    for (int i = 1; i < n; ++i)
    {//其实对于min(|a-c|,|b-d|);这种是不好处理的,而把它认为是两条边就比较好处理了,好鸡巴强悍
        //当然了,这题用Kurskal算法更合适
        edge.push_back(node(sx[i].id, sx[i + 1].id, sx[i+1].value - sx[i].value));
        //这个加边还是很巧妙的,就是
        edge.push_back(node(sy[i].id, sy[i + 1].id, sy[i+1].value - sy[i].value));
    }
    sort(all(edge), cmp);
    ll ans = 0;
    for (int i = 0; i <edge.size(); ++i)
    {
        if (getf(edge[i].u) != getf(edge[i].v))
        {
            ans += edge[i].w;
            fa[getf(edge[i].u)] = getf(edge[i].v);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6772
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    long long tmp = 0;
    priority_queue<long long> pq;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        pq.push(tmp);
    }

    for(int i = 0; i < m; i++){
        tmp = pq.top();
        pq.pop();
        pq.push(tmp/2);
    }

    long long ans = 0;
    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
        
    }

     cout << ans << endl;

}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int ca = 0, cb = 0;
	rep(i,s.length()) {
		if (s[i] == 'c') {
			cout << "No" << endl;
		}
		if (s[i] == 'a') {
			ca++;
			if (ca + cb > a + b) {
				cout << "No" << endl;
			} else {
				cout << "Yes" << endl;
			}
		}
		if (s[i] == 'b') {
			cb++;
			if (ca + cb > a + b) {
				cout << "No" << endl;
			} else {
				if (cb > b) {
					cout << "No" << endl;
					cb--;
				} else {
					cout << "Yes" << endl;
				}
			}
		}
	}
	return 0;
}

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

int main()
{    
    string s;
    cin >> s;
    int n = s.size();

    int hug_cnt = 0;
    rep(i,n/2)
        if(s[i] != s[n-1-i])
            hug_cnt++;
    
    cout << hug_cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll inv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = inv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}

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

    int n, k;
    cin >> n >> k;

    init(n * 3);

    for (int i = 1; i <= k; i++) {
        int k0 = k - i;
        int k1 = n - k - (i - 1);
        ll r = 0;
        if (k0 < 0 || k1 < 0) {
            r = 0;
        } else {
            r = comb(k0 + (i - 1), k0) * comb(k1 + i, k1) % P;
        }
        cout << r << '\n';
    }
    cout << flush;

    return 0;
}

Measured memory_bytes: 384
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
x = int(input())
print(n[x-1])

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

using namespace std;

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

    int x;
    cin >> x;
    cout << x / 500 * 1000 + (x % 500) / 5 * 5 << '\n';

    return 0;
}

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

set<int> ans;

int main()
{
	int temp;
	for(int i = 1; i <= 3; ++i)
	{
		cin >> temp;
		ans.insert(temp);
	}
	if(ans.size() == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

string s;
int f[123];

int main(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		f[s[i]]++;
	}
	for(int i=97;i<=122;i++){
		if(f[i]==0){
			char c;
			switch(i){
			case 97:
				c='a';
				break;
			case 98:
				c='b';
				break;
			case 99:
				c='c';
				break;
			case 100:
				c='d';
				break;
			case 101:
				c='e';
				break;
			case 102:
				c='f';
				break;
			case 103:
				c='g';
				break;
			case 104:
				c='h';
				break;
			case 105:
				c='i';
				break;
			case 106:
				c='j';
				break;
			case 107:
				c='k';
				break;
			case 108:
				c='l';
				break;
			case 109:
				c='m';
				break;
			case 110:
				c='n';
				break;
			case 111:
				c='o';
				break;
			case 112:
				c='p';
				break;
			case 113:
				c='q';
				break;
			case 114:
				c='r';
				break;
			case 115:
				c='s';
				break;
			case 116:
				c='t';
				break;
			case 117:
				c='u';
				break;
			case 118:
				c='v';
				break;
			case 119:
				c='w';
				break;
			case 120:
				c='x';
				break;
			case 121:
				c='y';
				break;
			case 122:
				c='z';
				break;
			}
			printf("%c\n",c);
			break;
		}
		if(i==122) printf("None\n");
	}
	//97 122
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<' '
#define AA(i) cout<<i<<' ';
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    int i;
    ll H = 0;
    ll ans;
    rep(i,N) {
        cin >> a[i];
        H ^= a[i]; 
    }
    rep(i,N) {
        ans = H^a[i];
        AA(ans);
    }
    return 0;
}

Measured memory_bytes: 4776
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();

		int[] c = new int[n];
		int[][] a = new int[n][m];
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			for (int j = 0; j < m; j++)
				a[i][j] = sc.nextInt();
		}

		int length = (int) Math.pow(2, n);
		int min = Arrays.stream(c).sum();
		boolean isAssigned = false;
		for (int i = 1; i < length; i++) {
			int costSum = 0;
			int[] valSum = new int[m];
			
			String cursor = Integer.toBinaryString(i);
			//System.out.print("cursor: " + cursor + " -> ");
			for (int j = cursor.length() - 1; j >= 0; j--) {
				if (cursor.charAt(j) == '1') {
					int index = cursor.length() - j - 1;
					//System.out.print(index);
					costSum += c[index];
					for(int k = 0; k < m; k++) {
						valSum[k] += a[index][k];
					}
				}
			}
			//System.out.println();
			
			boolean allOK = true;
			for(int j = 0; j < m; j++) {
				if(valSum[j] < x) {
					allOK = false;
					break;
				}
			}
			if(allOK && costSum <= min) {
				min = costSum;
				isAssigned = true;
			}
		}
		
		if(isAssigned)
			System.out.println(min);
		else
			System.out.println(-1);
	}
}


Measured memory_bytes: 38744
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000*1000*1000+7
#define mem(dp,a) memset(dp,a,sizeof dp)
int32_t main()
{
    int h,a;cin>>h>>a;
    int ans= (h/a) + ((h%a)?1:0);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int n,m,a,count = 0;
  cin>>n>>m;
  for(int i = 0;i < m;i++)
  {
    cin >> a;
    count += a;
  }
  if(n - count < 0)
  {
    cout << "-1" <<endl;
  }
  else
  {
    cout << n - count <<endl;
  }
    return 0;
}

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

using namespace std;

typedef long long int ll;

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

    vector <int> a(n+1),b(n);

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

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


    ll ans =0;
    int def =0;

    for(int i=0;i<n;i++)
    {

        ll temp = min(a[i],b[i]);

        ans+=temp;

        b[i] = b[i]-temp;

        temp = min(a[i+1],b[i]);

        ans+=temp;

        a[i+1] = a[i+1]-temp;



    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld long double
const int MX1=1e5+5;
const int MX2=1e6+5;
const li inf=4e18;
const li mod=1e9+7;

li power(li a,li b){li res=1;while(b){if(b%2)res=(res*a)%mod;
a=(a*a)%mod;b/=2;}return res;}

li mmi(li a){return power(a,mod-2);}

li cntbit(li n){li cnt=0;while(n){n&=(n-1);cnt++;}return cnt;}

void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	multiset<int> ms;
	ms.insert(a);
	ms.insert(b);
	ms.insert(c);
	int cnt=0;
	while(cnt<=1e5){
		set<int> s;
		for(auto it:ms){
			s.insert(it);
		}
		if((int)s.size()==1) break;
		int x=*ms.begin();
		ms.erase(ms.begin());
		int y=*ms.begin();
		ms.erase(ms.begin());
		while(x+1<=*ms.begin() and y+1<=*ms.begin()){
			x++;
			y++;
			cnt++;
		}
		while(x+2<=*ms.begin()){
			x+=2;
			cnt++;
		}
		if(x!=*ms.begin()){
			cnt++;
			ms.insert(x+2);
			ms.insert(y);
		}
	}
	cout<<cnt;
}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
total = 0
for i in range(N):
    if(A[i]<=B[i]):
        if(A[i+1]<= B[i] - A[i]):
            total+= A[i+1]+A[i]
            A[i+1]=0 
        else:
            A[i+1]-= B[i] - A[i]
            total += B[i]
    else:
        total += B[i]
print(total)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
using namespace std;

void PUNKS_NOT_DEAD() {
    int a, b, c;
    cin >> a >> b >> c;
    if (c < (a + b)) {
        cout << "No";
        exit(0);
    }
    if (4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    PUNKS_NOT_DEAD();
}

Measured memory_bytes: 256
using System;

class sample
{
		static void Main()
		{
				string[] input = Console.ReadLine().Split(' ');
				string[] input2 = Console.ReadLine().Split(' ');

				int H = Convert.ToInt32(input[0]);
				int N = Convert.ToInt32(input[1]);

				int[] damage = new int[N];
				int cnt = 0;

				for(int i=0;i<N;i++)
				{
						damage[i]=Convert.ToInt32(input2[i]);
						cnt += damage[i];
				}
				

				if((H-cnt)<=0)
				{
	                    Console.WriteLine("Yes");
				}
				else
				{ 
				        Console.WriteLine("No");
				}
		}
}

				


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

signed main() {
  int n, p;
  string s;
  cin >> n >> p >> s;

  reverse(s.begin(),s.end());

  if(p == 2 || p == 5) {
    int cnt = 0;

    for (int i = 0; i < n; i++) {
      if((s[i] - '0') % p == 0) cnt += (n - i);
    }
    cout << cnt << '\n';
    return 0;
  }

  map<int,int> mp;
  mp[0] = 1;

  int ten = 1;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp = (s[i] - '0') * ten + tmp;
    tmp %= p;
    ten *= 10;
    ten %= p;
    mp[tmp]++;
  }
  int ans = 0;
  for (auto it : mp) {
    ans += (it.second) * (it.second - 1) / 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1028
int main(void){
  int K, A, B, c = 0;
  scanf("%d", &K);
  scanf("%d", &A);
  scanf("%d", &B);

  for(int i = A; i <= B; i++){
    if(i % K == 0) c += 1;
  }

  if(c == 0) printf("NG\n");
  else printf("OK\n");


  return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    auto it1 = lower_bound(a.begin(), a.end(), x);
    int ans = min(it1-a.begin(), m-(it1-a.begin()));
    cout << ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

template<class T> class rollinghash {
public:
	const ull mask30 = (1LL << 30) - 1;
	const ull mask31 = (1LL << 31) - 1;
	const ull mod61 = (1LL << 61) - 1;
	const ull base = 10000001;
	vector<ull> hashvalue, basepower;
	int length;
	ull modulo(ull a) {
		ull au = a >> 61; ull ad = a & mod61;
		ull res = au + ad; if (res >= mod61) res -= mod61;
		return res;
	}
	ull multiply(ull a, ull b) {
		ull au = a >> 31; ull ad = a & mask31;
		ull bu = b >> 31; ull bd = b & mask31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30; ull midd = mid & mask30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}
	rollinghash(T s) {
		length = s.size();
		hashvalue = vector<ull>(length + 1);
		for (int i = 0; i < length; i++) {
			hashvalue[i + 1] = modulo(multiply(hashvalue[i], base) + s[i] + 1);
		}
		basepower = vector<ull>(length + 1);
		basepower[0] = 1;
		for (int i = 1; i <= length; i++) {
			basepower[i] = modulo(multiply(basepower[i - 1], base));
		}
	}
	ull hash(ll l, ll r) {
		assert(l <= r && 0 <= l && l <= length && 0 < r && r <= length);
		return modulo(hashvalue[r] + mod61 - modulo(multiply(hashvalue[l], basepower[r - l])));
	}
};

const int N = 500010;
vector<bool> ok(N);
int x, y;
vector<int> ans(N);
vector<bool> vis(N);
bool infi = false;

int solve(int now, int st, bool flag) {
	if (flag && now == st) {
		infi = true;
		return ans[now] = 0;
	}
	if (vis[now]) return ans[now];
	vis[now] = true;
	if (!ok[now]) return ans[now] = 0;
	int nxt = (now + y) % x;
	solve(nxt, st, true);
	return ans[now] = ans[nxt] + 1;
}

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

	string s, t;
	cin >> s >> t;
	x = s.size();
	y = t.size();
	int p = (1000010 + x - 1) / x;
	string b = "";
	rep(i, p) b += s;
	rollinghash rol(b), check(t);
	ll ha = check.hash(0, y);
	rep(i, x) {
		if (rol.hash(i, i + y) == ha) ok[i] = true;
	}
	rep(i, x) solve(i, i, false);
	int res = 0;
	rep(i, x) {
		chmax(res, ans[i]);
	}
	cout << (infi ? -1 : res) << '\n';
}

Measured memory_bytes: 55128
/* Manish Pant - insider_pants, hello_my_friend */
    
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } 

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N = 2e5 + 5;
int n;
vector<int> v;

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();

struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};

gp_hash_table<int, ll, chash> m;

void solve()
{
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        int mx = max(i, n - i - 1);
        if(v[i] >= mx) continue;

        ans += m[i - v[i]];
        m[i + v[i]]++;
    }
    cout << ans << endl;
}

int main()
{
    fast();
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a; cin >> a;
        v.pb(a);
    }
    solve();
}

Measured memory_bytes: 23248
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 105;
bool vis[N];
int main() {
    int n ,k;
    scanf("%d%d", &n, &k);
    for(int i = 0, x, y; i < k; i++) {
        scanf("%d", &x);
        for(int j = 0; j < x; j++) {
            scanf("%d", &y);
            vis[y] = true;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3816
<?php
$n = int();
$a = ints();
array_unshift($a, 10**10);
$a[] = 10**10;
$sum = 0;
for($i = 0; $i < $n;$i++){
  $sum += min($a[$i],$a[$i+1]);
}
echo $sum;

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 4728
#include<iostream>
#define ll long long
using namespace std;

int H;
ll A[500001];

int parent(int i){return i/2;}

int left(int i){return 2*i;}

int right(int i){return 2*i+1;}

void maxHeapify(int i){
  int l,r;

  l=left(i);
  r=right(i);
  
  int largest=i;
 
  if(0<l&&l<=H){
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  }
 
  if(0<r&&r<=H)if(r<=H&&A[r]>A[largest])largest=r;
 
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(largest); 
  }

}

void buildMaxHeap(){

  for(int i=H/2;i>0;i--) maxHeapify(i);

}

void solve(){
  buildMaxHeap();
  for(int i=1;i<=H;i++) cout<<" "<<A[i];
  cout<<endl;
}

int main(){

  cin>>H;
 
 for(int i=1;i<=H;i++) cin>>A[i];
 // for(int i=1;i<=H;i++) cout<<A[i]<<endl;
 solve();
  return 0;
}

Measured memory_bytes: 5068
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll dp[5010][5010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    ll a[5010];
    cin >> N >> K;
    rep(i,0,N) cin >> a[i];
    sort(a, a+N);
    // ll ans = 0;
    // if(N > 400 || K > 400) return 0;
    ll rv = N, lv = -1;
    while(rv - lv > 1){
        ll t = (rv+lv)/2;
        ll tmp = a[t];
        a[t] = 0;
        rep(i,0,N+1){
            rep(j,0,K+1){
                dp[i][j] = 0;
            }
        }
        dp[0][0] = 1;
        rep(i,0,N){
            rep(j,0,K+1){
                dp[i+1][j] |= dp[i][j];
                if(j - a[i] >= 0){
                    dp[i+1][j] |= dp[i][j - a[i]];
                }
            }
        }
        bool ok = false;
        if(K - tmp < 0){
            rv = t;
            continue;
        }
        rep(i,K-tmp,K){
            if(dp[N][i] == 1) ok = true;
        }
        // if(!ok) ans++;
        a[t] = tmp;
        if(!ok){
            lv = t;
        }else{
            rv = t;
        }
    }
    print(lv+1);
    // rep(t,0,N){
    //     ll tmp = a[t];
    //     a[t] = 0;
    //     rep(i,0,N+1){
    //         rep(j,0,K+1){
    //             dp[i][j] = 0;
    //         }
    //     }
    //     dp[0][0] = 1;
    //     rep(i,0,N){
    //         rep(j,0,K+1){
    //             dp[i+1][j] |= dp[i][j];
    //             if(j - a[i] >= 0){
    //                 dp[i+1][j] |= dp[i][j - a[i]];
    //             }
    //         }
    //     }
    //     bool ok = false;
    //     if(K - tmp < 0) continue;
    //     rep(i,K-tmp,K){
    //         if(dp[N][i] == 1) ok = true;
    //     }
    //     if(!ok) ans++;
    //     a[t] = tmp;
    // }
    // print(ans);


}


Measured memory_bytes: 196096
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC054A - One Card Poker
  // 1から13までの数が書かれたトランプで1枚ポーカー
  // 2 < 3 < 4 < … < 12 < 13 < 1 （強さの基準）
  int A, B; cin >> A >> B;
  if(A == B){
    cout << "Draw" << endl; // カードの種類に関わらず引き分けは同じ条件
  }else if(A == 1 || (A > B && B != 1)){
    cout << "Alice" << endl; // Aliceが勝つ条件を全て列挙
  }else{
    cout << "Bob" << endl; // 残りは全てBobが勝つ状態
  }
}

Measured memory_bytes: 256
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static String file = "../in";

    public static void main(String[] args) throws Exception
    {
        int test = 10,   // 0 for local testing, 1 for std input
            _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}

        new Main().e();

    }

    long[] f = new long[100_010], ff = new long[100_010];
    int mod = 1_000_000_007;
    
    void e() throws Exception
    {
        String[] sp = in.readLine().split(" ");
        int n = Integer.valueOf(sp[0]),
            k = Integer.valueOf(sp[1]);
        int[] ary = new int[n];
        sp = in.readLine().split(" ");    
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        Arrays.sort(ary);
        // 
        
        long sum = 0;

        f[0] = 1;
        ff[0] = 1;
        for(int i = 1; i <= 100_000; i++)
        {
            f[i] = f[i - 1] * i;
            f[i] %= mod;
            ff[i] = inverseMod(f[i]);
            ff[i] %= mod;
        }
 
        for(int i = 0; i < n; i++)
        {
            long f1 = comb(i, k - 1);
            long f2 = comb(n - 1 - i, k - 1);
            // System.out.printf("%d %d %d\n", f1, f2, ary[i]);
            sum = (sum + f1 * ary[i]) % mod;
            sum = (sum - f2 * ary[i]) % mod;
        }
 
        System.out.println(sum % mod);
    }

    long inverseMod(long a)
    {
        return pow(a, mod - 2);
    }

    long comb(int n, int k)
    {
        // n choose m
        if(n < 0 || k < 0) return 0;
        if(k > n) return 0;
        if(k == 0) return 1;
        
        return (((f[n] * ff[k]) % mod) * ff[n - k]) % mod;
    }

    long pow(long a, int b)
    {
        long re = 1;
        while(b > 0)
        {
            if(b % 2 != 0) {
                re *= a;
                re %= mod;
            }
            a = a * a;
            a %= mod;
            b /= 2;
        }

        return re;
    }
}

Measured memory_bytes: 50332
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		double a, b, C;
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		a = Double.parseDouble(str.split(" ")[0]);
		b = Double.parseDouble(str.split(" ")[1]);
		C = Double.parseDouble(str.split(" ")[2]);
		double sin = Math.sin(Math.toRadians(C));
		double cos = Math.cos(Math.toRadians(C));
		Double S = a * b * sin / 2;
		Double y = a * a + b * b - 2 * a * b * cos;
		Double x = Math.sqrt(y);
		// Double x = 2 * S - a - b;
		// Double y = -(S * S / (x * (x - a) * (x - b))) + x;
		System.out.println(S);
		System.out.println(x + a + b);
		System.out.println(sin * b);
	}
}



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

// 二分探索を行う関数
bool binarySearch(int key, int n, const vector<int>& A) {
    // 探索範囲の左端
    int left = 0;
    // 探索範囲の右端
    int right = n;

    while (left < right){
        // 探索範囲の真ん中を求める
        int mid = (left + right) / 2;

        // 真ん中がkeyの場合
        if (key == A[mid]) return true;
        
        // 真ん中がkeyではなかった場合
        if (key > A[mid]) left = mid + 1;   // 後半を探索
        else if (key < A[mid]) right = mid; // 前半を探索
    }

    return false;
}

int main() {
    // 数列Sの要素数n
    int n;
    cin >> n;

    // 数列Sを格納するための配列（nの最大値+α）
    vector<int> A(100100);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    // 数列Tの要素数q
    int q;
    cin >> q;

    // 数列T内の要素を格納する変数
    int key;
    // 答えを格納する変数
    int sum = 0;

    for (int i = 0; i < q; ++i) {
        cin >> key;
        if (binarySearch(key, n, A)) ++sum;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int used[100005];
int main()
{
    int n;
    cin >> n;
    vector<int> num(n);
    for(int i = 0;i < n;i++)
        scanf("%d",&num[i]),used[num[i]]++;
    sort(num.begin(),num.end());
    int cards = n;
    for(int i = num.size()-1;i >= 0;i--)
    {
        if(used[num[i]] >= 2)
        {
            int lo = 0;
            for(;lo < num.size();lo++)
            {
                if(used[num[lo]] >= 2 && lo != i)
                    break;
            }
            if(used[num[i]] >= 2 && used[num[lo]] >= 1)
            {
                used[num[i]]--;
                used[num[lo]]--;
                cards -= 2;
            }
        }
    }
    cout << cards;
    return 0;
}


Measured memory_bytes: 1024
#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 <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <functional>


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

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

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


int main(){
	vector<int> v(10);
	string s;
	while(cin>>s){
		for (int i = 0; i < 10; i++) v[i] = s[i] - '0';
		for (int i = 0; i < 10 - 1; i++){
			for (int j = 0; j < 10-i-1; j++){
				v[j] = (v[j] + v[j+1]) % 10;
			}
		}
		printf("%d\n",v[0]);
	}
	return 0;
}

Measured memory_bytes: 0
//#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
//#include<cmath>
//#include<string>
//#include<cctype>
//#include <vector>
using namespace std;
int main() {
	int n, w;
	double ans;
	for (; cin >> n >> w, n, w; cout << ans+0.01 << endl) {
		int a[100] = {},
			s =0,
			h = 0;
		ans = 0;
		while (n--) {
			int b;
			cin >> b;
			a[b / w]++;
			s = max(s, b / w);
			h = max(h, a[b / w]);
		}
		for (int i = 0; i <= s; i++)
			ans += (double)a[i] / h*(s - i) / s;
	}
	return 0;
}

Measured memory_bytes: 3212
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, 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")
    };
}
use std::collections::HashMap;
fn main() {
    input!{
        n:usize,
        tn:[i64;n],
    }
    let ans = tn.iter().fold(tn[0],|y,x| lcm(y,*x));
    println!("{}",ans);
}
fn gcd(a:i64,b:i64) -> i64{
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}
fn lcm(a:i64,b:i64) -> i64{
    a  / gcd(a, b) * b
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N; cin >> N;
  string S; cin >> S;

  ll len{1};
  ll res{};
  for (size_t i = 0; i < S.size(); ++i)
  {
    if(!(i + len <= S.size())){
      break;
    }
    string str = S.substr(i, len);
    auto it = S.find(str, i + len);
    while (it != S.npos)
    {
      ++len;
      str += S[i + len - 1];
      it = S.find(str, i + len);
    }
    chmax(res, len - 1);
  }
  cout << res << CRLF;  


  // ll res = S.size() / 2;
  // ll hited_len{};
  // for (size_t i = 0; i < S.size(); i++)
  // {
  //   for(size_t len = res; len > 0; --len){
  //     if(i + len >= S.size()){
  //       continue;
  //     }
  //     if(len < hited_len){
  //       break;
  //     }
  //     string str = S.substr(i, len);
  //     auto it = S.find(str, i + len);
  //     if(it != S.npos){
  //       chmax(hited_len, (ll)len);
  //       break;
  //     }
  //     else
  //     {
  //       continue;
  //     }
  //   }
  // }

  // cout << hited_len << CRLF;  
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF2 1000000000000000000
#define INF 2000000000
#define int long long int
struct edge { int to, cost; };
typedef pair<int, int> P;

int V;
vector<int> G[300010];
int d[300010];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + 300000 + 1, INF2);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++){
            int to = G[v][i];
            if (d[to] > d[v] + 1) {
                d[to] = d[v] + 1;
                que.push(P(d[to], to));
            }
        }
    }
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int s, t; cin >> s >> t;
        s--; t--;
        rep(j, 3) {
            int u = (s + 100000 * j);
            int v = (t + 100000 * (j + 1)) % 300000;
            G[u].push_back(v);
        }
    }
    int S, G; cin >> S >> G;
    S--; G--;
    dijkstra(S);
    int len = d[G];
    if (len >= INF) {
        cout << -1 << endl; 
    } else {
        cout << len / 3 << endl;
    }
    //dump(len);
    //rep(i, N) cout << i << " " << d[i] << endl;



    return 0;
}


Measured memory_bytes: 19072
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int n,a[100010];
int main()
{
	int i,j;
	ll sum=0,cnd=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		if(a[i]<0)
		{
			cnd++;
			a[i]=-a[i];
			sum+=a[i];
		}
		else 
		    sum+=a[i];
	}
	sort(a,a+n);
	if(cnd%2==0)
	{
		printf("%lld\n",sum);
	}
	else 
	{
		printf("%lld\n",sum-2*a[0]);
	}

	return 0;
}

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

typedef long long LL;
const int MAX = 200001;
const LL MOD = 1000000007;

long long fact[MAX];
long long inv[MAX];

LL mod_pow(LL x,LL n){
    LL ret = 1;

    while(n){
        if(n & 1)ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }

    return ret;
}

LL mod_P(LL n,LL k){
    if(n < k)return 0;
    LL ret = 1;
    for(LL i = 0;i < k;i++)ret = ret * (n - i) % MOD;
    return ret;
}

LL mod_C(LL n,LL k){
    if(n < k)return 0;
    return mod_P(n,k) * inv[k] % MOD;
}

void init(){
    fact[0] = inv[0] = 1;
    for(int i = 1;i < MAX;i++){
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = mod_pow(fact[i],MOD - 2);
    }
}

int main(){
    init();
    LL n,a,b;
    
    cin >> n >> a >> b;
    
    LL ans =((mod_pow(2,n) - 1 - mod_C(n,a) + MOD) - mod_C(n,b) + MOD) % MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main()
{
    long int n;
    scanf("%ld",&n);
    int count_500 = n/500;
    int count_5;
    if(n%500>=0)
    {
        count_5 = (n%500)/5;
    }
    printf("%d\n",1000*count_500+5*count_5);
    return 0;
}

Measured memory_bytes: 128
a = {}

while True:
    try:
        a_i = int(input())
        if a_i in a:
            a[a_i] += 1
        else:
            a[a_i] = 1
    except:
        break

mode_count = max(a.values())

b = []
for key, value in a.items():
    if value == mode_count:
        b.append(key)

print(*sorted(b),sep="\n")



Measured memory_bytes: 5596
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>();
    let mut ans = 0;
    for (i, ch) in s.chars().enumerate() {
        if i % 2 == 0 {
            if ch == 'p' {
                ans -= 1;
            }
        } else {
            if ch == 'g' {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main()
{
	int N, Q;
	cin >> N >> Q;
	char S[100000];
	int t[100000];
	t[0] = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
		if (i > 0)
		{
			t[i] = t[i - 1];

			if (S[i] == 'C'&&S[i - 1] == 'A')
			{
				t[i]++;
			}
		}
		
	}
	int ans[100000];
	int l[100000], r[100000];
	for (int i = 0; i < Q; i++)
	{
		cin >> l[i] >> r[i];
		l[i]--; r[i]--;
		ans[i] = t[r[i]] - t[l[i]];
	}
	for (int i = 0; i < Q; i++)
		cout << ans[i] << '\n';
	
	return 0;

}

Measured memory_bytes: 2432
#!/usr/bin/env ruby

def main
    n = gets.to_i
    as = gets.chomp.split(" ").map(&:to_i)
    as_sort = as.sort.reverse

    # alice = as_sort.each_slice(2).map(&:first).inject(:+)
    # bob = as_sort.each_slice(2).map(&:last).inject(:+)
    alice = 0
    bob = 0
    (as_sort.length).times do |i|
        alice += as_sort[i] if i%2==0
        bob += as_sort[i] if i%2==1
    end
    puts alice-bob    
end

main

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

int main() {
    ll n;
    std::cin >> n;
    string s;
    std::cin >> s;
    string s2 = s.substr(n,n);
    reverse(s2.begin(),s2.end());
    
    map<pair<string,string>,ll> m1,m2;
    
    for (int i = 0; i < (1<<n); i++) {
        string red = "";
        string blu = "";
        string red1= "";
        string blu1= "";
        
        for (int j = 0; j < n; j++) {
            if(i&(1<<j)){
                red += s[j];
                red1+= s2[j];
            }else{
                blu += s[j];
                blu1+= s2[j];
            }
        }
        m1[{red,blu}]++;
        m2[{red1,blu1}]++;
    }
    ll ans = 0;
    for (auto e : m1) {

        ans += e.second*m2[e.first];
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 89620
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, m, l;
int st[305][305];
ll mat[305][305] = {0};
void init(){
    n = read(), m = read(), l = read();
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            mat[i][j] = 1000000000000000ll;
    for (int i = 1; i <= n; ++i)
        mat[i][i] = 0;
    for (int i = 1; i <= m; ++i){
        int u = read(), v = read(), w = read();
        mat[u][v] = mat[v][u] = w;
    }
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
    memset(st, 0x3f, sizeof(st));
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j){
            if (i == j || mat[i][j] <= l) 
                st[i][j] = 0;
        }
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j){
                if (st[i][k] < 0 || st[k][j] < 0) continue;
                st[i][j] = min(st[i][j], st[i][k] + 1 + st[k][j]);
            }
}
void solve(){
    int q = read();
    while (q--){
        int s = read(), t = read();
        if (st[s][t] < 0 || st[s][t] == 0x3f3f3f3f)
            printf("-1\n");
        else printf("%d\n", st[s][t]);
    }
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 1664
//0043 Puzzle
//vñF`CcÌãªèvð¦¹

#include<cstdio>
#include<algorithm>

using namespace std;

//evª éÂA4ÚÈãÍg¦È¢
int haiCount[10] = {0};

bool f(int mentsuCount)
{
	if(mentsuCount == 4)
		return true;
	int i;
	bool result;
	//Æè ¦¸AÔÉR[cÆ¼èµÄÊqðìé
	for(i = 1; i <= 9; i++)
	{
		if(haiCount[i] >= 3)
		{
			haiCount[i] -= 3;
			result = f(mentsuCount+1);
			haiCount[i] += 3;
			if(result)
			{
				return true;
			}
		}
	}
	//ÍAWcÆ¼èµÄÊqðìé
	for(i = 1; i <= 7; i++)
	{
		if(haiCount[i] && haiCount[i+1] && haiCount[i+2])
		{
			haiCount[i]--, haiCount[i+1]--, haiCount[i+2]--;
			result = f(mentsuCount+1);
			haiCount[i]++, haiCount[i+1]++, haiCount[i+2]++;
			if(result)
			{
				return true;
			}
		}
	}
	return false;
}

int main(void)
{
	const int N =14;
	char hai[N];
	int i;
	int head;
	bool canOut;	//ãªêéH
	int outCount;	//ãªêévÌÂ

	while(scanf("%s", hai) == 1)
	{
		fill(haiCount, haiCount+10, 0);
		for(i = 0; i < N-1; i++)
			haiCount[hai[i]-'0']++;

		outCount = 0;

		//15ÚÌvðø­
		for(i = 1; i <= 9; i++)
		{
			canOut = false;
			if(haiCount[i] ==4)
				continue;

			//g¤vªêÂ¦Üµ½
			haiCount[i]++;

			//Ü¸Íª©çÅèµÄ¢«Üµå¤
			for(head = 1; head <= 9; head++)
			{
				if(haiCount[head] < 2)
					continue;

				haiCount[head] -= 2;
				canOut = f(0);
				haiCount[head] += 2;
				if(canOut)
				{
					break;
				}
			}

			if(canOut)
			{
				if(outCount++)
					printf(" %d", i);
				else
					printf("%d", i);
			}

			//gíÈ­ÈèÜµ½
			haiCount[i]--;
		}
		if(!outCount)
			puts("0");
		else
			putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
#define ll long long
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
using namespace std;
int main() {
    ll n, c = 100,cnt = 0;
    cin >> n;
    while(n > c) {
        cnt++;
        c *= 1.01;
    }
    cout << fixed << cnt;
}

Measured memory_bytes: 3632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

// use std::io::{stdout, Write, BufWriter};
use std::cmp::min;

fn main() {
    input! {
        a_size: usize,
        b_size: usize,
        m: usize,
        refg: [i32; a_size],
        mw: [i32; b_size],
        xyc: [(usize, usize, i32); m],
    }

    let mut ans = refg.iter().min().unwrap() + mw.iter().min().unwrap();

    for (x, y, c) in xyc {
        ans = min(ans , *(refg.get(x - 1).unwrap()) + *(mw.get(y - 1).unwrap()) - c)
    }

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


Measured memory_bytes: 14328
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<int> A(M),B(M),C(M);
    int dist[N][N];
    rep(i,0,N)rep(j,0,N)dist[i][j] = INF;
    rep(i,0,N)dist[i][i] = 0;
    rep(i,0,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;B[i]--;
        dist[A[i]][B[i]] = dist[B[i]][A[i]] = C[i];
    }
    rep(i,0,N)rep(j,0,N)rep(k,0,N){
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
    }
    int cnt = 0;
    rep(i,0,M){
        if(dist[A[i]][B[i]] != C[i])cnt++;
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256