akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,W;
    int we[1010],va[1010],dp[110][10010];
    cin >> n >> W;
    for(int i=0;i<n;i++){
        cin >> va[i] >> we[i];
    }
    for(int w=0;w<=W;w++){
        dp[0][w]=0;
    }
    for(int i=0;i<n;i++){
        for(int w=0;w<=W;w++){
            if(w>=we[i]){
                dp[i+1][w]=max(dp[i][w-we[i]]+va[i],dp[i][w]);
            }
            else dp[i+1][w]=dp[i][w];
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}



Measured memory_bytes: 7060
#!/usr/local/bin/python3.5 -tt

import fractions
import random
import sys

if __name__ == '__main__':
    def _(f):
        for l in f:
            for i in l.split():
                yield int(i)

    g = _(sys.stdin)

    N = next(g)

    lcm = 1

    for i in range(N):
        T = next(g)

        lcm = lcm * T // fractions.gcd(lcm, T)

    print(lcm)


Measured memory_bytes: 6108
package main

import (
	"fmt"
)

// go run ./main.go < in
func main() {
	var towerNum, roadNum int
	fmt.Scan(&towerNum, &roadNum)

	towerStatus := []int{}
	towerOriginal := []int{}

	for i := 1; i <= towerNum; i++ {
		var towerHeight int
		fmt.Scan(&towerHeight)
		towerStatus = append(towerStatus, towerHeight)
		towerOriginal = append(towerOriginal, towerHeight)
	}

	for i := 0; i < roadNum; i++ {
		var roadA, roadB int
		fmt.Scan(&roadA, &roadB)
		if towerOriginal[roadA-1] == towerOriginal[roadB-1] {
			towerStatus[roadA-1] = 0
			towerStatus[roadB-1] = 0
		} else if towerOriginal[roadA-1] > towerOriginal[roadB-1] {
			towerStatus[roadB-1] = 0
		} else {
			towerStatus[roadA-1] = 0
		}
	}

	count := 0
	for _, v := range towerStatus {
		if v != 0 {
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 8716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD= 1e9+7;

vector<ll> fact_inv, inv;
 

void init_nCk(ll SIZE) {
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < SIZE + 5; i++) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}

ll nCk(ll n, ll k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    ll ans = 1;
    for (ll i = n; i >= n - k + 1; i--) {
        ans *= i;
        ans %= MOD;
    }
    return ans * fact_inv[k] % MOD;
}

ll modPow(ll a, ll n) {
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}


int main(){
    ll n,a,b;
    cin >> n >> a >> b;

    init_nCk(max(a,b));

    ll ans = modPow(2,n) -nCk(n,a)-nCk(n,b)-1;
    while(ans < 0){
        ans += MOD;
    }

    cout << ans << endl;


}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<ll> path;
    vector<bool> used(n);
    auto dfs = [&](auto &&self, ll v, ll p) -> void {
        path.push_back(v);
        used[v] = true;
        for(auto to: g[v]) {
            if(!used[to]) {
                self(self, to, v);
                break;
            }
        }
    };

    vector<ll> ans;
    ll idx0 = 0, idx1 = g[0][0];
    used[idx0] = used[idx1] = true;

    dfs(dfs, idx0, -1);
    reverse(ALL(path));
    ans = path;

    path.clear();
    dfs(dfs, idx1, -1);
    for(auto i: path) ans.push_back(i);

    cout << ans.size() << "\n";
    REP(i, ans.size()) cout << ans[i]+1 << (i+1==ans.size() ? '\n' : ' ');

    return 0;
}

Measured memory_bytes: 10060
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(void){
	unsigned short *A, *B;
	
	int C[VMAX + 1];
	int n, i, j;
	scanf("%d",&n);
	
	A = malloc(sizeof(short)* n + 1);
	B = malloc(sizeof(short)* n + 1);
	
	for ( i = 0; i <= VMAX; i++ ) C[i] = 0;
	
	for ( i = 0; i < n; i++ ){
		scanf("%hu", &A[i + 1]);
		C[A[i + 1]]++;
	}
	
	for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i-1];
	
	for ( j = 1; j <= n; j++ ){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for ( i = 1; i <= n; i++ ){
		if( i > 1 ) printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 9536
#include <iostream>
#include <vector>
#include <algorithm>
#define N 100005
using namespace std;
int  d[N];
vector<int> a;
vector<int> prime;
void Prime(){
	for(int i=2;i<N;i++){
		if(d[i]) continue;
		prime.push_back(i);
		for(int j=2;j*i<=N;j++)
			d[j*i]=1; 
	}
}
int main(){
	int n;
	cin>>n;
	Prime();
	for(int i=n;;i++)
		if(!d[i]){
			cout<<i<<endl;
			break;
		}
	return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cmath>
#include<algorithm>
#define neko 100010
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
int n,m,t,ciru,cirv,ans,tp,flag;
struct node
{int v,nex;}e[neko<<1];
typedef int arr[neko];
arr num,dep,head,fa,s;
void add(int x,int y)
{
	e[++t].v=y,e[t].nex=head[x],head[x]=t;
	e[++t].v=x,e[t].nex=head[y],head[y]=t;
}
void dfs(int u)
{
	num[u]=((dep[u]=dep[fa[u]]+1)&1)?1:-1;
	for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)
	{
		if(v^fa[u])
		{
			if(dep[v]){if(!flag)ciru=u,cirv=v,flag=1;}
			else fa[v]=u,dfs(v),num[u]+=num[v];
		}
	}
}
void solve_odd()
{
	if(num[1]&1){ans=-1;return;}
	int fix=-num[1]/2,x;
	ans=abs(fix);
	for(x=ciru;x;x=fa[x])num[x]+=fix;
	for(x=cirv;x;x=fa[x])num[x]+=fix;
	f(i,1,n)ans+=abs(num[i]);
}
void solve_even()
{
	if(num[1]){ans=-1;return;}
	for(int x=ciru;x^cirv;x=fa[x])s[++tp]=num[x],dep[x]=0;
	//网上一些Solution没flag标记，可能最终会导致最后找到的那条环边一定是从上往下的，所以他们写的从cirv跳到ciru才是正确的。
	int mid=(tp+1)>>1,now;
	std::nth_element(s+1,s+mid,s+tp+1);
	if(tp&1)now=s[mid];
	else now=(s[mid]+s[mid+1])/2;
	ans=abs(now);
	f(i,1,n)if(dep[i])ans+=abs(num[i]);
	f(i,1,tp)ans+=abs(s[i]-now);
}
int main()
{
	int x,y;
	scanf("%d%d",&n,&m);
	f(i,1,m)scanf("%d%d",&x,&y),add(x,y);
	dfs(1);
	if(m==n-1)if(num[1])ans=-1;else f(i,1,n)ans+=abs(num[i]);
	else if((dep[ciru]-dep[cirv]+1)&1)solve_odd();
	else solve_even();
	return printf("%d\n",ans),0;
}

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

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

  string s;
  cin >> s;
  int y = stoi(s.substr(0, 2));
  int m = stoi(s.substr(2, 2));
  bool a = 1 <= y && y <= 12;
  bool b = 1 <= m && m <= 12;
  string ans;
  if (a) ans = b ? "AMBIGUOUS" : "MMYY"; 
  else ans = b ? "YYMM" : "NA";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
ss = len(s)
tt = len(t)
min = tt


for i in range(ss - tt + 1):
  count = 0
  for j in range(tt):
    if s[i+j] != t[j]:
      count += 1
  if min > count:
    min = count

print(min) 


Measured memory_bytes: 9108
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e7
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int N){
    vector<int>S;
    rep(i,N)if(bit & (1<<i))S.push_back(i);
    return S;
}

int main(){
    int n,m;cin>>n>>m;
    vector<vector<int>>sk(m);
    rep(i,m){
        int k;cin>>k;
        rep(j,k){
            int a;cin>>a;
            a--;
            sk[i].push_back(a);
        }
    }
    int res = 0;
    vector<int>p(m);
    rep(i,m)cin>>p[i];

    for(int bit=0;bit<(1<<n);bit++){
        vector<int>S = bitSearch(bit,n);
        bool f = true;
        rep(j,m){
            int cnt = 0;
            for(auto x:sk[j]){
                for(auto s:S){
                    if(x==s)cnt++;
                }
            }
            if(cnt%2!=p[j])f = false;
        }
        if(f)res++;
    }
    cout<<res;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double[] p = new double[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextDouble();
        }
        double[][] dp = new double[n+1][n+1];
        dp[0][0] = 1;
        for(int i = 1; i <= n; i++){
            dp[i][0] = (1 - p[i-1]) * dp[i-1][0];
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                dp[i][j] = p[i-1] * dp[i-1][j-1] + (1 - p[i-1]) * dp[i-1][j];
            }
        }
        double ans = 0;
        for(int i = n / 2 + 1; i <= n; i++){
            ans += dp[n][i];
        }
        System.out.println(ans);
    }
}


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

const int N=1e5+30;
typedef long long ll;
int n;
int a[N],b[N],c[N];
ll dp[N][5];
ll solve(int i,int last){
    if(i==n)return 0;
    int path1=-1 ,path2=-1,path3=-1;
    ll &ret=dp[i][last];
    if(~ret)return ret;
    if(last!=1){
        path1=a[i]+solve(i+1,1);
    }
    if(last!=2){
        path2=b[i]+solve(i+1,2);
    }
    if(last!=3){
        path3=c[i]+solve(i+1,3);
    }
    return ret=max(path1,max(path2,path3));

}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
    cout<<solve(0,4);

}



Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int cnt[101010];

