akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 5;
int n, a[N], b[N], cnt[N], cnt2[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(int i=1; i<=n; i++) 
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	set<pii, greater<pii>> st;
	for(int i=1; i<=n; i++) 
	{
		cin >> b[i];
		cnt2[b[i]]++;
		st.insert({cnt[b[i]], b[i]});
	}
	for(int i=1; i<=n; i++)
	{
		auto it = *st.begin();
		st.erase(st.begin());
		--cnt[a[i]];
		if(it.se!=a[i])
		{
			b[i] = it.se;
			if(--cnt2[it.se]) st.insert({cnt[it.se], it.se});
		}
		else
		{
			if(st.size())
			{
				auto it2 = *st.begin();
				st.erase(st.begin());
				b[i] = it2.se;
				if(--cnt2[it2.se]) st.insert({cnt[it2.se], it2.se});
				st.insert({cnt[it.se], it.se});
			}
			else 
			{
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	for(int i=1; i<=n; i++) cout << b[i] << " \n"[i==n];
	return 0;
}

Measured memory_bytes: 16088
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double

ll gcd(ll x,ll y) {
  if (x%y==0) return y;
  return gcd(y,x%y);
}

int main()
{
  ll x,y;
  cin>>x>>y;

  ll mx=max(x,y),mi=min(x,y);
  cout<<gcd(mx,mi)<<endl;

  return 0;
}



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

int main() {

    int N, C, K;
    cin >> N >> C >> K;

    vector<int> T(N);
    rep(i, N) cin >> T[i];

    sort(T.begin(), T.end());

    int ans = 0, start;

    for (int i = 0; i < N;) {
        start = i;
        ans++;
        while (i < N and T[i]-T[start]<= K and i-start < C) i++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3780
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int X;
  cin >> X;
  if (X == 0)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env ruby
def read_input()
  edge_num = gets(chomp: true).to_i
  edges = []
  graph = Hash.new { |hash,key| hash[key] = [] }
  (1...edge_num).reduce([edges,graph]) do |acc,_|
    edges, graph = acc
    edge = gets(chomp: true).split()
    edges << edge
    a,b = edge
    if (!graph.has_key?(a))
      graph[a] = []
    end
    graph[a] << b
    [edges, graph]
  end
end

def select_color(current, parent_color)
  if (current + 1 == parent_color)
    current + 2
  else
    current + 1
  end
end

def calc_max(max, children_num, is_root)
  return children_num if (is_root)
  
  if (children_num + 1 > max)
    children_num + 1
  else
    max
  end
end

def solve(graph, node, parent_color, color_edge, max)
  children = graph[node]
  return [max, color_edge] if children.nil?

  max = calc_max(max, children.length, parent_color.nil?)
  color = 0
  children.reduce([max, color_edge]) do |acc, child|
    max, color_edge = acc
    color = select_color(color, parent_color)
    color_edge[node][child] = color
    solve(graph, child, color, color_edge, max)
  end
end

edges, graph = read_input
color_edge = Hash.new {|hash,key| hash[key] = {} }
max, color_edge = solve(graph, "1", nil, color_edge , -1)

puts max
edges.each do |a,b|
  puts color_edge[a][b]
end


Measured memory_bytes: 209148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//----------------------//

int main() {
	int x; cin >> x;
	
	ll ans = 2;
	REP(i, x) {
		ll l = 0, r = 1e16;
		while (r - l > 1) {
			ll m = (l + r) / 2;
			if (m - ans - 1 >= ans + 2) r = m;
			else l = m;
		}
		ans = l;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  int sum = 1;
  for (int i =0;i < n;i++){
    if ( (sum * 2) >= (sum + k) ) {
      sum += k;
    }
    else sum *= 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
H = l.shift() * 1
W = l.shift() * 1 
N = inp.shift() * 1
ans = []
for (i=0; i<H; i++) {
    ans[i] = new Array(W)
}

h = 0
w = 0
a = inp.shift().split(' ')
m = 'R'
for (i=0; i<N; i++) {
    n = a[i] * 1
    for (j=0; j<n; j++) {
        if (ans[h][w] === undefined) {
            ans[h][w] = i+1
        }

        if (w == W - 1 && m == 'R') {
            h++
            m = 'L'
        } else if (w === 0 && m == 'L') {
            h++
            m = 'R'
        } else if (m == 'R') {
            w++
        } else if (m == 'L') {
            w--
        }
    }
}
console.log(ans.map(a => a.join(' ')).join('\n'))

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

int main()
{
    int a,b,c;
    int i;
    int count = 0;

    scanf("%d %d %d",&a,&b,&c);
    for (i = a;i <= b;i++)
    {
        if(c%i==0)
        {
            count++;
        }
    }

    printf("%d\n",count);

    return 0;
}

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

int main() {
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  string a[210];
  
  rep(i,n){
    a[2*i]=s[i];
  a[2*i+1]=t[i];
  }
  
  rep(i,2*n)cout<<a[i];
  cout<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
    ll n, k;
    cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ll cnt = i;
        double tmp = 1.0 / double(n);
        while (cnt < k)
        {
            tmp *= 0.5;
            cnt *= 2;
        }
        ans += tmp;
    }
    cout << setprecision(12)<<ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll a,b; cin >> a >> b;
  if(a<9&&b<9){
    cout << "Yay!";
  }
  else{
    cout << ":(";
  }
}
  

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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lld a,b;
  cin>>a>>b;
  if(a==1 || b==1){
    cout<<1<<endl;
    return 0;
  }
  lld ans=(a*b+1);
  ans/=2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc126C
{
    class Program
    {
        static void Main(string[] args)
        {
            string N_K = Console.ReadLine();
            string[] inp = N_K.Split(' ');
            var N = Convert.ToInt32(inp[0]);
            var K = Convert.ToInt32(inp[1]);
            var count = 0;
            double otpt = 0;
            int z = 0;
            for (int i =1;i<=N;i++)
            {
                z = i;
                while (z < K)
                {
                    z = 2 * z;
                    count++;
                }
                otpt = otpt + Math.Pow(0.5, count)/N;
                count = 0;
            }
            Console.WriteLine(Convert.ToString(otpt));
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
n,m = map(int,input().split())
l = []
r = []
low = 0
high = 10 ** 5 + 1
for i in range(m):
    ll,rr = map(int,input().split())
    l.append(ll)
    r.append(rr)
    low = max(low,ll)
    high = min(high,rr)

if high>=low:
    print(high-low+1)
else:
    print(0)


Measured memory_bytes: 11008
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

// https://pyteyon.hatenablog.com/entry/2019/03/11/200000 より
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
	int N, M, K;
	scanf("%d %d %d", &N, &M, &K);
	
	vector<int> Friend[100001];
	vector<int> Block[100001];
	
	UnionFind tree(N+1);
	
	for(int i = 0; i < M; i++){
		int A, B;
		scanf("%d %d", &A, &B);
		Friend[A].push_back(B);
		Friend[B].push_back(A);
		tree.merge(A, B);
	}
	for(int i = 0; i < K; i++){
		int C, D;
		scanf("%d %d", &C, &D);
		Block[C].push_back(D);
		Block[D].push_back(C);
	}
	
	for(int i = 1; i < N+1; i++){
		int ans = tree.size(i) - 1 - Friend[i].size();
		for(int j = 0; j < Block[i].size(); j++){
			if(tree.issame(Block[i][j], i)){
				ans --;
			}
		}
		printf("%d ",ans);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 13432
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;
const long long int MOD=1e9+7;
long long f[1000009], invf[1000009];


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void fanc(long long n){
  f[1] = 1;
  invf[1] = 1;
  for(int i=2;i<=n;i++){
    f[i] = (i*f[i-1])%MOD;
    invf[i] = modinv(f[i], MOD);
  }
}

int main(){
  long long x, y;
  long long s, t;
  cin >> x >> y;
  
  if((2*x-y)%3==0 && (2*y-x)%3==0){
    s = (2*x-y)/3;
    t = (2*y-x)/3;
    if(s<0 || t<0){
      cout << 0 << endl;
    }
    else if(s==0 || t==0){
      cout << 1 << endl;
    }
    else{
      fanc(s+t);
      cout << ((invf[s]*invf[t])%MOD*f[s+t])%MOD << endl;
    }
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 14592
#include <iostream>
#include <algorithm>

using namespace std ;

const int M = 100000;

main(){
  int n, m, s, dp[50][3001];
  while(cin >> n >> m >> s && (n|m|s)){
    fill(dp[0], dp[50], 0);
    dp[0][0] = 1;
    for(int k=1;k<=m;k++){
      for(int i=n*n;i>0;i--){
        for(int j=k;j<=s;j++){
          dp[i][j] = (dp[i][j] + dp[i-1][j-k]) % M;
        }
      }
    }
    cout << dp[n*n][s] << endl;
  }
}

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

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> xs(n), ys(m);
    for (auto& e : xs) cin >> e;
    for (auto& e : ys) cin >> e;

    xs.push_back(x);
    ys.push_back(y);

    if (*max_element(begin(xs), end(xs)) < *min_element(begin(ys), end(ys))) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K, A[201010], B[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];

	rep(k, 0, K) {
		rep(i, 0, N) B[i] = 0;
		rep(i, 0, N) {
			int L = max(0, i - A[i]);
			int R = min(N - 1, i + A[i]);

			B[L]++;
			B[R + 1]--;
		}
		rep(i, 1, N) B[i] += B[i - 1];

		bool same = true;
		rep(i, 0, N) {
			if (A[i] != B[i]) same = false;
			A[i] = B[i];
		}

		if (same) break;
	}

	rep(i, 0, N) {
		if(i) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}







Measured memory_bytes: 5248
#include "bits/stdc++.h"
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	int a[n], b[n], c[n];
	for(int i{}; i<n; i++){
		cin >> a[i] >> b[i] >> c[i];
		}

	int dp[n][3]; // A_B_C
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for(int i{1}; i<n; i++){
		dp[i][0] = a[i]+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i]+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i]+max(dp[i-1][1], dp[i-1][0]);
		}

	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << "\n";



}



Measured memory_bytes: 6004
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]

def gcd(ls):
    ls = [i for i in ls if i > 0]
    while True:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min != 0]
        if len(ls) == 0:
            return _min
        ls.append(_min)

_gcd = gcd(a_ls)
if max(a_ls) >= k and k % _gcd == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 61848
import bisect
from operator import itemgetter
import math
import copy
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(x):
    if visited[x] == False:
        visited[x] = True
        path.append(x)
        if x == N:
            return True
        for i in root[x]:
            if tami(i):
                return True
        else:
            del path[-1]
    return False

def nas(x):
    global cnt
    if (visited[x] == False) and (data[x] == 0):
        visited[x] = True
        cnt += 1
        for i in root[x]:
            nas(i)

N = I()
ab = [IL() for i in range(N-1)]
data = np.array([0]*(N+1))
root = [[]*(N+1) for i in range(N+1)]
visited = [False]*(N+1)

path = []
f = 0
for a,b in ab:
    root[a].append(b)
    root[b].append(a)

tami(1)
middle_No = path[math.ceil(len(path)/2)-1]
data[middle_No] = 1

visited = [False]*(N+1)
cnt = 0
nas(N)

Snuke = cnt
Fennec = N - Snuke

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 128680
n = int(input())
if 100 <= n <= 111:
    print(111)
if 112 <= n <= 222:
    print(222)
if 223 <= n <= 333:
    print(333)
if 334 <= n <= 444:
    print(444)
if 445 <= n <= 555:
    print(555)
if 556 <= n <= 666:
    print(666)
if 667 <= n <= 777:
    print(777)
if 778 <= n <= 888:
    print(888)
if 889 <= n <= 999:
    print(999)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveC();
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			sum += val;
			list.add(val);
		}
		if (sum % 10 != 0) {
			System.out.println(sum);
		} else {
			Collections.sort(list);
			for (int val : list) {
				if (val % 10 != 0) {
					System.out.println(sum - val);
					return;
				}
			}
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<map>
#include<tuple>
#include<string>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV 1000000007
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m; x=x*x%m;n>>=1;}return r%m;}
using namespace std;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  s = "0" + s + "0";
  int dp[500005] = {};
  for(int i = 1; i < (int)s.size() - 1; i++){
    dp[i+1] = max(dp[i+1],dp[i]);
    //SHOW(i,dp[i]);
    if(s[i-1] == '1' && s[i] == '0' && s[i+1] == '1'){
      int j = i-1;
      while(s[j] != '0'){
        dp[i+1] = max(dp[i+1],dp[j-1] + i - j);
        j--;
      }
      j = i+1;
      while(s[j] != '0'){
        dp[j] = max(dp[j],dp[i-2] + j - i);
        j++;
      }
    }
  }
  cout << dp[n+1] << endl;
}

Measured memory_bytes: 2840
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
using namespace std;

void tplus(int t[]) {
	if (t[9] == 2) {
		for (int i = 0; i < 10; i++) {
			t[i] = 0;
		}
	}
	else {
		t[0]++;
		for (int i = 0; i < 10; i++) {
	
			if (t[i] == 2) {
				t[i + 1]++;
				t[i] = 0;
			}
			
		}
	}
	if (t[9] == 2) {
		for (int i = 0; i < 10; i++) {
			t[i] = 0;
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	int k[10];
	int s[10][10];
	int p[10];
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	int t[10];
	
	for (int i = 0; i < 10; i++) {
		t[i] = 0;
	}
	int ans = 0;
	
	for (int i = 0; i < pow(2, n); i++) {
		
		int light = 1;
		
		for (int j = 0; j < m; j++) {
			
			int pre;
			int hoge = 0;
			for (int r = 0; r < k[j]; r++) {
				if (t[s[j][r]-1] == 1) {
					hoge++;
				}
			}
			if (hoge % 2 == p[j]) pre = 1;
			else pre = 0;
			int u;
			u = light * pre;
			light = u;
			
		}
		if (light == 1) ans++;
		tplus(t);
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main(){
	long long a[1001],m,n,an=0,su=0,i;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{cin>>a[i];su+=a[i];}
	while(i--)
	{
		if(a[i]*4*m>=su)
		an++;
	}
	cout<<(an>=m?"Yes":"No");
	return 0;
}

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

using namespace std;

string s;
char dpn;
int n, a, b, ans;

int main() {
  cin >> s;
  s = '2' + s + '2';
  n = s.size();
  dpn = s[(n - 1) / 2];
  
  for(int i = (n - 1) / 2 - 1; i >= 0; i--) {
    if(s[i] != dpn) {
      a = i + 1;
      break;
    }
  }
  for(int i = (n + 1) / 2; i < n; i++) {
    if(s[i] != dpn) {
      b = i - 1;
      break;
    }
  }
  ans = min(n - a - 1, b);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  vector<int> V(N);
  for (int i=0; i<N; ++i) {
    cin >> vec.at(i);
  }
  for (int j=0; j<N; ++j) {
    int a = vec.at(j)-1;
    V.at(a) = j+1;
  }
  for (int k=0; k<N; ++k) {
    cout << V.at(k) << endl;
  }
}

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

using namespace std;

const int N = 1e6 + 6;

char s[N];

int dp[N], to[N];
int last[N][26];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < 26; i++)
    last[n][i] = n;
  dp[n] = 1;
  for (int i = n-1; i >= 0; i--) {
    int now = s[i] - 'a';
    to[i] = 0;
    for (int j = 0; j < 26; j++) {
      last[i][j] = last[i+1][j];
      if (dp[last[i][j]] < dp[last[i][to[i]]])
        to[i] = j;
    }
    dp[i] = dp[last[i][to[i]]] + 1;
    last[i][now] = i;
  }
  int ans = 0, cur = 0;
  for (int i = 0; i < 26; i++) {
    if (dp[last[0][i]] < dp[last[0][ans]])
      ans = i;
  }
  cur = last[0][ans];
  while (cur < n) {
    printf("%c", ans + 'a');
    ans = to[cur];
    cur = last[cur+1][ans];
  }
  printf("%c\n", ans + 'a');
  return 0;
}

Measured memory_bytes: 24960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;cin>>k;
  vector<lvector> v;
  set<ll> st;for(ll i=1;i<10;++i) st.insert(i);
  v.emplace_back(lvector{1,2,3,4,5,6,7,8,9});
  for(ll dig=1;dig<10;dig++) {
    lvector tmp;
    for(ll i:v[dig-1]) {
      ll res=i%10;
      if(res==0) {
        tmp.emplace_back(i*10);st.insert(i*10);
        tmp.emplace_back(i*10+1);st.insert(i*10+1);
      }
      else if(res==9) {
        tmp.emplace_back(i*10+8);st.insert(i*10+8);
        tmp.emplace_back(i*10+9);st.insert(i*10+9);
      }
      else {
        tmp.emplace_back(i*10+res-1);st.insert(i*10+res-1);
        tmp.emplace_back(i*10+res);st.insert(i*10+res);
        tmp.emplace_back(i*10+res+1);st.insert(i*10+res+1);
      }
    }
    v.emplace_back(tmp);
  }
  ll val=0,ans;
  for(ll i:st) {
    val+=1;
    if(val==k) {
      ans=i;
      break;
    }
  }
  print(ans);
  return 0;
}

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

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

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

    void solve(){

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

        if((n == 1 && m == 2) || (n == 2 && m == 1)) System.out.println(3);
        else if((n == 1 && m == 3) || (n == 3 && m == 1)) System.out.println(2);
        else System.out.println(1);

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


Measured memory_bytes: 22612
//#pragma GCC optimize("O2")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
const int maxn = 2e2 + 55;
const int mod = 1e9 + 7;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	vi x;
	cin >> n >> k;
	x.resize(n);
	for(auto &i : x) cin >> i;
	sort(all(x));
	ll ans = 0;
	for(int i = 0; i+k < n; i++)
		ans += x[i];
	cout << ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
  int N,K,L; cin>>N>>K>>L;
  UnionFind tree(N);
  vector<int>p(K);vector<int>q(K);
  for(int i=0;i<K;i++){
    cin>>p[i]>>q[i];
    tree.unite(p[i]-1,q[i]-1);
  }
  UnionFind TREE(N);
  vector<int>r(L);vector<int>s(L);
  for(int i=0;i<L;i++){
    cin>>r[i]>>s[i];
    TREE.unite(r[i]-1,s[i]-1);
  }
  map<pair<int,int>,int>A;
  for(int i=0;i<N;i++){
    A[make_pair(tree.root(i),TREE.root(i))]++;
  }
  for(int i=0;i<N;i++){
    cout<<A[make_pair(tree.root(i),TREE.root(i))];
    if(i!=N)cout<<" ";
    else cout<<endl;
  }
}

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

int main() {
    int a,b,c,tmp,count=0;
    cin>>a>>b>>c;
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    if(a>b) swap(a,b);
    count = (c-a)/2 + (c-b)/2;
    if((c-a)%2 & (c-b)%2) {
        count++;
    } else if((c-a)%2 | (c-b)%2) {
        count+=2;
    }
    cout << count << endl;
}

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

/*
N+sum(B)個ののカードをソートして大きいものN個をとる
*/

void solve(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> v;
    rep(i,n){
        int a;
        cin >> a;
        v.emplace_back(make_pair(-a,1));
    }
    rep(i,m){
        int b,c;
        cin >> b >> c;
        v.emplace_back(make_pair(-c,b));
    }
    sort(v.begin(), v.end());
    ll number = 0;
    ll sum=0;
    ll i=0;
    while(number < n){
        ll f = -v[i].first;
        ll s = v[i].second;
        //cout << "f:" << f << " s:" << s << endl;
        /*
        nとnumberとの差がfより大きければ全部足す
        そうでなければ
        */
        sum += min(n-number,s) * f;
        number += s;
        i++;
    }
    cout << sum << endl;
}

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

Measured memory_bytes: 2420
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n,m = map(int,input().split())

s1=input()

s2=input()

len_moji = lcm(n,m)

len_s1 = []

len_s2 = []

for i in range(n):
    len_s1.append(i*len_moji//n+1)

for i in range(m):
    len_s2.append(i*len_moji//m+1)
#print(len_s1)
#print(len_s2)
count = 0
for ix, vs1 in enumerate(len_s1):
    for jx in range(count,len(len_s2)):
        #print(vs1, len_s2[jx])
        if vs1 < len_s2[jx]:
            count = jx-1
            break
        if vs1 == len_s2[jx]:
            count = jx
            if s1[ix] != s2[jx]:
                print(-1)
                exit()
            break
print(len_moji)

Measured memory_bytes: 72380
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  int n,m;
  cin>>n>>m;
  std::vector<int> like[310];
  for(int i=0;i<n;i++){
    like[i].resize(m+1);
    for(int j=m;j>=1;j--){
      int a;
      cin>>a;
      like[i][a]=j;
    }

  }

  int result=n;
  bool omitted[310]={};
  for(int i=1;i<=m;i++){
    int contestants[310]={};
    for(int j=0;j<n;j++){
      const std::vector<int>& person=like[j];
      int join_id=-1;
      int max_like=0;
      for(int k=1;k<=m;k++){
        if(!omitted[k]){
          if(max_like<person[k]){
            max_like=person[k];
            join_id=k;
          }
        }
      }
      if(join_id==-1){
        cout<<result<<endl;
        return 0;
      }
      contestants[join_id]++;
    }

    int max_contestants=0;
    std::vector<int> omit_id;
    for(int j=1;j<=m;j++){
      if(max_contestants<contestants[j]){
        omit_id.clear();
        omit_id.push_back(j);
        max_contestants=contestants[j];

      }else if(max_contestants==contestants[j]){
        omit_id.push_back(j);
      }
    }
    if(max_contestants>0){
      result=std::min(max_contestants,result);
    }

    for(auto o:omit_id){
      omitted[o]=true;
    }
  }
  cout<<result<<endl;


  
  return 0;
}


Measured memory_bytes: 640
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll MAX = 2e5+10;
vector<ll> d(MAX,-1);
ll solve(ll n){
  if(n==0) return d[n] = 0;
  if(d[n]!=-1) return d[n];
  ll res = 0,cnt = 0,cn=n;
  while(n!=0){
    cnt += n%2;
    n /= 2;
  }
  res = solve(cn%cnt);
  return d[cn] = res + 1;
}
signed main(){
  init_io();
  ll n,btc=0,v0,v1,a0=0,a1=0;
  string s;
  cin >> n >> s;
  for(auto c:s){
    if(c=='1') btc++;
  }
  if(btc==1){
    if(s.back()=='1'){
      for(int i=0;i<n-1;++i)cout<< 2 <<endl;
      cout<< 0 <<endl;
    }else{
      for(int i=0;i<n-1;++i){
        if(s[i]=='1')cout<< 0 <<endl;
        else cout<< 1 <<endl;
      }
      cout<< 2 <<endl;
    }
    return 0;
  }
  v0=1,v1=1;
  for(int i=n-1;i>=0;i--){
    a0 += v0*(s[i]=='1');
    a1 += v1*(s[i]=='1');
    v0 *= 2;
    v1 *= 2;
    a0 %= btc+1;
    a1 %= btc-1;
    v0 %= btc+1;
    v1 %= btc-1;
  }
  v0=1,v1=1;
  vector<ll> ans(n);
  for(int i=n-1;i>=0;i--){
    if(s[i]=='0'){
      ll t = (a0+v0)%(btc+1);
      ans[i] = solve(t);
    }else{
      ll t = (a1-v1+(btc-1)*4)%(btc-1);
      ans[i] = solve(t);
    }
    v0 *= 2;
    v1 *= 2;
    v0 %= btc+1;
    v1 %= btc-1;
  }
  for(int i=0;i<n;i++){
    cout << ans[i]+1 << endl;
  }
}


Measured memory_bytes: 6752
using System;
using System.Collections.Generic;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                var chars = Console.ReadLine().ToCharArray();
                var q = new Queue<char>(chars);
                if (chars[0] == '-') break;
                var m = int.Parse(Console.ReadLine());
                for (int i = 0; i < m; i++)
                {
                    var h = int.Parse(Console.ReadLine());
                    for (int j = 0; j < h; j++)
                    {
                        var temp = q.Dequeue();
                        q.Enqueue(temp);
                    }
                }

                foreach (var item in q)
                {
                    Console.Write(item);
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define INF 3000
using namespace std;

int H, W;
vector<vector<char>> A(1000, vector<char>(1000));
vector<vector<int>> B(1000, vector<int>(1000, INF));

void dfs(int x, int y) {
    if (y + 1 < W && B[x][y] + 1 < B[x][y + 1]) {
        B[x][y + 1] = B[x][y] + 1;
        dfs(x, y + 1);
    }
    if (0 <= y - 1 && B[x][y] + 1 < B[x][y - 1]) {
        B[x][y - 1] = B[x][y] + 1;
        dfs(x, y - 1);
    }
}

void dfs_down(int x, int y) {
    if (x + 1 < H && B[x][y] + 1 < B[x + 1][y]) {
        B[x + 1][y] = B[x][y] + 1;
        dfs_down(x + 1, y);
    }
}

void dfs_up(int x, int y) {
    if (0 <= x - 1 && B[x][y] + 1 < B[x - 1][y]) {
        B[x - 1][y] = B[x][y] + 1;
        dfs(x - 1, y);
    }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
            if (A[i][j] == '#') B[i][j] = 0;
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (B[i][j] != INF) {
                dfs(i, j);
                dfs_down(i, j);
            }
        }
    }

    for (int i = H - 1; i >= 0; i--) {
        for (int j = W - 1; j >= 0; j--) {
            dfs_up(i, j);
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, B[i][j]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 7296
// Aizu Vol-1 0114: Electro-Flyt
// 2017.8.23 bal4u@uu
// ??????????????±??????????¢??°?????????????????£?????????????±??????????????????????????????????

#include <stdio.h>

long long gcd(long long a, long long b) { long long r; while (b != 0) r = a % b, a = b, b = r; return a; }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }

int carmichael(int a, int m)
{
    int n;
	long long b;
	for (n = 1, b = a; b != 1; n++) b = (b * a) % m;
	return n;
}

int main()
{
	int i;
	int a[3], m[3];
	long long b[3];

	while (1) {
		for (i = 0; i < 3; i++) {
			scanf("%d%d", a + i, m + i);
			if (!a[0]) return 0;
		}
		for (i = 0; i < 3; i++)	b[i] = carmichael(a[i], m[i]);
		printf("%lld\n", lcm(lcm(b[0], b[1]), b[2]));
	}
	return 0;
}

Measured memory_bytes: 600
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]

dp = [[0 for _ in range(n)] for _ in range(n)]
INF = 10**18
for i in range(n):
    for j in range(n):
        if i!=j:
            dp[i][j] = INF
for a,b,t in l:
    dp[a-1][b-1] = t
    dp[b-1][a-1] = t
#print(dp)

#最短リスト
for c in range(n):
    for f in range(n):
        for la in range(n):
            dp[f][la] = min(dp[f][la] , dp[f][c] +  dp[c][la])

#各辺が何かしらの最短ルートに含まれているか
ans = 0
for a, b, t in l:
    cou = 0
    for j in range(n):
        for k in range(n):
            #jからkの最短ルートにa,bが入ってるいるか
            if dp[j][k] != dp[j][a-1] + t + dp[b-1][k]:
                cou += 1
    if cou==n**2:
        ans += 1

print(ans)


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

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define For(i, a) for (int i=0; i<a; i++)
#define FORR(i,a,b) for (int i = a; i >= b; i--)
#define Forr(i,a) for (int i = a; i >= 0; i--)

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args)
{cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }

void solve(){
  int x; cin >> x;
  if(x==0)cout << 1 << "\n";
  else cout << 0 << "\n";

}


int32_t main(){
  ios_base:: sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  for(int tt=1;tt<=t;tt++){
    solve();
  }
}

Measured memory_bytes: 3608
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    s = input()
    if not s[2] == s[3]:
        print(no)
        exit()
    if not s[4] == s[5]:
        print(no)
        exit()
    print(yes)




main()





Measured memory_bytes: 5716
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {
  ll n;
  ccin >> n;
  string s;
  ccin >> s;
  ll m = 1;
  rep(i, n) {
    m *= 2;
  }
  vector<map<string, ll>> vmp(n + 1);
  rep(i, m) {
    ll jk = 1;
    string sr = "";
    string sb = "";
    rep(j, n) {
      if (i & jk) {
        sr.push_back(s[j]);
      } else {
        sb.push_back(s[j]);
      }
      jk *= 2;
    }
    reverse(all(sb));
    string ss = sr;
    ss.append(sb);
    ++vmp[sr.size()][ss];
  }
  vector<map<string, ll>> vmp2(n + 1);
  rep(i, m) {
    ll jk = 1;
    string sr = "";
    string sb = "";
    rep(j, n) {
      if (i & jk) {
        sr.push_back(s[n + j]);
      } else {
        sb.push_back(s[n + j]);
      }
      jk *= 2;
    }
    reverse(all(sb));
    string ss = sb;
    ss.append(sr);
    ++vmp2[sb.size()][ss];
  }
  ll ans = 0;
  rep(i, n + 1) {
    for (const auto &j :vmp[i]) {
      ans += j.second * vmp2[i][j.first];
    }
  }

  ccout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 84608
#include <stdio.h>

int main()
{
  int x, y, r, d;
  
  scanf("%d%d", &x, &y);
  
  if(x < y){
    d = x;
    x = y;
    y = d;
  }

  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  printf("%d\n", x);
  
  return 0;
}

Measured memory_bytes: 592
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code)]

use std::collections::{HashMap, BinaryHeap, BTreeMap};

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($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<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (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")
    };
}

// 可愛い可愛い、お手製のライブラリ達
macro_rules! p {
    ($t:expr) => {
        println!("{}", $t);
    };
}
macro_rules! debug {
    ($t:expr) => {
        println!("{:?}", $t);
    };
}
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    gcd(b, a % b)
}
fn lcm(a:usize, b:usize) -> usize {
    a / gcd(a, b) * b
}

// エントリーポイント
fn main() {
    input! {
        A:usize,
        B:usize,
    }

    let acc_xor = |n| if (n - 1) / 2 % 2 == 0 {1} else {0} + if n % 2 == 0 {n} else {0};
    let xor_left = acc_xor(A - 1);
    let xor_right = acc_xor(B);
    println!("{}", xor_left ^ xor_right);
}


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


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

  ll n,d;
  cin >> n >> d;
  ll ans=0;
  rep(i,n){
    ll x,y;
    cin >> x >> y;
    
    ll dist = x*x + y*y;
    if(dist <= d*d) ans++;
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int MAXV = 1e5 + 5;
const int MAXM = 1 << 9;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int a[MAXM][MAXV];
int n, m, r, q, v[MAXN], w[MAXN];
int query(int x, int y) {
	if (x <= m) return a[x][y];
	else {
		int ans = query(x / 2, y);
		if (y >= w[x]) chkmax(ans, v[x] + query(x / 2, y - w[x]));
		return ans;
	}
}
int main() {
	read(n), m = (1 << 9) - 1, r = 1e5;
	for (int i = 1; i <= n; i++)
		read(v[i]), read(w[i]);
	for (int i = 1; i <= m; i++) {
		int f = i / 2;
		for (int j = 1; j <= r; j++) {
			a[i][j] = a[f][j];
			if (j >= w[i]) chkmax(a[i][j], v[i] + a[f][j - w[i]]);
		}
	}
	read(q);
	for (int i = 1; i <= q; i++) {
		int x, y; read(x), read(y);
		printf("%d\n", query(x, y));
	}
	return 0;
}


Measured memory_bytes: 205432
n=int(input())
a_dict={}
for i in range(n):
    a=input()
    if a not in a_dict:
        a_dict[a]=0
    else:
        a_dict[a]+=1
k=max(a_dict.values())
moji=[i for i,j in a_dict.items() if j==k ]
# moji=[]
# j=max(a_dict.values())
# for i,k in a_dict.items():
#     if k==j:
#         moji.append(i)
moji=sorted(moji)
for i in moji:
    print(i)

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

using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll n, cap;
ll b[N], ra[N][2];
int p[N];


bool check(ll spent) {
    ll whole = spent / cap;
    ll sum = 0;
    for(int j = 1; j <= n; j++) {
        int i = p[j];
        if (j <= whole) sum += ra[i][1] * (cap - b[i]);
        else sum -= ra[i][0] * b[i];
    }
    ll rem = spent % cap;
    if (rem == 0) return sum >= 0;
    
    for(int j = 1; j <= n; j++) {
        ll nSum = sum;
        int i = p[j];
        if (j <= whole) {
            int sub = p[whole + 1];
            nSum += -ra[i][1] * (cap - b[i]) 
                + ra[sub][1] * (cap - b[sub]) + ra[sub][0] * b[sub];
        } else nSum += ra[i][0] * b[i];
        nSum += max(ra[i][0] * (rem - b[i]), ra[i][1] * (rem - b[i]));
        if (nSum >= 0) return 1;
    }
    return 0;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> cap;
    for(int i = 1; i <= n; i++) {
        cin >> b[i] >> ra[i][0] >> ra[i][1];
    }
    for(int i = 1; i <= n; i++) p[i] = i;
    sort(p + 1, p + n + 1, [&](int p1, int p2){
        ll w1 = (cap - b[p1]) * ra[p1][1] + b[p1] * ra[p1][0];
        ll w2 = (cap - b[p2]) * ra[p2][1] + b[p2] * ra[p2][0];
        return w1 > w2;
    });
    //for(int i = 1; i <= n; i++) cout << p[i] << " \n"[i == n];
    ll L = 0, R = 0;
    for(int i = 1; i <= n; i++) R += b[i];
    while (L <= R) {
        ll mid = (L + R) / 2;
        if (check(mid)) R = mid - 1;
        else L = mid + 1;
    }
    cout << L;
}


Measured memory_bytes: 2944
N = int(input())
x = []
u = []
ans = 0
for i in range(0,N):
  s = input().split()
  x.append(float(s[0]))
  u.append(str(s[1]))
for i in range(0,N):
  if u[i] == 'BTC':
    ans = ans + x[i] * 380000.0
  else:
    ans = ans + x[i]
print (ans)

Measured memory_bytes: 3064