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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

void gaussJordan(vll &A, ll size) {
	int s = 0;
	for (ll b = size-1; b >= 0; b--) {
		//探す
		ll pos = -1;
		for (int i = s; i < A.size(); i++) {
			if ((A[i]>>b) & 1) { pos = i; break; }
		}
		if (pos == -1) continue;
		if (pos != s) swap(A[pos], A[s]);
		//消す
		for (int i = 0; i < A.size(); i++) {
			if (i != s && ((A[i]>>b) & 1)) A[i] ^= A[s];
		}
		s++;
	}
}

void Main() {
	ll N; cin >> N;
	vll A(N); cin >> A;
	ll xd = 0;
	ll size = 60;
	ll ans = 0;
	for (auto &v : A) xd ^= v;

	for (int i = 0; i < size; i++) {
		if ((xd>>i) & 1) {
			ans += (1ll<<i);
			for (auto &v : A) v &= (~(1ll<<i));
		}
	}
	gaussJordan(A, size);
	
	ll xd2 = 0;
	for (auto &v : A) xd2 ^= v;
	cout << ans + xd2 * 2 << endl;	
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <utility>
#include <tuple>

using namespace std;
typedef long long ll;

int main()
{
    ll n, a;
    cin >> n >> a;
    vector<ll> x(n+1, 0);
    ll max_value = a;
    for (int i=1; i<=n; ++i){
        cin >> x[i];
        max_value = max(max_value, x[i]);
    }
    ll dp[n+1][n+1][max_value * n + 1];
    for (int i=0; i<=n; ++i){
        for (int j=0; j<=n; ++j){
            for (int k=0; k<=max_value * n; ++k){
                dp[i][j][k] = (i == 0 && j == 0 && k == 0) ? 1 : 0;
            }
        }
    }
    for (int i=0; i<=n; ++i){
        for (int j=0; j<=n; ++j){
            for (int k=0; k<=max_value * n; ++k){
                if(i >= 1 && k - x[i] >= 0){
                    dp[i][j][k] = dp[i-1][j-1][k-x[i]] + dp[i-1][j][k];
                }
                else if(i >= 1){
                    dp[i][j][k] = dp[i-1][j][k];
                }
            }
        }
    }
    ll ans = 0;
    for (int i=1; i<=n; ++i){
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int Max = 1e9+7;

bool done[3333][3333];
double dp[3333][3333];
double h[3333];

double f(int turn, int heads) {
    //  f(turn, heads) = f(turn -1 , heads - 1) * head[turn] +
    //  f(turn-1, heads) * tail[turn]

    if (turn == 0) {
        if (heads == -1) {
            // cout<<"ret: "<<(1.0f - h[turn])<<endl;
            return (1.0f - h[turn]);
        }
        if (heads == 0) {
            // cout<<"ret: "<<h[turn]<<endl;
            return h[turn];
        }
        // cout<<"ret: "<<"0"<<endl;
        return 0.0f;
    }

    if (done[turn][heads] == true) {
        return dp[turn][heads];
    }
    done[turn][heads] = true;

    double ans = 0.0f;
    ans = f(turn -1 , heads -1) * h[turn];
    // if (turn == 1 && heads == 1) {
    //     cout<<f(turn-1, heads-1)<<" and "<<h[turn]<<endl;
    // }
    ans += f(turn-1, heads) * (1.0f - h[turn]);
    // if (turn == 1 && heads == 1) {
    //     cout<<f(turn-1, heads)<<" and "<<(1.0f - h[turn])<<endl;
    // }
    dp[turn][heads] = ans;
    return ans;
}

int main(void) {
    int n;
    cin>>n;
    for(int i = 0; i < n; ++i)
        cin>>h[i];
    double ans = 0.0f;
    memset(done, 0, sizeof(done));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= i; ++j) {
            f(i, j);
            int turn = i+1;
            int heads = j+1;
            if ((heads > (turn-heads)) && i == n-1) {
                ans += f(i, j);
            }
            // cout<<dp[i][j]<<' ';
        }
        // cout<<endl;
    }
    cout<<fixed;
    cout<<setprecision(10);
    cout<<ans;
    return 0;
}



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

int main(){
    int N;cin>>N;
    vector<int> V(N,0);
    vector<int> C(N,0);
    rep(i,N)cin>>V[i];
    rep(i,N)cin>>C[i];
    int ans=0;
    rep(i,N){
        if(V[i]>C[i])ans+=V[i]-C[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
int main(void)
{
	fastio
	ll x;
	cin >> x;
	ll ans = (x/500)*1000;
	x -= (x/500)*500;
	ans += (x/5)*5;
	cout<<ans<<"\n";
	return 0;
}

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

int main(){
	float x1, y1, x2, y2, xp, yp;
	double x0, y0, x, y, _x, _y, a, b;
	while(scanf("%f,%f,%f,%f,%f,%f", &x1, &y1, &x2, &y2, &xp, &yp) != EOF){
		double angle = atan2(y2 - y1, x2 - x1);
		
		if(angle > M_PI/2) angle -= M_PI;
		if(angle < -M_PI/2) angle += M_PI;
		
		x0 = (y1 == y2 ? 0 : x1 - y1 * (x2-x1) / (y2-y1));
		y0 = (x0 != 0 || x1 == x2 ? 0 : y1 - x1 * (y2-y1) / (x2-x1));
		
		x = xp - x0;
		y = yp - y0;
		
		a = cos(angle) * cos(angle) - sin(angle) * sin(angle);
		b = 2 * sin(angle) * cos(angle);
		
		_x = a * x + b * y + x0;
		_y = b * x - a * y + y0;
		
		cout << fixed <<  setprecision(6) << _x << " " << _y << endl;
	}
	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll R = 1e6+69;
ll n,t[R],ans;
int main()
{
	scanf("%lld", &n);
	for(int i=0;i<n;++i) scanf("%lld", &t[i]);
	sort(t,t+n);
	reverse(t,t+n);
	for(int i=1;i<n;++i)
	{
		//  printf("%lld\n", ans);
		ans+=t[(i/2)];
		//  printf("now: t[i/2]:%lld, for i=%d\n", t[(i/2)], i);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5368
#--Trick or Treat
import itertools

N, K = map(int, input().split())

A = []
judge = list(range(1,N+1))
for i in range(K):
  d = int(input())
  A.append([int(i) for i in input().split()])

allocate = list(itertools.chain.from_iterable(A))
#print(judge)
#for i in range(1,K):

l1_l2_sym_diff = []
l1_l2_sym_diff = set(allocate) ^ set(judge)
print(len(l1_l2_sym_diff))



Measured memory_bytes: 9240
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
 
countMod0Num :: Int -> [Int] -> Int
countMod0Num n = length . filter ((==) 0) . map (flip mod n)

canSolveN :: Int -> Int -> Int -> Bool
canSolveN num4 num2 numOther
    | numOther == 0 = True
    | numOther <= num4 = True
    | (numOther + num2) <= (num4 + 1) = True
    | numOther <= (num4 + 1) && (num2 `mod` 2) == 0 = True
    | otherwise = False
    where
        num4Remain = num4 - numOther

canSolve :: [Int] -> Bool
canSolve arr = canSolveN num4 num2 numOther
    where
        num4 = countMod0Num 4 arr
        num2 = (countMod0Num 2 arr) - num4
        numOther = (length arr) - num2 - num4

toYesNo :: Bool -> String
toYesNo True = "Yes"
toYesNo False = "No"

solve :: [Int] -> String
solve = toYesNo . canSolve

main :: IO()
main = do
    n <- B.getLine
    a <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    putStrLn $ solve a 

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

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private void solve(Scanner sc, PrintWriter out) {
    int H = sc.nextInt();
    int W = sc.nextInt();
    sc.nextLine();
    for (int i = 0; i < H; ++i) {
      String C = sc.nextLine();

      for (int ct = 0; ct < 2; ++ct) {
        out.println(C);
      }
    }
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 10452
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans;
    char a;
    ll bit=0;
    bool flag=true;
    while(cin>>a){
        if ((bit & (1<<(a-'a')))==(1<<(a-'a'))){
            flag=false;
            break;
        }
        bit|=(1<<(a-'a'));
    }

    {
        if(flag)cout <<"yes"<<endl;
        else cout <<"no"<<endl;
    }


    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return w*ret;
}
long long t1,t2,a1,a2,b1,b2;
long long tot1,tot2;
int main()
{
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	a1*=t1,a2*=t2;
	b1*=t1,b2*=t2;
	if((a1<b1&&a2<b2)||(a1>b1&&a2>b2))
	{
		cout<<0<<endl;
		return 0;
	}
	if(a1+a2==b1+b2)
	{
		cout<<"infinity"<<endl;
		return 0;
	}
	tot1=a1+a2,tot2=b1+b2;
	if((tot1<tot2&&a1<b1)||(tot1>tot2&&a1>b1))
	{
		cout<<0<<endl;
		return 0;
	}
	if(tot2<tot1) swap(a1,b1),swap(tot1,tot2);
	if((a1-b1)%(tot2-tot1)==0) cout<<(a1-b1)/(tot2-tot1)*2<<endl;
	else cout<<((a1-b1)/(tot2-tot1)+1)*2-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int MAXN = 10005;
const int NIL = -1;
struct Node{int l, r, p;};
Node T[MAXN];
int H[MAXN];
int D[MAXN];

void SetDepth(int u, int h)
{
	D[u] = h;
	if(T[u].l != NIL) SetDepth(T[u].l, h+1);
	if(T[u].r != NIL) SetDepth(T[u].r, h+1);
}

int SetHeight(int H[], int u)
{
	int h1, h2;
	h1 = h2 = 0;
	if(T[u].l != NIL) h1 = SetHeight(H, T[u].l) + 1;
	if(T[u].r != NIL) h2 = SetHeight(H, T[u].r) + 1;
	return H[u] = max(h1, h2);
}

int Getsibling(int u)
{
	if(T[u].p == NIL) return NIL;
	if(T[T[u].p].l != u) return T[T[u].p].l;
	else return T[T[u].p].r;		
}

void print(int u)
{
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].p);
	printf("sibling = %d, ",Getsibling(u));
	int deg = 0;
	if(T[u].l != NIL) deg++;
	if(T[u].r != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);
	
	if(T[u].p == NIL) printf("root\n");
	else if(deg == 0) printf("leaf\n");
	else printf("internal node\n") ;
}


int main ()
{
	int n, u, l, r, root;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		T[i].r = T[i].l = T[i].p = NIL;
	}

	for(int i = 0; i < n; i++)
	{
		cin >> u >> l >> r;
		T[u].l = l;
		T[u].r = r;
		if(T[u].l != NIL) T[l].p = u;
		if(T[u].r != NIL) T[r].p = u; 
	}
	
	for(int i = 0; i < n; i++)
	{
		if(T[i].p == NIL)
			root = i;
	}
	SetHeight(H, root);
	SetDepth(root, 0); 
	for(int i = 0; i < n; i++)
	{
		print(i);
	}
	return 0; 
} 


Measured memory_bytes: 3168
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>
#include<set>


using namespace std;

int main(){

	int x[500]={};
	x[1]=380;
	x[2]=380;
	for(int i=1;i<60;i++){
		x[i+2]=x[i]+380;
	}
	
	
	
	x[3]=550;x[5]=850;
	int RR=380*5*0.8;
	x[10]=RR;
	RR=550*4*0.85;
	x[12]=RR;
	RR=850*3*0.88;
	x[15]=RR;
	for(int i=2;i<60;i++){
		if(x[i+2]>x[i]+380)x[i+2]=x[i]+380;
		if(x[i+3]>x[i]+550)x[i+3]=x[i]+550;
		if(x[i+5]>x[i]+850)x[i+5]=x[i]+850;

		int R=380*5*0.8;
		if(x[i+10]>x[i]+R)x[i+10]=x[i]+R;
		R=550*4*0.85;
		if(x[i+12]>x[i]+R)x[i+12]=x[i]+R;
		R=850*3*0.88;
		if(x[i+15]>x[i]+R)x[i+15]=x[i]+R;
	}

	


	int n;
	double S=0;
	while(1){
		S=0;
		cin>>n;if(!n)return 0;
		/*
		while(n>0){
			if(n>=1500){
				n-=1500;S+=850*3*0.88;
			}
			else if(n>=1200){
				n-=1200;S+=550*4*0.85;
			}
			else if(n>=1000){
				n-=1000;S+=380*5*0.8;
			}
			else if(n>=500){
				n-=500;S+=850;
			}
			else if(n>=400){
				n-=400;S+=380;
			}
			else if(n>=300){
				n-=300;S+=550;
			}
			else {
				n-=200;S+=380;
			}
			cout<<n;
		}
		*/
		n/=100;
		cout<<x[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
e=enumerate
n,a=open(0)
d=[0]+[-1e18]*2001
for j,(a,i)in e(sorted((-int(a),i)for i,a in e(a.split()))):d=[max(t-a*abs(~i-j+k+int(n)),d[k-1]-a*abs(~i+k))for k,t in e(d)]
print(max(d))

Measured memory_bytes: 78052
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,d=n1()
X=n3(n)
ans=0

for i in range(n):
    for j in range(i+1,n):
        line1,line2=X[i],X[j]
        c=0
        for x,y in zip(line1,line2):
            c+=(x-y)**2
        if (math.sqrt(c)).is_integer():
            ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int Y = scanner.nextInt();

        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= N; j++) {
                int k = N - i - j;
                if (k >= 0) {
                    int sum = 10000 * i + 5000 * j + 1000 * k;
                    if (sum == Y) {
                        System.out.print(String.format("%d %d %d", i, j, k));
                        return;
                    }
                }
            }
        }
        System.out.print(String.format("%d %d %d", -1, -1, -1));
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  int x,y;
  int ans=0;
  for(int i=0;;i++){
    if(a[2]-a[0]<=1){
      x=a[2]-a[0];break;
    }
    a[0]+=2;
    ans++;
  }
  for(int i=0;;i++){
    if(a[2]-a[1]<=1){
      y=a[2]-a[1];break;
    }
    a[1]+=2;
    ans++;
  }
  if(x+y==1)ans+=2;
  if(x==1&&y==1)ans++;
  cout<<ans<<endl;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;

    constexpr unsigned long mx = 1000001;
    vector<vector<unsigned long>> fact(mx, {1});
    for(unsigned long i = 2; i < mx; ++i)for(unsigned long j = i; j < mx; j += i)fact[j].push_back(i);

    vector<unsigned long> coef(mx, 1);
    for(unsigned long i = 2; i < mx; ++i)coef[i] = coef[MOD % i] * (MOD - MOD / i) % MOD;

    vector<unsigned long> sieve(mx, 1);
    for(unsigned long i = 2; i < mx; ++i)if(sieve[i])for(unsigned long j = i; j < mx; j += i){
        sieve[j] = 0;
        (coef[j] *= MOD + 1 - i) %= MOD;
    }

    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    copy_n(istream_iterator<unsigned long>(cin), N, A.begin());

    unsigned long ans{0};
    vector<unsigned long> hoge(mx);
    for(const auto& i : A)for(const auto& j : fact[i]){
        (ans += coef[j] * (hoge[j] * i % MOD)) %= MOD;
        hoge[j] += i;
        if(hoge[j] >= MOD)hoge[j] -= MOD;
    }

    ans %= MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 205952
//**************************
//*** writer  :  Alan Hu **
//************************
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<cmath>

using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
     
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int maxn=1e5+10;

int n,m,tp,cnt[maxn];
bool vis[maxn];

vi v[maxn];

void dfs(int x)
{
    rept(i,0,v[x].size())
    {
        int to=v[x][i];
        if (vis[to]) continue;
        vis[to]=true;
		cnt[++tp]=to;
        dfs(to);
		return;
    }
}

int main()
{
    cin>>n>>m;
    while (m--)
    {
        int x,y;
		cin>>x>>y;
        v[x].pb(y);
		v[y].pb(x);
    }
    tp=1;
    cnt[1]=1;
	vis[1]=true;
	dfs(1);
    reverse(cnt+1,cnt+tp+1);
	dfs(1);
	cout<<tp<<endl;
    rept(i,1,tp) cout<<cnt[i]<<" "; 
	cout<<cnt[tp]<<endl;
    return 0;
}

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

int main() {
  int n, k, a, b, c, d, e, f, g, h, i, z, x;
  cin >> k >> n;
    x = 0;
  while (n >= k ){
   a = n / 10000;//おおきい
  b = (n - 10000 * a ) / 1000;
   c = ( n - 10000 *a - 1000 * b ) / 100;
    d = ( n - 10000 *a -1000 * b - 100 * c) / 10;
    e = ( n - 10000 *a -1000 * b - 100 * c - 10 * d) / 1;

    if( a == e && b == d ){x++;}
      n--;
  }
  
 
  cout << x << endl;
}


Measured memory_bytes: 256
N = int(input())
in_list = []
for i in range(N):
    in_list.append(int(input()))
in_max = max(in_list)
in_max2 = sorted(in_list)[-2]
for i in in_list:
    if i!=in_max:
        print(in_max)
    else:
        print(in_max2)

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

int main()
{
    int k;
    cin>>k;
    string str;
    cin>> str;

    int len = str.size();

    if(len > k)
    {
        str = str.substr(0,k) + "...";
    }
    cout<<str<<"\n";


}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 A, B;
  cin >> A >> B;
  if (A < 9 && B < 9)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
  return 0;
}


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

int main(){
    char n[200010] = {0};
    long long int sum = 0;
    scanf("%s", n);

    for(auto i=0; i<strlen(n); ++i){
        sum += (n[i] - '0');
    }

    if(sum % 9 == 0){
        printf("Yes");
    }else{
        printf("No");
    }

    return(0);
}

Measured memory_bytes: 1924
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
main(){
  int d, n, m, k;
  while( cin >> d && d ){
    cin >> n >> m;
    vector<int> v;
    v.push_back(0);
    rep(i, n-1){
      cin >> k;
      v.push_back(k);
    }
    v.push_back(d);
    sort(v.begin(), v.end());

    int sum = 0;
    rep(i, m){
      cin >> k;
      vector<int>::iterator pos = upper_bound(v.begin(), v.end(), k)-1;
      sum += min(k - *pos, *(pos+1) - k );
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1432
def main():
    #"""
    N, M = [int(n) for n in input().split(" ")]
    friends = []
    for _ in range(M):
        a, b = [int(n) for n in input().split(" ")]
        friends.append([a - 1, b - 1])
    #"""
    """
    N = 200000
    M = 200000
    friends = []
    import random
    for _ in range(M):
        a = random.randint(1, N)
        b = random.randint(1, N)
        while a == b:
            a = random.randint(1, N)
            b = random.randint(1, N)
        if a <= b:
            friends.append([a - 1, b - 1])
        else:
            friends.append([b - 1, a - 1])
    #friends = sorted(friends)
    """
    #print(friends)
    """
    dic = {}
    vdic = {}
    nowg = 0
    for f in friends:
        a = f[0]
        b = f[1]

        if a not in dic and b not in dic:
            dic[a] = nowg
            dic[b] = nowg
            vdic[nowg] = [a, b]
            nowg += 1
        elif a in dic and b not in dic:
            dic[b] = dic[a]
            vdic[dic[a]].append(b)
        elif a not in dic and b in dic:
            dic[a] = dic[b]
            vdic[dic[b]].append(a)
        else:
            aG = dic[a]
            bG = dic[b]
            # b -> a
            if aG == bG:
                continue
            for k in vdic[bG]:
                vdic[aG].append(k)
                dic[k] = aG
            del(vdic[bG])


    score = 0
    for k ,v in vdic.items():
        #print(g)
        s = len(v)
        if score <= s:
            score = s
    print(score)

    """

    X = {}
    for i in range(N):
        X[i] = []

    def show(m):
        for i in range(len(m)):
            print(m[i])

    #show(X)

    for f in friends:
        X[f[0]].append(f[1])
        X[f[1]].append(f[0])

    #show(X)

    groups = []

    vdic = [0 for _ in range(N)]

    for n in range(N):
        already = False
        if vdic[n] == 1:
            continue
        queue = [n]
        group = [n]
        vdic[n] = 1
        while len(queue) > 0:
            #print("now queue:", queue)
            nowNode = queue[0]
            del(queue[0])
            nextQueue = []
            for i in X[nowNode]:
                if vdic[i] == 0:
                    nextQueue.append(i)
                    group.append(i)
                    vdic[i] = 1
            queue += nextQueue
            nextQueue = []
        groups.append(group)

    #print(groups)

    score = 0
    for g in groups:
        #print(g)
        s = len(g)
        if score <= s:
            score = s
    print(score)



if __name__ == "__main__":
    main()

Measured memory_bytes: 79212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int N = 1e5+5;
struct node{
	int v,w;
};
vector<node> E[N];
long long dis[N];
bool vis[N];

void dfs(int u,long long sum){
	dis[u] = sum;
	vis[u] = 1;
	for(int i = 0;i < E[u].size();i++){
		int& v = E[u][i].v;
		if (vis[v]) continue;
		dfs(v,sum + E[u][i].w);
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1;i < n;i++){
		int a,b,c;
		cin >> a >> b >> c;
		node tmp = {b,c};
		E[a].push_back(tmp);
		tmp.v = a;
		E[b].push_back(tmp);
	}
	int q,k;
	cin >> q >> k;
	dfs(k,0);
	while(q--){
		int x,y;
		cin >> x >> y;
		cout << dis[x] + dis[y] << '\n';
	}
	return 0;
}

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

int main(void){
    int n, a, b;
    cin >> n;
    a = n / 100;
    b = n % 100;
    
    if (a >= 1 && a <= 12 && b >= 1 && b <= 12) {
        cout << "AMBIGUOUS" << endl;
    } else if (a >= 1 && a <= 12) {
        cout << "MMYY" << endl;
    } else if (b >= 1 && b <= 12) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
    
}


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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N - a*1000) / 100;
  c = (N - a*1000 - b*100) / 10;
  d = (N - a*1000 - b*100 - c*10) / 1;
  if ((a==b && a==c) || (b==c && b==d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
H = list(map(int, input().split()))

I = sorted(H,reverse=True)

if len(H) <= K:
    print(0)
elif K == 0:
    print(sum(H))
else:
    for i in range(K):
        I[i] = 0
    print(sum(I))


Measured memory_bytes: 31524
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(int, N);
	in_v(string, W, N);
	set<string> c;
	for (auto&& s : W)
		c.insert(s);
	if (c.size() != N) {
		out("No");
		return 0;
	}
	loop(i, N - 1)
		if (W[i].back() != W[i + 1].front()) {
			out("No");
			return 0;
		}
	out("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
int main(){
 
    string x;
    cin >> x;
    int n = x.size() + 1;
    vector<char> num(n);
    rep(i,n-1) num[i] = x[i];
    vector<int> intnum(n);
    rep(i,n-1) intnum[i] = num[i] - '0';


    ll sum = 0;
    rep(i,n){
        sum += intnum[i];
    }

    if(sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
 
}

Measured memory_bytes: 4568
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, k; rd(n, k);
  long tot=0;
  for(int a=1; a<=n; a++){
    if(a%k==0){
      auto y=(n/k).to!(long);
      tot+=y*y;
    }else{
      auto x=k-a%k;
      if((x*2)%k==0){
        if(n>=x){
          auto y=((n-x)/k+1).to!(long);
          tot+=y*y;
        }
      }
      // writeln(a, " ", tot);
    }
  }
  writeln(tot);

}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,ansl=0,sum=0,l;
	cin>>n;
	for(i=1;i<=n;i++)
	 cin>>l,sum+=l,ansl=max(ansl,l);
	if(ansl<sum-ansl)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

int n, s, w, q;
int a[100000];
void generate(){
  int g = s;
  for(int i=0;i<n;i++){
    a[i] = (g/7) % 10;
    if(g % 2 == 0) g = (g/2);
    else g = (g/2) ^ w;
  }
}

int calc(){
  int res = 0;
  map<int, int> cnt;
  int val = a[n-1] % q;
  int ten = 1;
  cnt[0]++;
  cnt[val]++;
  if(val == 0 && a[n-1] != 0) res++;
  for(int i=n-2;i>=0;i--){
    ten = (ten * 10) % q;    
    val = (val + a[i] * ten) % q;
    if(a[i] != 0 && cnt.count(val)) res += cnt[val];
    cnt[val]++;
  }
  return res;
}

int calc2(int k){
  int cnt = 0, res = 0;
  for(int i=n-1;i>=0;i--){
    if(k == 2 && a[i] % 2 == 0) cnt++;
    if(k == 5 && (a[i] == 0 || a[i] == 5)) cnt++;
    if(a[i] != 0) res += cnt;
  }
  return res;
}

main(){
  while(cin >> n >> s >> w >> q && (n|s|w|q)){
    generate();
    if(q == 2 || q == 5) cout << calc2(q) << endl;
    else cout << calc() << endl;
  }
}

Measured memory_bytes: 5804
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [n, y] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    let ans = [[a, b, n - a - b] | a <- [0..n], b <- [0..(n - a)], 9 * a + 4 * b == y `div` 1000 - n && n - a - b >= 0]
    if null ans
        then putStrLn "-1 -1 -1"
        else do
            let [a, b, c] = head ans
            putStrLn $ show a ++ " " ++ show b ++ " " ++ show c

Measured memory_bytes: 636
import java.io.FileInputStream;
import java.util.Scanner;


public class Main
 {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
//        System.setIn(new FileInputStream("text"));
        while(hasNext()){
            StringBuilder s = new StringBuilder(NLine());
            StringBuilder ans=new StringBuilder();
            if(s.length()==0)return;
            for (int i = 0; i < s.length(); i++) {
                if(s.charAt(i)=='@'){
                    i++;
                    int len = s.charAt(i)-'0';
                    i++;
                    for (int j = 0; j < len; j++) {
                        ans.append(s.charAt(i));
                    }
                } else {
                    ans.append(s.charAt(i));
                }
            }
            System.out.println(ans);
        }
    }

    
    static int c=-2;
    static int NI(){
        return (int)NL();
    }
    
    static long NL(){
        try {
            long r = 0;
            skip();
            if(c=='-') return -NL();
            for(;'0'<=c&&c<='9';c=System.in.read())
                r = r * 10 + c - '0';
            return r;
        } catch (Exception e) {
            return -1;
        }
    }
    
    static char NC(){
        try {
            skip();
            return (char)c;
        } catch (Exception e) {
            return 0;
        }
    }
    
    static String NS(){
        StringBuilder sb=new StringBuilder();
        try {
            skip();
            for(;!isSkip();){
                sb.append((char)c);
                c=System.in.read();
            }
            return sb.toString();
        } catch (Exception e) {
            return "";
        }
    }
    
    static String NLine(){
        StringBuilder sb=new StringBuilder();
        try {
            if(c==-2){
                c=System.in.read();
            }
            for(;c!='\n'&&c!='\r';){
                sb.append((char)c);
                c=System.in.read();
//                System.out.println(c);
            }
//            c=System.in.read();
            skip();
            return sb.toString();
        } catch (Exception e) {
            return "";
        }
    }
    
    static void skip(){
        try{
            while(isSkip()){
                c=System.in.read();
            }
        } catch (Exception e){}
        
    }
    
    static boolean hasNext(){
        skip();
        return c!=-1;
    }
    
    static boolean isSkip(){
        return 0 <= c && c <= ' ';
    }
}

Measured memory_bytes: 16848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    int N, K;
    cin >> N >> K;

    int V[N];
    REP(i, N) cin >> V[i];

    int ans = 0;
    REP2(A, 0, K) {
        int L = min(N, K) - A;
        REP2(B, 0, L) {
            priority_queue<int, vi, greater<int> > Q;
            if (A > 0) REP(i, A) Q.push(V[i]);
            if (B > 0) REP(i, B) Q.push(V[N-1-i]);

            int M = K - A - B;
            while (M > 0) {
                if (Q.empty() || Q.top() >= 0) break;
                Q.pop();
                M--;
            }

            int sum = 0;
            while (!Q.empty()) {
                sum += Q.top();
                Q.pop();
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int n,m;cin >> n >> m;
  map<int,int> mp;rep(i,m){int a;cin >> a;mp[a] = 1;}
  ll dp[n+1];ll MOD = 1000000007;
  dp[0] = 1; //0段目にたどり着く方法? = 1
  if(mp[1] == 1)dp[1] = 0;
  else dp[1] = 1;
  for(int i=2;i<=n;++i){
    if(mp[i] == 1)dp[i] = 0;
    else if(mp[i-2] == 1 && mp[i-1] == 1)dp[i] = 0;
    else if(mp[i-2] == 1)dp[i] = dp[i-1]%MOD;
    else if(mp[i-1] == 1)dp[i] = dp[i-2]%MOD;
    else dp[i] = (dp[i-2]+dp[i-1])%MOD;
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

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

    ll root=INF;
    for(ll i=1;i*i<=n;i++){
        if(n%i!=0){
            continue;
        }else{
            ll x=i-1,y=n/i-1;

            root=min(root,x+y);
        }
    }

    cout << root << endl;

    return 0;
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double[]	cheese = null;

		while((cheese = parseCheese()) != null) {
			int	cnt = parseNum();
			while (cnt-- > 0) {
				double	size = (double)parseNum();
				if (size > cheese[0] || size > cheese[1] || size > cheese[2]) {
					System.out.println("OK");
				} else {
					System.out.println("NA");
				}
			}
		}
	}

	private static int parseNum() {
		int		num = 0;
		String	str = null;

		if ((str = parseStdin()) != null) {
			num = Integer.parseInt(str);
		}

		return num;
	}

	private static double[] parseCheese() {
		String		str    = null;
		double[]	cheese = null;
		int[]		tmp    = null;

		if ((str = parseStdin()) != null) {
			String[]	lines = str.split(" ");

			if (lines.length == 3) {
				if (!lines[0].equals("0") || !lines[1].equals("0") || !lines[2].equals("0")) {
					tmp       = new int[3];
					tmp[0]    = Integer.parseInt(lines[0]);
					tmp[1]    = Integer.parseInt(lines[1]);
					tmp[2]    = Integer.parseInt(lines[2]);
					cheese    = new double[3];
					cheese[0] = Math.sqrt((double)(tmp[0]*tmp[0] + tmp[1]*tmp[1])) / 2.0;
					cheese[1] = Math.sqrt((double)(tmp[1]*tmp[1] + tmp[2]*tmp[2])) / 2.0;
					cheese[2] = Math.sqrt((double)(tmp[2]*tmp[2] + tmp[0]*tmp[0])) / 2.0;
				}
			}
		}
 
		return cheese;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 17044
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string a = s.substr(0, n);
    string b = s.substr(n, n);
    map<string, map<string, int>> cnt;
    REP(i, 1 << n) {
        string p = "";
        string s = "";
        REP(j, n) {
            if (i >> j & 1) {
                p += b[j];
            } else {
                s += b[j];
            }
        }
        cnt[p][s]++;
    }
    int ans = 0;
    REP(i, 1 << n) {
        string p = "";
        string s = "";
        REP(j, n) {
            if (i >> j & 1) {
                p += a[j];
            } else {
                s += a[j];
            }
        }
        string rs = s;
        reverse(ALL(rs));
        string rp = p;
        reverse(ALL(rp));

        ans += cnt[rs][rp];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 119552
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x,y,d;
    x=a*b;
    y=a-b;
    d=a+b;
    if(x>=d&&x>=y)
    {
        cout<<x;
    }
    else if(y>=x&&y>=d)
    {
        cout<<y;
    }
    else if(d>=x&&d>=y)
    {
        cout<<d;
    }
 
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int m, k;
  cin >> m >> k;

  if (m == 1 && k == 0) {
    cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
    return 0;
  }
  else if (m == 1 && k == 1) {
    cout << -1 << endl;
    return 0;
  }

  if (k >= (1 << m)) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ans;
  rep(i, (1 << m)) {
    if (i == k) continue;
    ans.push_back(i);
  }
  ans.push_back(k);
  repr(i, (1 << m) - 1) {
    if (i == k) continue;
    ans.push_back(i);
  }
  ans.push_back(k);
  
  rep(i, (1 << (m + 1))) {
    if (i) cout << " ";
    cout << ans[i];
  }
  

  
  return 0;
}

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

int main() {
  int a=0,b=0,c=0,d=0,e=0;
  cin >> a >> b >> c >> d >> e;
  if( (c-e)<0 || (d-e)<0 || (c+e)>a || (d+e)>b ){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  //cout << a << ' '  << b << ' ' << c << endl;
  return 0;
}



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

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    int d[100];
    cin>>n;
    REP(i,n)cin>>d[i];
    int sum=0;
    REP(i,n)REP(j,n)if(i<j)sum+=d[i]*d[j];
    cout<<sum<<endl;
}

Measured memory_bytes: 256
//Select sort

#include<stdio.h>
#define N 100

void sel(void);

int i = 0,arr[N];
int n = 0;
int k = 0;
int minj = 0;
int j = 0;
int count = 0;
int temp = 0;

int main()
{

  //input data
  scanf("%d",&n);

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

  //calculate
  sel();

  //output data
  printf("%d",arr[0]);

  for(k = 1; k < n;k++)
    {
      printf(" %d",arr[k]);
    }
  printf("\n");

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

  return 0;
}

void sel(void)
{
  for(i = 0; i < n - 1; i++)
    {
      minj = i;
    
      //for(j = n - 1; j > i; j--)
      for(j = i+1; j<n;j++)
	{ 
	  if(arr[j] < arr[minj])
	    {
	      minj = j;
	    }
	}

      if(minj != i)
      {
	  temp = arr[i];
	  arr[i] = arr[minj];
	  arr[minj] = temp;
   
	  count++;
	  }
    }
}



Measured memory_bytes: 2108
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int p, q;
	int a[100];
	for (int i = 0; i < 100; i++) { a[i] = 0; }
	while (cin >> p >> q) {
		if(p==0&&q==0)
		{
			bool others_even = a[0]%2==1&&a[1]%2==1;
			for (int i = 2; i < 100; i++) {
				others_even = others_even && (a[i] % 2 == 0);
			}
			if (others_even) { cout << "OK" << endl; }
			else { cout << "NG" << endl; }
			for (int i = 0; i < 100; i++) { a[i] = 0; }
			continue;
		}
		a[p - 1]++;
		a[q - 1]++;
	}
	return 0;

}


Measured memory_bytes: 3100
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define rnd(d) (ll)((double)(d) + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)(x) ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
	int n; cin >> n;
	ll s; cin >> s;
	vll x(n), p(n);
	Loop(i, n) {
		cin >> x[i] >> p[i];
	}
	deque<pair<int, ll>> deq;
	Loop(i, n) {
		deq.push_back({ i, p[i] });
	}
	stack<int> stk;
	while (deq.size() > 1) {
		if (x[deq.front().first] > s) {
			stk.push(deq.back().first);
			deq.pop_back();
		}
		else if (x[deq.back().first] < s) {
			stk.push(deq.front().first);
			deq.pop_front();
		}
		else {
			if (deq.front().second >= deq.back().second) {
				stk.push(deq.back().first);
				deq.front().second += deq.back().second;
				deq.pop_back();
			}
			else {
				stk.push(deq.front().first);
				deq.back().second += deq.front().second;
				deq.pop_front();
			}
		}
	}
	stk.push(deq.back().first);
	deq.pop_back();
	ll ans = 0;
	ll current_x = s;
	while (stk.size()) {
		ans += abs(current_x - x[stk.top()]);
		current_x = x[stk.top()];
		stk.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 3456