int main(){
  int N; cin>>N;
  for(int i=1;i*i<=N;i++){
    for(int j=1;j*j<=N;j++){
      for(int k=1;k*k<=N;k++){
        cnt[i*i+j*j+k*k+i*j+i*k+j*k]++;
      }
    }
  }
  for(int i=1;i<=N;i++) cout<<cnt[i]<<endl;
  return 0;
}

Measured memory_bytes: 3816
N = gets.to_i
a = gets.split(' ').map(&:to_i)
a.unshift(0)
ballin = []
check = Array.new(N + 1, 0)

N.downto(1) do |i|
	if i > N / 2 && a[i] == 1
		ballin.unshift(i)
		check[i] = 1
	else
		mul = []
		t = N / i
		n = 0
		t.downto(2) do |j|
			n += 1 if check[i * j] == 1
		end
		if n & 1 != a[i]	
			ballin.unshift(i)
			check[i] = 1
		end
	end
end
cnt = ballin.size
puts cnt
if cnt > 0
	puts ballin.join(' ')
end

Measured memory_bytes: 23124
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main()
{
    ll n, h;
    cin >> n >> h;
    ll maxstrike=0;
    ll a[n+10];
    for(ll i=0; i<n; i++)
    {
        ll strike, throww;
        cin >> strike >> throww;
        if(strike>maxstrike)
            maxstrike = strike;
        a[i]=throww;
    }
    ll c = 0;
    sort(a, a+n, greater<int>());
    for(ll i=0; i<n; i++)
    {
        if(h<=0)
            break;
        if(a[i]>maxstrike) // substitute with normal strike otherwise
        {
            h-=a[i];
            c++;
        }
        else
            break;

    }
    if(h>0)
    {
        ll y = h/maxstrike;
        if(h%maxstrike!=0)
            y++;
        c+=y;
    }
    cout << c;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int n;

ll modpow(ll x, ll y) {
  ll v = 1;
  REP(i,y) {
    v *= x; v %= MOD;
  }
  return v;
}

// 包除原理解法
void solve1() {
  ll p1 = modpow(10, n);
  ll p2 = (modpow(9, n) * 2) % MOD;
  ll p3 = modpow(8, n);
  ll ans = p1 - (p2 - p3);
  ans %= MOD;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

// DP解法
int dp[1000010][2][2]; // [N][0を含むかどうか][9を含むかどうか]

void solve2() {
  dp[0][0][0] = 1;
  REP(i,n) {
    REP(j,2) {
      REP(k,2) {
        REP(x,10) {
          int nj = j | x == 0;
          int nk = k | x == 9;
          dp[i+1][nj][nk] += dp[i][j][k];
          dp[i+1][nj][nk] %= MOD;
        }
      }
    }
  }
  cout << dp[n][1][1] << endl;
}

int main() {
  cin >> n;
  // solve1();
  solve2();

  return 0;
}

Measured memory_bytes: 19116
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,i,j,k,m,l;
	cin>>n;
	ll arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	k=0;
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(i!=j)
			{
				k+=(arr[i]*arr[j]);
			}
		}
	}
	cout<<k<<"\n";
	return 0;
}
	

