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


int main(){
  int A,B;
  cin>>A>>B;
  int sum =0;
  for(int i =0;i<B-A+1;i++){
    string a = to_string(A + i);
    if(a.at(0)==a.at(4)&&a.at(1)==a.at(3)){
      sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	deque<char> a,b ;
	for(int i=0;i<s.size();i++){
		if(i<s.size()/2) a.push_back(s.at(i)) ;
		else b.push_back(s.at(i)) ;
	}
	ll ans = s.size()-2 ;
	b.pop_back() ;b.pop_back() ;
	b.push_front(a.back()) ;
	a.pop_back() ;
	while(a!=b){
		ans -= 2 ;
		b.pop_back() ;b.pop_back() ;
		b.push_front(a.back()) ;
		a.pop_back() ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[105],n,k,ans; 
int main()
{
  cin>>n>>k;
  int x,y;
  for(int i=1;i<=k;i++)
  {
  	  cin>>x;// di  第i个点心有x个店卖
	  for(int j=1;j<=x;j++)
	  {
	  	     cin>>y;
			 a[y]++;
	   } 
  }
  for(int i=1;i<=n;i++)
  {
  	  if(a[i]==0) ans++;
  }
  cout<<ans;
return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PIP;

#define INF INT_MAX/3

int h, w;
char s[50][50];
int d[50][50];
bool visited[50][50];
int dd[] = {-1, 0, 1, 0, -1};

bool range(int y, int x) {return 0 <= x && x < w && 0 <= y && y < h;}

int main(){
    cin.sync_with_stdio(false);
    cin >> h >> w;
    int white = 0;
    rep(i, h)rep(j, w) {
        cin >> s[i][j];
        if (s[i][j] == '.') white++;
        d[i][j] = INF;
        visited[i][j] = false;
    }

    queue<PIP> q;
    q.push(PIP(1, P(0, 0)));
    while(q.size()) {
        PIP p = q.front();
        q.pop();
        if (visited[p.se.fi][p.se.se]) continue;
        visited[p.se.fi][p.se.se] = true;
        d[p.se.fi][p.se.se] = p.fi;
        rep(i, 4) {
            int x = p.se.se + dd[i], y = p.se.fi + dd[i + 1];
            if (range(y, x) && s[y][x] == '.' && !visited[y][x]) {
                q.push(PIP(p.fi + 1, P(y, x)));
            }
        }
    }

    if (!visited[h - 1][w - 1]) cout << -1 << endl;
    else cout << white - d[h - 1][w - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define for0(i,n) for(int i=0;i<n;i++)
#define rep(i,s,n) for(int i=s;i<n;i++)
#define sp <<" "<<					// giving space
#define MOD 1000000007				// for mod
#define ll_max 1000000000000000000
#define ll long long
#define ld long double
#define BOOST ios_base::sync_with_stdio ( false ); cin.tie ( nullptr ); cout.tie ( nullptr );
using namespace std;
// Vector
#define vi vector<int>					//integer vector
#define vll vector<ll>
#define pb push_back				//vector element insertion
#define pf push_front
#define er(v,i) v.erase(v.begin()+i)			// erase ith element in a vector
#define erng(v,x) v.erase(v.begin(),v.begin()+x)       	// delete a range in array

//Stack
/*  stack<int> s;						//declaring stack
s.push(1)						// enter  element in stack
s.top()							//returns top element in stack
s.pop()							//removes top element in  stack
*/
// pair
#define pii pair<int,int>					//pair integers
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)			// entering pair element in vector(size not defined)

//Hashmap
/* map<string,string> a;				//declaration
a[“abc”]=”xyz”;					// element entry in map;
gquiz1.insert(pair<int, int>(1, 40));
map<string,string>::iterator itr;			//iterating map
for (itr = a.begin(); itr!=a.end(); itr++){
    cout <<(*itr).first  << itr->second <<endl;
  }
  itr = companies.find("abc");		//finding element in map
  cout << itz->second;

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


Measured memory_bytes: 2560
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 as nx
# from bisect import bisect_left,bisect_right
from heapq import heapify,heappush,heappop
n,m=n1()
AB=t3(n)

d=defaultdict(list)
for a,b in AB:
    d[a].append(b)

ans=0
h=[]
for i in range(1,m+1):
    while len(d[i])>0:
        heappush(h,-1*d[i].pop())
    if len(h)>0:
        ans+=-1*heappop(h)
print(ans)

Measured memory_bytes: 37768
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

ll MOD;

namespace mod {
ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll power(ll x, ll e, ll M) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % M;
    }
    x = x * x % M;
  }
  return v;
}

ll inverse(ll x) { return power(x, MOD - 2); }

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

ll multiChoose(int n, int k) {
  if (n == 0 && k == 0) {
    return 1;
  } else {
    return choose(n + k - 1, k);
  }
}
}  // namespace mod

int main() {
  int N;
  while (cin >> N >> MOD) {
    mod::initFact(N + 10);
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
    dp[0][0] = 1;
    for (int n = 1; n <= N; n++) {
      dp[n][0] = 1;
      for (int k = 1; k <= n; k++) {
        dp[n][k] =
            (dp[n - 1][k] + dp[n - 1][k - 1] + dp[n - 1][k] * k % MOD) % MOD;
      }
    }
    ll res = 0;
    for (int k = 0; k <= N; k++) {
      ll sum = 0;
      for (int i = 0; i <= k; i++) {
        ll y = dp[k][i] * mod::power(2, (N - k) * i) % MOD;
        sum = (sum + y) % MOD;
      }
      ll y = sum * mod::power(2, mod::power(2, N - k, MOD - 1)) % MOD *
             mod::choose(N, k) % MOD;
      if (k % 2 == 0) {
        res = (res + y) % MOD;
      } else {
        res = (res - y + MOD) % MOD;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 72832
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,k;
vl a,b;

bool f(ll x){
	ll t=0;
	for(int i=0;i<n;i++) t+=max(0ll,a[i]-x/b[i]);
	return t<=k;
}

int main(){
	cin>>n>>k;
	a=b=vl(n);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	sort(a.begin(),a.end());
	sort(b.rbegin(),b.rend());
	ll l=-1,r=INF;
	while(r-l>1){
		ll m=(l+r)/2;
		if(f(m)) r=m;
		else l=m;
	}
	cout<<r<<endl;
}

Measured memory_bytes: 3328
using System;

public class Program
{
	public static void Main()
	{
		var classes = new Class[]
		{
			new Class { Name = "light fly", Weight = 48.00 },
			new Class { Name = "fly", Weight = 51.00 },
			new Class { Name = "bantam", Weight = 54.00 },
			new Class { Name = "feather", Weight = 57.00 },
			new Class { Name = "light", Weight = 60.00 },
			new Class { Name = "light welter", Weight = 64.00 },
			new Class { Name = "welter", Weight = 69.00 },
			new Class { Name = "light middle", Weight = 75.00 },
			new Class { Name = "middle", Weight = 81.00 },
			new Class { Name = "light heavy", Weight = 91.00 },
			new Class { Name = "heavy", Weight = 150.00 }
		};
		while (true)
		{
			var line = Console.ReadLine();
			if (string.IsNullOrEmpty(line))
			{
				return;
			}
			double weight = double.Parse(line);
			foreach (var item in classes)
			{
				if (weight <= item.Weight)
				{
					Console.WriteLine(item.Name);
					break;
				}
			}
		}
	}
}

public class Class
{
	public double Weight { get; set; }
	public string Name { get; set; }
}

Measured memory_bytes: 9152
n = int(input())
a = [int(input()) for _ in range(n)]
now = 1
ans = 0
while True:
    now = a[now-1]
    ans += 1
    if (now==2):
        print(ans)
        break
    elif (now==1):
        print(-1)
        break
    elif (ans>len(a)):
        print(-1)
        break
    



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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n>>k;
        
        ll mx=(n*(n-1))/2 - (n-1);
        if(k>mx){
                cout<<-1<<endl;
                return;
        }
        cout<<mx-k+n-1<<endl;
        
        for(i=2;i<=n;i++){
                cout<<1<<" "<<i<<endl;
        }
        ll cnt=0;
        for(i=2;i<=n;i++){
                for(j=i+1;j<=n;j++){
                        if(cnt==mx-k)break;
                         cout<<i<<" "<<j<<endl;       
                         cnt++;
                         
                }
                if(cnt==mx-k)break;
        }
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

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

int pcnt(int x){
    return __builtin_popcount(x);
}

int f(int x) {
    if(x == 0) return 0;
    return f(x%pcnt(x))+1;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi x(n);
    rep(i, n) x.at(i) = s.at(i)-'0';
    int popcnt = 0;
    //最初に入力された二進数Xのpopcountを求める
    rep(i, n) popcnt += x.at(i);
    vi ans(n);
    //Oと1で処理
    rep(b,2){
        int npopcnt = popcnt;
        if(b == 0) npopcnt++; else npopcnt--;
        //npopcntが０以下の場合の例外処理
        if(npopcnt <= 0) continue;
        //元の割った余り？
        int r0 = 0;
        rep(i, n){
            r0 = (r0*2)%npopcnt;
            r0 += x.at(i); 
        }
        int k = 1;
        for(int i = n-1; i >= 0; i--) {
            if(x.at(i) == b) {
                int r = r0;
                if(b == 0) r = (r+k)%npopcnt;
                //r-kはマイナスになる可能性があるのでnpopcntを足す
                else r =(r-k+npopcnt)%npopcnt;
                ans.at(i) = f(r) + 1;
            }
            k = (k*2)%npopcnt;
        }
    }
    rep(i,n) cout << ans.at(i) << endl;
}


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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3116
import numpy as np
MAX = 200002
MOD = 998244353
fac = np.zeros(MAX)
finv = np.zeros(MAX)
inv = np.zeros(MAX)

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX):
    fac[i] = int(fac[i-1]) * i % MOD
    inv[i] = MOD - int(inv[MOD%i]) * (MOD//i) % MOD
    finv[i] = int(finv[i-1]) * int(inv[i]) % MOD

def COM(N,K):
    return  int(fac[N]) * (int(finv[K]) * int(finv[N - K]) % MOD) % MOD

def resolve():
    N,M,K = map(int,input().split())
    ans = 0
    for i in range(K + 1):
        ans_k = M * COM(N-1, i )
        ans_k = ans_k * pow(M-1,N-1-i, MOD) % MOD
        ans = (ans + ans_k) % MOD
    print(ans)
resolve()

Measured memory_bytes: 31344
#include<stdio.h>
int main(){
	double v,n,y;
	while(scanf("%lf",&v)!=EOF){
		y=4.9*(v/9.8)*(v/9.8);
		n=(y+5)/5.0;
		if(n-(int)n!=0){
			n++;
		}
		printf("%d\n",(int)n);
	}
	return 0;
}

Measured memory_bytes: 628
import std.stdio, std.string, std.conv, std.algorithm;

void main() {
	int n, m;
	"%d %d\n".readf(&n, &m);
	int[][] a;
	int[] b;
	foreach (_n; 0..n) a ~= readln.split.to!(int[]);
	foreach (_m; 0..m) b ~= readln.split[0].to!int;
	foreach (_a; a) {
		long s = 0L;
		foreach (i; 0..m) s += _a[i] * b[i];
		s.writeln;
	}
}

Measured memory_bytes: 2892
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

const int INF = 650000;
int h, w, k;
int sx, sy;
char maze[805][805];
int d[805][805];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int dis(int x, int y) {
	int xx = min(x, h-1-x);
	int yy = min(y, w-1-y);
	return min(xx, yy);
}

void bfs() {
	queue<P> que;
	FOR(i, h) {
		FOR(j, w) d[i][j] = INF;
	}
	que.push(P(sx, sy));
	d[sx][sy] = 0;

	while (que.size()) {
		P p = que.front(); que.pop();
		FOR(i, 4) {
			int nx = p.first + dx[i], ny = p.second + dy[i];

			if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] == '.' && d[nx][ny] == INF) {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> h >> w >> k;
	FOR(i, h) {
		string s;
		cin >> s;
		FOR(j, w) {
			maze[i][j] = s[j];
			if (s[j] == 'S') {
				sx = i;
				sy = j;
			}
		}
	}

	if (sx == 0 || sx == h-1 || sy == 0 || sy == w-1) {
		cout << 0 << endl;
		return 0;
	}

	bfs();
	int res = INF;
	FOR(i, h) {
		FOR(j, w) {
			if (d[i][j] <= k) {
				if (dis(i, j) == 0) {
					cout << 1 << endl;
					return 0;
				}
				res = min(res, (dis(i, j)+k-1)/k+1);
			}
		}
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
typedef long long ll;
using namespace std;

int gcd(int a, int b) {
		return a % b == 0 ? b : gcd(b, a % b);
}

int lcm(int a, int b) {
		return a / gcd(a, b) * b;
}

int main() {
		int n;
		int a[1000];
		cin >> n;
		int i = 0;
		while (cin >> a[i]) {
				i++;
		}

		ll temp = a[0];

		for (i = 1; i < n; i++) {
				temp = lcm(temp, a[i]);
		}
		
		cout << temp << endl;

		return 0;
}
		

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int( 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong

signed main(){
    int n,k;
    cin >> n >> k;
    int A[MAX];
    REP(i,n) scanf("%lld",&A[i]);
    int kosuu[50] = {};
    REP(i,n){
        int bit = 1;
        REP(j,50){
            if( (bit&A[i])){
                kosuu[j] ++; 
            }
            if( int(A[i]/2) < bit) break;
            bit *= 2;
        }
    }


    int res = 0;
    int bit = 1;
    int binary_k[50] = {};
    int ind = 0;
    REP(i,48){
        if(  (bit& k) ){
            binary_k[i] = 1;
            res += (n-kosuu[i]) * bit;
        }
        else res += kosuu[i] * bit;
        bit *= 2;
        ind ++;
    }


    


    REPR(i,ind){
        int tmpbit = bit;
        if( binary_k[i] ){
            int ans = 0;
            REPR(j,ind){
                if(j == i) ans += kosuu[j] * tmpbit;
                else if( j > i){
                    if(binary_k[j]) ans += (n-kosuu[j]) * tmpbit;
                    else ans += kosuu[j] * tmpbit;
                } 
                else{
                    ans += max( (n-kosuu[j]),kosuu[j] ) * tmpbit;
                }
                tmpbit /= 2;
            }
            res = max( ans , res);
        }
        
    }

    cout << res << endl;
}

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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#define debug(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#define debug(...) __VA_ARGS__
#endif
const int N = 200005;

ll a[N];

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

    int n; cin >> n;
    ll sum = 0;
    fo1(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    ll s = 0;
    ll ans = OO;
    fo1(i, n-1) {
        s += a[i];
        ll k = sum - s;
        ans = min(ans, abs(k - s));
    }

    cout << ans << endl;

    return 0;
}

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



  
int main(){
  
  int64_t n;
  cin>>n;
  
  vector<int64_t> data(n);
  
  for (int64_t i=0;i<n;i++){
    int64_t tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  
  vector<int64_t> count(n);
  
  count.at(0)=1;
  
  vector<int64_t> rec(0,0);
  
  
  int64_t morethan1=0;
  
  for (int64_t i=1;i<n;i++){
    if (data.at(i)==data.at(i-1)){
      count.at(i)=count.at(i-1)+1;
    }
    else {
      count.at(i)=1;
    }
    
    if (count.at(i)==2 or count.at(i)==4){
      morethan1++;
      rec.push_back(data.at(i));
    }
    
    if (morethan1==2){
      break;
    }
  }

  
  if (int(rec.size())==2){
    cout<<rec.at(0)*rec.at(1)<<endl;
  }
  
  else {
    cout<<"0"<<endl;
  }
  
  
}

    











Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
//#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    int res = 1;

    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);

        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool isprime(int x)
{
      if(x<2)
        return false;
    for(int i=2;i*i<=x;i++)
     {
        if (x%i==0)
            return false;
    }
    return true;
}
vector<int>primeFactors(int n)
{
    vector<int>v;
    int x=0;
    while (n % 2 == 0)
    {
        x++;
        n = n/2;
        v.pb(2);
    }
    //if(x>0)
    //v.pb({2,x});
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        int y=0;
        while (n % i == 0)
        {
            y++;
            n = n/i;
            v.pb(i);
        }
        //if(y>0)
        //v.pb({i,y});
    }
    if (n > 2)
        v.pb(n);
    return v;
}

vector<int>leastPrimeFactor(int n)
{
    vector<int>least_prime(n);
    // Create a vector to store least primes.
    // Initialize all entries as 0.
    // We need to print 1 for 1.
    least_prime[1] = 1;

    for (int i = 2; i <= n; i++)
    {
        // least_prime[i] == 0
        // means it i is prime
        if (least_prime[i] == 0)
        {
            // marking the prime number
            // as its own lpf
            least_prime[i] = i;

            // mark it as a divisor for all its
            // multiples if not already marked
            for (int j = 2*i; j <= n; j += i)
                if (least_prime[j] == 0)
                   least_prime[j] = i;
        }
    }
    return least_prime;
}

void solve()
{
char c;
cin>>c;
if(c>='A'&&c<='Z')
    cout<<"A"<<endl;
else
    cout<<"a"<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
//cin>>t;
t=1;
while(t--)
{
solve();
}
}



Measured memory_bytes: 3624
from itertools import groupby

N=int(input())
S=['a' for i in range(0,N)]
for i in range(0,N):
    S[i]=input()
S.sort()
X=groupby(S)
data=[]
for key,group in X:
    g=len(list(group))
    data.append([g,key])
data.sort()
m=data[len(data)-1][0]
for i in range(0,len(data)):
    if data[i][0]==m:
        print(data[i][1])

Measured memory_bytes: 40076
#include<bits/stdc++.h>
using namespace std;
int n;
string s,t,ans;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>s>>t;
    for(int i=0;i<n;i++)
	{
        ans+=s[i];
        ans+=t[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int k;
  cin >> k;
  vector<bool> chk(k, false);
  int now = 0, ans = 0;
  while(1){
    ans++;
    now = now * 10 + 7;
    now %= k;
    if(now == 0){
      cout << ans << endl;
      return 0;
    }
    if(chk.at(now) == false){
      chk.at(now) = true;
    }else{
      break;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

int main(){
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	
	for(int i=0;i<H;i++){
		cin >> S.at(i);
	}	//���͊���
	
	for(int i=0; i<H; i++){  
		for(int j=0; j<W; j++){
			int bomb=0;
			if(S.at(i).at(j)=='.'){
				for(int k=max(0,i-1);k<=min(H-1,i+1);k++){
					for(int l=max(0,j-1);l<=min(W-1,j+1);l++){
						if(S.at(k).at(l)=='#'){
							bomb++;
						}
					}
				}   //S[i][j]�̎���̔��e�̌�bomb
				S.at(i).at(j)=bomb+'0';  //S[i][j]�̎���̔��e�̌��ɒu������
			}
		}  
		cout << S.at(i) << endl;  
	}  
}

Measured memory_bytes: 256
def main():
    N = int(input())
    a = list(map(int,input().split()))

    res = 0
    for i in range(N):
        if (i+1) % 2 == 1 and a[i] % 2 == 1:
            res += 1
    print(res)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61916
// inputに入力データ全体が入る
function Main(input) {
  var result = "";
  if(input[0] == input[1] && input[0] == input[2]) {
    result = "No";
  } else {
    result = "Yes";
  }
  console.log(result)
}

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


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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

#define INF 1e15+10

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

    ll n,w;
    cin>>n>>w;
    vector<ll> dp(n*1e3 +10, INF); // dp on the possible values and task is to minimize this dp[] which will be the sum of the weights 
    dp[0] = 0;

    ll rows[n][2];
    for(int i=0;i<n;++i)    cin>>rows[i][0]>>rows[i][1];
    ll tot = 0;
    for(int i=0;i<n;++i)    tot += rows[i][1];

    for(int i=0;i<n;++i){
        for(int j=tot - rows[i][1];j>=0;--j){
            dp[j + rows[i][1]] = min(dp[j + rows[i][1]], dp[j] + rows[i][0]);
        }
    }

    ll answer = 0;

    for(ll j=0;j<=tot; ++j){
        if(dp[j] <= w){
            answer = max(answer, j);
        }
    }

    cout<<answer<<"\n";

    return 0;
}

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

int main()
{
	int n,y;
	std::cin >> n >> y;
	int a = -1, b = -1, c = -1;
	for(int i = 0; i <= n; i++){
		for(int k = 0; k <= n; k++){
			bool flag = true;
			int sen = y - i*10000 - k*5000;
			int sen2 = n - i - k;
			if(sen2 < 0)flag = false;
			if(sen / 1000 != sen2)flag = false;
			if(flag){
				a = i;
				b = k;
				c = sen2;
			}
		}
	}
	std::cout << a <<" "<<b<<" "<< c << std::endl;
}

Measured memory_bytes: 256
/*{{{*/
#include "bits/stdc++.h"
using namespace std;

#define MT make_tuple
#define all(x) begin(x), end(x)
#define putchar(x) cout << (x)
static int fastio = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename ...T> string format(const string& fmt, T&&... args) {
    size_t sz = snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
    unique_ptr<char[]> buf(new char[sz]);
    snprintf(buf.get(), sz, fmt.c_str(), args...);
    return string(buf.get(), buf.get() + sz - 1);
}

template<class T> struct rge { T b, e; auto begin() const { return b; } auto end() const { return e; } };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
template<class T> auto dud(T* x) -> decltype(cerr << *x, 0);
template<class T> char dud(...);

struct debug {
#ifdef LOCAL
    debug(int line) {
        if(line) cerr << "LINE(" << line << ") -> ";
    }
    template<class T> typename enable_if<sizeof dud<T>(0) != 1, debug&>::type operator<<(T i) {
        cerr << boolalpha << i; return * this;
    }
    template<class T> typename enable_if<sizeof dud<T>(0) == 1, debug&>::type operator<<(T i) {
        return *this << range(begin(i), end(i));
    }
    template<class T, class U> debug& operator<<(pair<T, U> d) {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    debug& operator<<(tuple<>&) { return *this << "()"; };
    template<class ...T> debug& operator<<(tuple<T...> d) {
        *this << "("; debug_tuple<sizeof...(T), 0>(d);
        return *this << ")";
    }
    template<size_t L, size_t I, class T> void debug_tuple(const T& t) {
        *this << (I == 0 ? "" : ", ") << get<I>(t);
        if(I + 1 < L) debug_tuple<L, (I + 1) % L>(t);
    }
    template<class T> debug & operator <<(rge<T> d) {
        *this << "[";
        for(auto it = d.b; it != d.e; ++it)
            *this << (it != d.b ?  ", " : "") << *it;
        return *this << "]";
    }
    debug& operator<<(ostream&(*pf)(std::ostream&)) {
        cerr << pf; return *this;
    }
#else
    debug(int) {}
    template<class T> debug& operator<<(T&&) { return *this; }
    debug& operator<<(ostream&(*)(std::ostream&)) { return *this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] "

#define debug0()  debug(__LINE__)
#define debug1(x) debug(0)
#define GET_MACRO(_0, _1, NAME, ...) NAME
#define debug(...) GET_MACRO(_0, ##__VA_ARGS__, debug1, debug0)(__VA_ARGS__)
/*}}}*/
using LL = long long;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 200005;

void solve(int) {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    auto A = H1 * 60 + M1;
    auto B = H2 * 60 + M2;
    auto X = (A <= B) ? B - A : B + 24 * 60 - A;
    cout << max(0, X - K) << endl;
}

int main() {
    int T = 1;
    //cin >> T;
    for(int i = 1; i <= T; ++i) {
        solve(i);
    }
    return 0;
}


Measured memory_bytes: 3656
#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))

typedef long long ll;

const int M=10000000;
int dp[400][400];

vector<int>wass;
bool ok(int a, int b){
    return abs(wass[a]-wass[b])<=1;
}
int solve(int l,int r){
    if(dp[l][r]!=-1)return dp[l][r];
    if(l==r)return dp[l][r]=0;
    else if(l==r+1)return dp[l][r]=0;
    else{
        int ans=0;
        for(int p=l+1;p<r;++p){
            ans=max(ans,solve(l,p)+solve(p,r));
        }
        if(ok(l,r-1)){
            if(solve(l+1,r-1)==r-l-2){
                ans=r-l;
            }
        }
        return dp[l][r]=ans;
    }
}
int main()
{
    while(true){
        for(int i=0;i<400;++i){
            for(int j=0;j<400;++j){
                dp[i][j]=-1;
            }
        }
        int N;cin>>N;
        if(!N)break;
        wass.assign(N,0);

        for(int i=0;i<N;++i){
            cin>>wass[i];
        }
        int ans=solve(0,N);
        cout<<ans<<endl;
    }
   
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define NMAX 110
using namespace std;

int N,M,S,T;
vector<int> G[NMAX];
int R[NMAX][NMAX];
int L[NMAX];

bool BFS() {
  int a,b;
  queue<int> Q;
  Q.push(S);
  memset(L,-1,sizeof L);
  L[S] = 0;
  while(!Q.empty()) {
    a = Q.front();
    Q.pop();
    if(a==T)
      break;
    for(int i=0;i<(int)G[a].size();i++) {
      b = G[a][i];
      if(R[a][b]>0 && L[b]==-1) {
	L[b] = L[a]+1;
	Q.push(b);
      }
    }
  }
  return L[T]!=-1 ;
}

int DFS(int a, int f) {
  if(a==T)
    return f;
  int b,c;
  for(int i=0;i<(int)G[a].size();i++) {
    b = G[a][i];
    if(L[a]+1 == L[b] && R[a][b]>0) {
      if((c = DFS(b,min(f,R[a][b])))) {
	R[a][b] -= c;
	R[b][a] += c;
	return c;
      }
      else
	L[b] = -1;
    }
  }
  return 0;
}

int maxFlow()
{
  int flow, maxFlow = 0;
  while( BFS() )
    while( (flow = DFS(S,INT_MAX)) )
      maxFlow += flow;
  return maxFlow;
}

int main()
{
  int a,b,c;
  scanf("%d%d",&N,&M);
  
  for(int i=0;i<M;i++)
    {
      scanf("%d%d%d",&a,&b,&c);
      G[a].push_back(b);
      G[b].push_back(a);
      R[a][b] += c;
    }
  S = 0;
  T = N-1;

  printf("%d\n",maxFlow());
      
  return 0;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)

int main(){
	ll a,b,k;
	cin >> a >> b >> k;
	FORR(i,1,min(a,b)+1){
		if(a%i==0 && b%i==0){
			k--;
			if(k==0){
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
n=int(input())
ws=[input() for i in range(n)]
s=ws[0][-1]
for i in range(1,n):
    if ws[i][0]==s:
      s=ws[i][-1]
    else:
      print('No')
      exit()
if len(set(ws))==n:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
    int i,a[4],b[4],a_total=0,b_total=0,put;
    for(i=0;i<4;i++)
    {
        scanf("%d",&a[i]);
        a_total+=a[i];
    }
    for(i=0;i<4;i++)
    {
        scanf("%d",&b[i]);
        b_total+=b[i];
    }
    put=a_total<b_total?b_total:a_total;
    printf("%d\n",put);
    //Sleep(1000);
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a <= c && c <= b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
if n == 2:
	print(2)
else:
	ans = 1
	s = []
	for x in a:
		if x < len(s)*2 + 1:
			ans *= len(s)+1
			ans %= MOD
		else:
			s.append(x)
	for i in range(len(s)):
		ans *= i+1
		ans %= MOD
	print(ans)

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18+7;

int main(){
	setIO();
	int n, ct = 0; cin >> n;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j*i < n; j++)
			ct++;
	}
	cout << ct << endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(){
  char m;
  int a,b,c[256],i,j;
  for(i=0;i>-1;i++){
    scanf("%d %c %d",&a,&m,&b);
    if(m=='?'){
      break;
    }
    if(m=='+'){
      c[i]=a+b;
    }
    if(m=='-'){
      c[i]=a-b;
    }
    if(m=='*'){
      c[i]=a*b;
    }
    if(m=='/'){
      c[i]=a/b;
    }
  }
  for(j=0;j<i;j++){
    printf("%d\n",c[j]);
  }
  return(0);
}

Measured memory_bytes: 1028
#include <stdio.h>
int main()
{
    int i,j,k,ans=0,n,h;
    scanf("%d %d",&k,&n);
    for(i=0;i<=k;i++)
        for(j=0;j<=k;j++)
        {
            h=n-i-j;
            if(h>k) continue;
            else if(h<0) continue;
            else ans++;
        }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

ll dp[100010][13];//:=前からi桁目を決めるまでで，そこまでで13で割った余りがjの組み合わせ

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int n=sz(s);

  dp[0][0]=1;

  rep(i,n){
    rep(j,13){
      if(s[i]=='?'){//前からi桁目が?のとき，0~9を入れて試す
        rep(next,10){
          dp[i+1][(j*10+next)%13]+=(dp[i][j])%MOD;
          //たとえば'12?'は'100+20+?'なので余りは
          //(12*10の余り+'?')%13となる
        }
      }
      else{
        dp[i+1][(j*10+s[i]-'0')%13]+=(dp[i][j])%MOD;
      }
    }
  }
  cout << dp[n][5]%MOD << endl;
  return 0;
}


Measured memory_bytes: 10624
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<set>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100050
#define ll long long
#define low(x) (x&(-x))
#define inf 1000000000
using namespace std;
int read(){
    int x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int s[100500],ans,n;
int main(){
//	freopen("in.txt","r",stdin);
	n=read();
	rep(i,1,n) {
		int x=read();
		s[x+5]++; s[x-1+5]++; s[x+1+5]++;
	}
	rep(i,-1,100001) ans=max(ans,s[i+5]);
	printf("%d\n",ans);
	return 0;
}

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

ll dp[33][305],ans=0,all;
int p[7],a[7],n,c;
inline void solve(){
	int i,j,k,t=(1<<(n-1))-1;
	for(i=0;i<n*c;++i){
		int o=p[i%n],nl=min(n*c,a[o]*n+i);
		if(!o)continue;
		o=(1<<(o-1));
		for(j=t;j>=0;--j){
			if(o&j)continue;
			for(k=n*c;k>=i;--k){
				if(!dp[j][k])continue;
				dp[j|o][max(k,nl)]+=dp[j][k];
			}
		}
	}
	ans+=dp[t][n*c];
	return;
}

int main(){
	int i;
	scanf("%d%d",&n,&c);
	for(i=1;i<=n;++i)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(i=1;i!=n;++i)p[i]=i;
	int num=0;
	do{
		memset(dp,0,sizeof(dp));
		dp[0][a[n]*n]=1;
		solve();++num;
	}while(next_permutation(p+1,p+n));
	double res=1.0/((double)(num));
	for(i=1;i<=n-1;++i)res/=((double)(c));
	printf("%.12lf\n",res*((double)(ans)));
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <math.h>

 
int main() {
	double xs[101],ys[101],rs[10001];
	int n,ans[10001];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf %lf",&xs[i],&ys[i]);
 	}
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		double gx,gy,R=0;
		scanf("%lf %lf",&gx,&gy);
		bool isPeriphery=false;
		for(int j=0;j<n;j++){
			int p1=j;
			int p2=(j+1)%n;
			double dx1,dy1,dx2,dy2,len1,len2;
			dx1=xs[p1]-gx;
			dy1=ys[p1]-gy;
			dx2=xs[p2]-gx;
			dy2=ys[p2]-gy;
			len1=hypot(dx1,dy1);
			len2=hypot(dx2,dy2);
			double gaiseki=dx1*dy2-dx2*dy1;
			double naiseki=dx1*dx2+dy1*dy2;
 			
			if(naiseki<=0&&gaiseki==0){
				isPeriphery=true;
			}else{
				double aSinVal,sinVal;
				
			if(len1*len2>0){
					sinVal=gaiseki/(len1*len2);
				}else{
					isPeriphery=true;
					break;
				}
				if(sinVal<-1)sinVal=-1;
				if(sinVal>1)sinVal=1;
 				aSinVal=asin(sinVal);
				if(gaiseki>0){
					if(naiseki>=0)R+=aSinVal;
					else R+=M_PI-aSinVal;
				}else{
					if(naiseki>=0)R+=aSinVal;
					else R+=-aSinVal-M_PI;
				}
			}
 		}
		
		int type;
		if(fabs(R-M_PI*2)<0.0001){
			type=2;
		}else{
			type=0;
		}
 
		if(isPeriphery==true){
			type=1;
		}
		rs[i]=R;
		ans[i]=type;
	}
 	for(int i=0;i<q;i++){
		printf("%d\n",ans[i]);
	}
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll s;
  cin >> s;

  ll a = s;
  set<ll> num;
  num.insert(a);
  ll i = 1;

  while(true){
    if(a % 2 == 0)
      a /= 2;
    else
      a = 3*a + 1;

    if(num.count(a) == 1){
      cout << i + 1 << "\n";
      return 0;
    }

    num.insert(a);
    i++;
  }
  
  return 0;
}


Measured memory_bytes: 3552
// my の定義式を修正
// df=0
// int を li に
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define dist(a,b) max((a)-(b),(b)-(a));
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;

int main(){
  int n,_; cin >>n >>_;
  vector<li> a;

  rep(_,n+1){
    int p; cin >>p;
    a.push_back(p);
  }
  if(df){
    for(const auto &x: a) cout << x << " ";
    cout << "\n";
  } 

  li mx,my,x;
  mx=my=x=dist(a[n],a[n-1]);
  for(int i=n-1; i>=0; i--){
    li d=dist(a[n],a[i]);
    x=max(my,d);
    mx=min(mx,x);
    my=max(my,min(mx,d));
    if(mx==my) {
      d=dist(a[n],a[0]);
      x=max(my,d);
      break;
    }
    if(df)printf("x:%ld mx:%ld my:%ld \n",x,mx,my);
  }
  printf("%ld\n",x);
}


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

int main() {
  vector<vector<int>> c(3, vector<int>(3));

  int tmp;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> tmp;
      c.at(i).at(j) = tmp;
    }
  }

  int a1Upper = 100;
  for (int i = 0; i < 3; i++) a1Upper = min(a1Upper, c.at(0).at(i));
  string ans = "No";
  int b1, b2, b3, a2, a3;
  for (int a1 = 0; a1 <= a1Upper; a1++) {
    b1 = c.at(0).at(0) - a1;
    b2 = c.at(0).at(1) - a1;
    b3 = c.at(0).at(2) - a1;
    a2 = c.at(1).at(0) - b1;
    a3 = c.at(2).at(0) - b1;
    if (b1 < 0 || b2 < 0 || b3 < 0 || a2 < 0 || a3 < 0) {
      continue;
    }
    if ((a2 != c.at(1).at(1) - b2) || (a2 != c.at(1).at(2) - b3)) {
      continue;
    }
    if ((a3 != c.at(2).at(1) - b2) || (a3 != c.at(2).at(2) - b3)) {
      continue;
    }
    ans = "Yes";
    break;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    rep(i,N)cin >> a[i] >> b[i] >> c[i];
    LL DP[N+10][3] = {0};
    LL tmp;

    rep(i,N) rep(j,3) rep(k,3){   //jは前日に何をしていたか,kは前々日に何をしていたか
        if(j == k)continue;
        if(j == 0)tmp = a[i];
        if(j == 1)tmp = b[i];
        if(j == 2)tmp = c[i];
        chmax(DP[i+1][j],DP[i][k] + tmp);
    }
    LL ans = max(DP[N][0],DP[N][1]);
    ans = max(ans,DP[N][2]);
    cout << ans << endl;
}

Measured memory_bytes: 3840
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	r.Scan(true)

	s := make([]int, 0, 55)
	{
		i := 11
		for {
			if pow(2, i-1, i) == 1 {
				x := fact(i)
				if len(x) == 1 && x[0].count == 1 {
					s = append(s, i)
					if len(s) >= 55 {
						break
					}
				}
			}
			i += 10
		}
	}

	i2s := func(src []int) (dst []string) {
		dst = make([]string, 0, len(src))
		for i := range src {
			value := &src[i]
			dst = append(dst, fmt.Sprint(*value))
		}
		return
	}
	fmt.Fprintln(stdout, strings.Join(i2s(s[0:n]), " "))
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int P=1e9+7;
int n,m,s,a[N],f[N];
long long  fac[N],inv[N];
long long A(int n,int m){
	if(m>n||n<0)	return 0;
	return fac[n]*inv[n-m]%P;
}
long long fsp(long long x,int y){
	long long ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		y>>=1,x=x*x%P;
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&m),s=1<<n,fac[0]=inv[0]=1;
	for(int i=0;i<m;i++)	scanf("%d",&a[i]);
	for(int i=1;i<=s;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	f[0]=1;
	for(int i=m-1;~i;i--)
		for(int j=s-1;j;j--)
			for(int k=0;k<n;k++){
				int d=1<<k;
				if(!(j&d))	continue;
				f[j]=(f[j]+f[j^d]*A(s-a[i]-j+d,d-1)%P*d)%P;
			}
	long long ans=fac[s-1];
	for(int i=1;i<s;i++){
		int ty=1;
		for(int j=0;j<n;j++)
			if(i>>j&1)	ty=-ty;
		ans=(ans+ty*fac[s-i-1]*f[i]%P+P)%P;
	}
	printf("%lld\n",ans*s%P);
	return 0;
}


Measured memory_bytes: 1536