Measured memory_bytes: 3584
ss=input()
tt=input()
s=[]
t=[]
for i in ss:
    s.append(i)
for i in tt:
    t.append(i)
sss=sorted(s)
ttt=sorted(t)
ssss=""
tttt=""
for i in sss:
    ssss+=i
for i in range(len(ttt)):
    tttt+=ttt[len(ttt)-i-1]
if ssss<tttt:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ALL(a)  (a).begin(),(a).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define DEBUG(x) cerr<<#x<<": "<<x<<endl
#define PB push_back
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long LL;

//#define vdebug(v) REP(iiii,v.size()){ cout<<#v<<"["<<iiii<<"]: "<<v[iiii]<<endl; }}

int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

class Vertex;
class Point;

class Vertex{
public:
	int me;//自分
	bool mada;//既に見られたか
	int num;//番号
	vector<Point> c;//子供
	Vertex(){
		me=-1;
		num = INT_MAX;
		mada=true;
	}
};

class Point{
public:
	int n;//番号
	int w;//重み
	Point(){
		n=-1;
		w=0;
	}
	Point(int n_, int w_){
		n=n_;
		w=w_;
	}
};

int main(){
	int N,M;
	cin>>N>>M;
	vector<Vertex> a(N);
	REP(i,N){
		a[i].me=i;
	}

	//グラフを作る
	REP(i,M){
		int L,R,D;
		cin>>L>>R>>D;
		a[L-1].c.push_back(Point(R-1,D));
		a[R-1].c.push_back(Point(L-1,-D));
	}

	/*
	REP(i,N){
		cout<<"a["<<i<<"] = ";
		for(auto item: a[i].c){
			cout<<"("<<item.n<<" "<<item.w<<") ";
		}
		cout<<a[i].mada;
		cout<<endl;
	}
	*/

	bool dame=false;

	//BFS
	while(true) {
		//まだ見ていない連結成分があったら見に行く
		auto rootitr = find_if( a.begin(), a.end(), [](Vertex& x){ return x.mada && (x.c.size()!=0); });
		if(rootitr == a.end()){
			break;
		}
		int root=rootitr-a.begin();
		//debug(root);
		queue<int> q;
		for(q.push(root); !q.empty(); q.pop()){
			int k = q.front();
			REP(i, a[k].c.size()){
				if(a[a[k].c[i].n].mada){
					a[a[k].c[i].n].num = a[k].num + a[k].c[i].w;
					a[a[k].c[i].n].mada=false;
					q.push(a[k].c[i].n);
				} else {
					int tmp = a[k].num + a[k].c[i].w;
					if(tmp != a[a[k].c[i].n].num){
						dame=true;
						//break;
					}
				}
			}
			//if(dame) break;
		}
		//if(dame) break;
	}

	if(dame){
		cout<<"No"<<endl;
	} else {
		cout<<"Yes"<<endl;
	}
	return 0;
}


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

int main(){
    int n;
    double kisuu;
    cin >> n;
    if (n % 2 == 1){
        kisuu = ( double (n) / 2 ) + 0.5 ;
    }else{
        kisuu = n / 2;
    }
    double ans = double(kisuu) / n ;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  ll l = 0, r = 10000000000000;
  while(r-l>1){
    ll mid = (l+r)/2;
    ll need_s = max(mid - n, (ll)0);
    ll t = m - need_s*2;
    if(t>=mid*2) l = mid;
    else r = mid;
  }
  std::cout << l << '\n';
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    private static readonly Scanner sc = new Scanner();
    private const int INF = 1010101010;
    static void Main(string[] args)
    {
        int n = sc.Int;
        int a = sc.Int;
        int b = sc.Int;
        long[] vn = new long[n];

        for (int i = 0; i < n; i++)
            vn[i] = sc.Long;

        vn = vn.OrderBy(e => -e).ToArray();

        int cnt = vn.Where(e => e == vn[a - 1]).Count();

        vn = vn.Take(a).ToArray();
        double ave = (double) vn.Sum() / a;

        int cnti = vn.Where(e => e == vn[a - 1]).Count();

        long ans = 0;
        if (vn[0] == vn[a - 1])
        {
            for (int i = a; i <= Math.Min(cnt, b); i++)
                ans += Comb(cnt, i);
        }
        else
        {
            ans = Comb(cnt, cnti);
        }

        Console.WriteLine(ave);
        Console.WriteLine(ans);
    }

    static long Comb(int n, int k)
    {
        if (k == 1) return n;
        if (n == k) return 1;
        if (comb_table[n, k] != 0) return comb_table[n, k];
        return comb_table[n, k] = Comb(n-1, k) + Comb(n-1, k-1);
    }

    private static long[,] comb_table = new long[51, 51];
}

class Scanner
{
    private string[] _str = new string[0];
    private int _i;

    public string Str
    {
        get
        {
            if (_i >= _str.Length)
            {
                _str = Console.ReadLine().Split(' ');
                _i = 0;
            }
            return _str[_i++];
        }
    }

    public int Int { get { return int.Parse(Str); } }
    public long Long { get { return long.Parse(Str); } }
    public double Double { get { return double.Parse(Str); } }
}

Measured memory_bytes: 13524
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n,x;
cin>>n>>x;
ll tmp;
ll a[n];
for(ll i=0;i<n;i++){
    cin>>tmp;
    a[i]=fabs(tmp-x);
}
ll ans=a[0];
for(ll i=1;i<n;i++){
    ans=gcd(ans,a[i]);
}
cout<<ans<<endl;
}









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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int n, q;

int a[maxn], b[maxn];

// bbbbbb
//a
//a
//a
//a


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

    cin>>n>>q;

    ll black = 1ll*(n-2)*(n-2);

    for (int i=1; i<=n; i++) {
	a[i]=n;
	b[i]=n;
    }

    int h = n;
    int w = n;


    while (q--) {
	int t, x;
	cin>>t>>x;
	if (t==1) {
	    if (x < w) {
		// We block off all future row updates from interfering with columns [x,w).
		// So we just have the current height for those columns.
		for (int i=x; i<w; i++) {
		    b[i] = h;
		}
		w = x;
	    }
	    black -= (b[x]-2);
	} else {
	    if (x < h) {
		for (int i=x; i<h; i++) {
		    a[i] = w;
		}
		h = x;
	    }

	    black -= (a[x]-2);
	}
    }

    cout<<black<<endl;    
    return 0;
}


Measured memory_bytes: 5232
#include <stdio.h>

int main() {
  int n, m, l;
  scanf("%d%d", &n, &m);
  for (l = m/n; l>0; l--) {
    int r = m - l*n;
    if (r%l==0) {
      printf("%d\n", l);
      return 0;
    }
  }
  return 0;
}


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


int main(){
    int N; cin >> N;
    int ans = 1;
    string W[100] = {};
    for (int i = 0; i < N; i++) cin >> W[i];

    for (int i = 0; i < N-1; i++){
        if (W[i][W[i].size() - 1] != W[i + 1][0]){
            ans = 0;
        }
    }

    for (int i = 0; i < N; i++){
        for (int j = i + 1; j < N; j++){
            if(W[i] == W[j]){
                ans = 0;
            }
        }
    }
    
    if (ans == 1){
        cout << "Yes" << endl;
    }
    else if (ans == 0)
    {
        cout << "No" << endl;
    }
    return 0;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long INF = 1e13;
#define fi first
#define sec second 
#define MOD 1000000007
#define pb push_back
#define endl "\n"
#define test cout<<"debuged\n";

#define si 1000000
#define pi pair<ll,ll>

ll dp[3010][3010];
ll vis[3010][3010];
 vector<ll> v(si,0);
ll solve(ll s,ll e,ll n,ll c)
{
  if(s>e)
   return 0;
 if(vis[s][e]==1)
    return dp[s][e];
  if(c==1)
  {
    ll h=(-1*INF);
    ll k= max(solve(s+1,e,n,c*-1)+v[s],solve(s,e-1,n,c*-1)+v[e]);
      vis[s][e]=1;
     dp[s][e]=max(k,h);
    return dp[s][e];
  }
  else
  {
    ll h=(INF);
    ll a= solve(s+1,e,n,c*-1)-v[s];
    ll b= solve(s,e-1,n,c*-1)-v[e];
    a=min(a,h);
      vis[s][e]=1;
    dp[s][e]=min(a,b);
    return dp[s][e];
  }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    ll n,k,s=0;
    cin>>n;
    for(ll i=0;i<n;i++)
      cin>>v[i];
   
    for(ll i=0;i<3010;i++)
      for(ll j=0;j<3010;j++)
        vis[i][j]=0;

    ll p=solve(0,n-1,n,1);  
    cout<<p;
}


Measured memory_bytes: 149504
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    x = ans = 0
    for s in S:
        if s == 'I':
            x += 1
            if x > ans:
                ans = x
        else:
            x -= 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9092
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> one = nextStrArray();
		double N = Double.parseDouble(one.get(0));
		double M = Double.parseDouble(one.get(1));
		double D = Double.parseDouble(one.get(2));
		double output = (D == 0) ? (1 / N) : (2 * (N - D) / N / N);
		myout(output * (M - 1));
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33348
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    sort(V.begin(), V.end());
    double sum = (V[0] + V[1]) / 2.0;
    rep(i,2,N){
        sum = (sum + V[i]) / 2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import copy

n = int(input())
MOD = 10**9+7

dp = [[[[0]*(5) for i in range(5)] for i in range(5)] for i in range(n+1)]

dp[0][0][0][0] = 1
# A:1, C:2, G:3, T:4
for cn in range(1, n+1):
    for c3 in range(5):
        if cn <= 3 and c3 > 0:
            continue
        for c2 in range(5):
            if cn <= 2 and c2 > 0:
                continue
            for c1 in range(5):
                if cn == 1 and c1 > 0:
                    continue
                
                if c2 == 1 and c1 == 3: # AGX
                    dp[cn][c2][c1][1] = (dp[cn][c2][c1][1] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][2] = 0
                    dp[cn][c2][c1][3] = (dp[cn][c2][c1][3] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][4] = (dp[cn][c2][c1][4] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                elif c2 == 1 and c1 == 2: # ACX
                    dp[cn][c2][c1][1] = (dp[cn][c2][c1][1] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][2] = (dp[cn][c2][c1][2] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][3] = 0
                    dp[cn][c2][c1][4] = (dp[cn][c2][c1][4] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                elif c2 == 3 and c1 == 1: # GAX
                    dp[cn][c2][c1][1] = (dp[cn][c2][c1][1] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][2] = 0
                    dp[cn][c2][c1][3] = (dp[cn][c2][c1][3] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][4] = (dp[cn][c2][c1][4] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                elif c3 == 1 and c1 == 3: # AXGY        
                    dp[cn][c2][c1][1] = (dp[cn][c2][c1][1] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][2] = 0
                    dp[cn][c2][c1][3] = (dp[cn][c2][c1][3] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][4] = (dp[cn][c2][c1][4] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                elif c3 == 1 and c2 == 3: # AGXY        
                    dp[cn][c2][c1][1] = (dp[cn][c2][c1][1] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][2] = 0
                    dp[cn][c2][c1][3] = (dp[cn][c2][c1][3] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][4] = (dp[cn][c2][c1][4] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                else:
                    dp[cn][c2][c1][1] = (dp[cn][c2][c1][1] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][2] = (dp[cn][c2][c1][2] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][3] = (dp[cn][c2][c1][3] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    dp[cn][c2][c1][4] = (dp[cn][c2][c1][4] + copy.deepcopy(dp[cn-1][c3][c2][c1])) % MOD
                    
total = 0
for c3 in range(1, 5):
    for c2 in range(1, 5):
        for c1 in range(1, 5):
            total = (total + dp[n][c3][c2][c1]) % MOD
print(total)

Measured memory_bytes: 78308
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

ll llpow(ll a, ll b){
  ll ret = 1;
  for (ll i = 0; i<b; i++) ret *= a;
  return ret;
}

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  bool f = (a + b < c) && ((ll)4 * a * b < llpow(c - a - b, 2));
  cout << (f? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()

if S == "RRR":
    print(3)
elif S == "RRS":
    print(2)
elif S == "SRR":
    print(2)
elif S == "RSR":
    print(1)
elif S == "SRS":
    print(1)
elif S == "RSS":
    print(1)
elif S == "SSR":
    print(1)
else:
    print(0)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
int main() {
  int A, B, count = 0; cin >> A >> B;
  for(int i = A; i <= B; i++) {
    string s = to_string(i);
    string t = s; reverse(t.begin(), t.end());
    if(s == t) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

struct edge {int to, cost; };

vector<edge> G[100005];
vector<int> color;

void dfs(int v, int c, int p=-1) {
  for (edge u : G[v]) {
    if (u.to == p) continue;
    if(u.cost%2==1){
      color[u.to]=1-c;
      dfs(u.to, 1-c, v);
    } else {
      color[u.to]=c;
      dfs(u.to, c, v);
    }
  }
}



int main(){
  int n, u, v, w;
  cin >> n;
  color.resize(n);
  rep(i, n-1){
    cin >> u >> v >> w;
    --u; --v; w%=2;
    edge a, b;
    a.to=v; a.cost=w;
    b.to=u; b.cost=w;
    G[u].push_back(a);
    G[v].push_back(b);
  }
  color[0]=0;
  dfs(0, 0);
  rep(i, n){
    cout << color[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

string rd(string c,int x,int y)
{
    int n = c.size();
    string str;
    int cnt = 0;

    for(int i = 0; i < n; i++){
        if(i == x || i == y){
            continue;
        }else{
            str[cnt] = c[i];
        }
    }
    return str;
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    int a = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == ')'){
            cnt++;
        }else{
            cnt--;
        }
        a = max(a,cnt);
    }
    string ans;
    for(int i = 0; i < abs(a); i++){
        ans += '(';
    }
    ans += s;
    int b = 0;
    cnt = 0;
    for(int i = 0; i < ans.size(); i++){
        if(ans[i] == '('){
            cnt++;
        }else{
            cnt--;
        }
    }
    for(int i = 0 ; i < cnt; i++){
        ans += ')';
    }
    cout << ans;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

struct edge{
  int from;
  int to;
  ll cost;
};

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

  int N, M;
  cin >> N >> M;

  vector<edge> E(M);

  ll a, b, c;
  for(int i = 0; i < M; i++){
    cin >> a >> b >> c;
    a--;
    b--;
    E[i].from = a;
    E[i].to   = b;
    E[i].cost = -c;
  }

  vector<ll> d(N);
  for(int i = 0; i < N; i++){
    d[i] = INF;
  }

  d[0] = 0;
  bool is_negative = false;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){

      edge e = E[j];

      if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
        d[e.to] = d[e.from] + e.cost;
        if (i == N-1 && e.to == N-1) {         //頂点の数と同じ回数ループすると、負の閉路があるのでループをぬける
            is_negative = true;
            break;
        } 
      }
    }
  }

  if(is_negative){
    cout << "inf" << endl;
  }else{
    cout << -d[N-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(Math.min(a, b) + Math.min(c, d));
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) cout << "Alice" << endl;
	else cout <<"Borys" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8[:], i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] >= key:
            ok = mid
        else:
            ng = mid

    return ok


@nb.njit("i8(i8, i8[:])", cache=True)
def solve(N, L):
    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            c = binary_search(L, L[a] + L[b]) - 1
            ans += c - b
    return ans


def main():
    N = int(input())
    L = np.array(input().split(), dtype=np.int64)

    ans = solve(N, L)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 106984
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    a = na()
    a.sort()

    tmp = []
    for i, ai in enumerate(a):
        if i % 2:
            tmp.append(ai)
        else:
            tmp.append(24 - ai)
    tmp.append(0)
    tmp.append(24)
    tmp.sort()
    ans = INF
    for i in range(len(tmp) - 1):
        ans = min(ans, tmp[i + 1] - tmp[i])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
//const ll mod=1e9+7;
const ll mod=998244353;

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

vector<pair<ll,ll>> xd(mx);
vector<bool> used(mx,false);
vector<int> v[mx];

ll dfs(int x){
  used[x] = true;
  mint tmp = 1;
  for(auto it:v[x]){
    tmp *= dfs(it);
  }
  return tmp.x+1;
}

int main(){
  int n;
  cin >> n;
  xd.resize(n);  
  rep(i,n){
    cin >> xd[i].F >> xd[i].S;
  }
  sort(xd.begin(),xd.end());
  set<P> st;
  for(int i=n-1; i>=0; i--){
    while(!st.empty() && st.begin()->F < xd[i].F+xd[i].S){
      v[i].emplace_back(st.begin()->S);
      st.erase(st.begin());
    }
    st.insert(P(xd[i].F,i));
  }

  mint ans = 1;
  rep(i,n)if(!used[i]){
    ans *= dfs(i);
  }
  cout << ans.x << ln;
  return 0;
}

Measured memory_bytes: 26740
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var S = ReadLine();
            var ans = 0;
            var cnt = 0;
            for(var i=0;i<3;i++)
            {
                if (S[i] == 'R')
                {
                    cnt++;
                    ans = Math.Max(ans, cnt);
                }
                else cnt = 0;
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17560
#include <iostream>
#include <cctype>
using std::cout;
using std::cin;
using std::endl;

int counter[26] = {};

void printChars()
{
	int i;
	char a;
	for (i = 0; i < 26; i++)
	{
		a = i + 'a';
		cout << a << " : " << counter[i] << endl;
	}
}

int main()
{
	char c;
	int num;
	while (cin >> c)
	{
		c = tolower(c);
		num = c - 'a';
		if (0 <= num && num <= 25) counter[num]++;
	}
	printChars();
	return 0;
}

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

int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll f = 0;
    //ll ans = 0;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }
    if(b == 2){
        cout << a/2 << endl;
        return 0;
    }
    if(n<b){
        cout <<  (a*n)/b-a*(n/b) << endl;
        return 0;
    }
    else{
        if(a%b == 0){
            cout << a+(-a/b) << endl;
            return 0;
        }
        else{
            cout << a+(-a/b)-1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    long long N;
    cin >> N;
    vector<long long> A(N), X(N);
    long long S = 0;
    for (long long i=0; i<N; i++) {
        cin >> A[i];
        S += A[i];
    }
    
    X[0] = S;
    for (long long i=1; i<N; i++) {
        if (i%2==1) {
            X[0] -= 2*A[i];
        }
    }
    for (long long i=1; i<N; i++) {
        X[i] = (2*A[i-1]) - X[i-1];
    }
    for (long long i=0; i<N; i++) {
        cout << X[i] << ' ';
    }
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;

int main() {
  int N;
  cin >> N;
  int ans = N % 10;
  if (ans == 3) {
    cout << "bon" << endl;
  }
  else if (ans < 2 || ans == 6 || ans == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
package main

import (
	"os"
	"fmt"
	"bufio"
	"strconv"
	"strings"
)

func main() {
	var sc     = bufio.NewScanner(os.Stdin)
	sc.Scan()
	var N, _   = strconv.Atoi(sc.Text()) // 参加人数
	sc.Scan()
	var DX     = strings.Split(sc.Text(), " ")
	var D, _   = strconv.Atoi(DX[0]) // 日数
	var X, _   = strconv.Atoi(DX[1]) // 最後に残ったチョコの数
	var A      = make([]int, N) // 参加者の情報

	for i := 0; i < N; i++ {
		sc.Scan()
		A[i], _  = strconv.Atoi(sc.Text())
	}
	
	var ans = X
	for i := 0; i < N; i++ {
		var day = 1
		var cnt = 0
		for j := 1; day <= D; j++ { 
			cnt++
			day = (j * A[i]) + 1
		}
		ans += cnt
	}

	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <string>
#include <list>

using namespace std;



int min(char* s) {
	int n = 0;
	int sum = 0, tmpI = 0;
	bool flag = true;
	list<int> intlist;

	for(int i = 0; s[i] != '\0'; i++) {
		if(s[i] == '[') {
			int count = 1, j;
			for(j = 1; count != 0; j++) {
				if(s[j + i] == '[') {
					count += 1;
				} else if(s[j + i] == ']') {
					count -= 1;
				}
			}
		//cout << "Weeeei" << endl;
			char* tmpS = new char[10000];
			strncpy(tmpS, s+i+1, j-2);
			tmpS[j-2] = '\0';
			//cout << tmpS << endl;
			int x = min(tmpS);
			intlist.push_back( x );
			n++;
			flag = false;
			i = i + j-1;
			delete[] tmpS;
		}
	}
	if(flag) {
		tmpI = atoi(s);
		//cout << tmpI << endl;
		return tmpI / 2 + 1;
	}

	intlist.sort();

	list<int>::iterator itr = intlist.begin();
	for(int i = 0; i < n/2 + 1; itr++, i++) {
		sum += *itr;
	}

	/*
	bool flag = true;
	for(int i = 0; s[i] != '\n'; i++) {
		if(s[i] == '[') {
			if(!flag) {
				string s2;
				for(int j = 0; s[j] != ']' && s[j + 1] != ']'; j++) {
					strncpy(s2, s+i, j-i+1);
				}
				min(s2);
			} else {
				n++:
				flag = false;
			}
		}
	}

	int[] input = new input[n];
	int j = 0;
	for(int i = 0; s[i] != '\n'; i++) {
		if(s[i] == '[') {
			;
		} else if(s[i] == ']') {
			input[j] = tmpI;
			tmpI = 0;
		} else {
			tmpI = tmpI * 10 + atoi(c);
		}
	}
	sort(input);
	for(int i = 0; i < n/2 + 1; i++) {
		sum = input[i] / 2 + 1;
	}
	*/

	return sum;
}


int main (void) {
	int n;
	cin >> n;
	
	//cout << "ok" << endl;
	for (int i = 0; i < n; i++) {
		char* s = new char[10002];
		//char c;
		//int j = 0;
		/*for( ; cin >> c && (c != '\n' && c != '\0'); j++) {
			s[j] = c;
		}
		s[j] = '\0';
		*/
		cin >> s;
		//cout << s;
		//cout << "abon" << endl;

		cout << min(s) << endl;
		delete[] s;

	}
}

Measured memory_bytes: 1348