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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

vll G[100100];

ll ng;
bool reachable[100100];
void dfs(ll v, ll p){
  reachable[v]=true;
  for(auto nv: G[v]){
    if(nv==ng) continue;
    if(nv==p) continue;
    dfs(nv,v);
  }
}

ll dist[100100];
void dfs2(ll v, ll p, ll c){
  dist[v]=c;
  for(auto nv: G[v]){
    if(nv==p) continue;
    dfs2(nv,v,c+1);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,u,v; cin>>n>>u>>v;
  u--,v--;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  queue<pll> q;
  q.emplace(u,-1);
  q.emplace(v,-1);
  vb visited(n);
  visited[u]=visited[v]=true;
  while(!q.empty()){
    auto p=q.front(); q.pop();
    ll v=p.first, parent=p.second;
    bool flg=false;
    for(auto nv: G[v]){
      if(nv==parent) continue;
      if(visited[nv]){
        ng=nv;
        flg=true;
        break;
      }else{
        visited[nv]=true;
        q.emplace(nv,v);
      }
    }
    if(flg) break;
  }
  
  dfs(u,-1);
  dfs2(v,-1,0);
  
  // rep(i,n) cout<<reachable[i]<<endl;
  // rep(i,n) cout<<dist[i]<<endl;
  
  ll ans=0;
  rep(i,n){
    if(reachable[i]){
      chmax(ans,dist[i]-1);
    }
  }
  cout<<ans<<endl;
  
}


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

int main(){
    ll n;
    cin >> n;
    ll total = 0;
    rep(i,n){
        ll x = i+1;
        if((x%5 != 0) && (x%3 != 0)){
            total += x;
        }
    }

    cout << total << endl;
    
} 

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
#define int long long
#define MOD 1000000007
int gcd(int a,int b){
  if(a==0){
    return b;
  }
  return gcd(b%a,a);
}
int lcm(int a,int b){
  return a*b/gcd(a,b);
}
int keta(int a){
  int count = 0;
  while(a!=0){
    a = a/10;
    count++;
  }
  return count;
}
signed main(){
  int n;
  cin >> n;
  float a[n];
  float b[n];
  float wa = 0;
  rep(i,n){
    cin >> a[i];
    b[i]=1/a[i];
    wa = wa + b[i];
  }
  cout << 1/wa << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a[100001];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;


	scanf("%d %d", &n,&m);
	for (int i = 0; i < n; i++)a[i] = 0;
	for (int i = 0; i < m; i++){
		scanf("%d %d", &x,&y);
		a[x - 1]++;
		a[y - 1]++;
	}
	for (int i = 0; i < n; i++){
		if (a[i] % 2 == 1){
			printf("NO\n");
			return 0;
		}
	}

	printf("YES\n");
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<int> V(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> V[i];
    }
    for (int i = 0; i < N; ++i) {
        int c;
        cin >> c;
        V[i] -= c;
    }
    sort(V.begin(), V.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (V[i] > 0) {
            ans += V[i];
        }
        else {
            break;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3556
from itertools import permutations
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

ret = [i for i in range(1, n + 1)]
a = 0
b = 0
perm_list = permutations(ret)
for i, j in enumerate(perm_list):
    if p == list(j):
        a = i
    if q == list(j):
        b = i

print(abs(a-b))

Measured memory_bytes: 3064
S = list(input())
K = int(input())

N = len(S)
first = S[0]
last = S[-1]
now = 1
ing = 0
a = []
cnt = 1
flag = 0
if N > 1:
    while now < N:
        if S[now] == S[now-1]:
            ing = 1
            cnt += 1
            now += 1
            continue
        else:
            if ing ==1:
                a.append(cnt)
                cnt = 1
                now +=1
                ing = 0
            else:
                now +=1
                cnt = 1
                ing = 0
    if ing ==1:
        a.append(cnt)

    output = 0
    for j in range(len(a)):
        output += a[j]//2

    if first==last:
        if S[0]==S[1]:
            if S[-1]==S[-2]:
                X =a[0]
                Y =a[-1]
            else:
                X = a[0]
                Y = 1
        else:
            if S[-1]==S[-2]:
                X = 1
                Y =a[-1]
            else:
                X = 1
                Y = 1

        if (X==1)and(Y==1):
            output += 1
            flag = 1
        elif X==1:
            if Y%2==1:
                output+=1
                flag = 1
        elif Y==1:
            if X%2==1:
                output+=1
                flag = 1
        else:
            if (X%2==1)and(Y%2==1):
                output += 1
                flag = 1

    output = output * K - flag
    if (len(a)==1)and(a[0]==N):
        output = (K*N)//2
elif N == 1:
    output = K//2

print(output)

Measured memory_bytes: 3188
fun main(args: Array<String>) {
    val values = readLine()!!.split(" ").map(String::toInt)

    var result = 10000000;
    for ((i, v1) in values.withIndex()) {
        for ((j, v2) in values.withIndex()) {
            if (i == j) continue

            if (result > (v1 + v2)) {
                result = v1 + v2
            }
        }
    }

    println(result)
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v) {
    for (auto &e:u) fill_v<T>(e, v...);
}

int64 calc(string s) {
    int64 res = 0;
    vector<int64> cnt(8, 0);
    string fest = "FESTIVAL";
    REP(i, s.size()) {
        int64 id = fest.find(s[i]);
        if (id == 0) {
            cnt[id]++;
        } else if (id < 7) {
            cnt[id] += cnt[id-1];
        } else {
            res += cnt[6];
        }
    }
    return res;
}

int main(void) {
    int64 K;
    cin >> K;
    vector<int64> cnt(7, 0);
    vector<PLL> card;
    REP(i, 7) cnt[i] = 1;
    card.emplace_back(cnt.back(), 1);
    int64 sum = 7;
    int64 add = 1;
    while (card.back().fs*add < INF_LL) {
        while (1) {
            vector<int64> cnt2(cnt);
            cnt2[0] += add;
            FOR(i, 1, 7) {
                cnt2[i] += cnt2[i-1]* add;
            }
            if (cnt2.back() >= card.back().fs*(add+1)) {
                swap(cnt, cnt2);
                card.emplace_back(cnt.back(), add);
                sum += add * 7;
                break;
            } else {
                add++;
            }
        }
    }
    card.emplace_back(2*INF_LL, INF_LL);
    vector<int64> L;
    while (K) {
        int64 id = upper_bound(all(card), PLL(K, INF_LL))- card.begin();
        id--;
        K -= card[id].fs;
        L.push_back(id);
    }
    string fest = "FESTIVAL";
    string res = "";
    int64 idx = 0;
    reverse(all(L));
    REP(i, card.size()-1) {
        REP(j, 7) {
            res += string(card[i].sc, fest[j]);
        }
        while (idx < L.size() && L[idx] == i) {
            res += "L";
            idx++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, 10 ** 6 + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

def main():
    n, k = map(int, input().split())
    if k >= n-1:
        return cmb(2*n-1, n, mod) % mod
    else:
        t = 0
        for i in range(k+1):
            t += cmb(n, i, mod) * cmb(n-1, i, mod) 
            t %= mod
        return t
print(main())



Measured memory_bytes: 127700
#include<iostream>
#include<set>
#include<cmath>
#include<vector>
#define MAX 300000
using namespace std;
vector<int> vms;
vector<int> vmsp;
bool bvms[MAX];

void MakeVMS(){
  int n = 0;
  do{
    vms.push_back( 7*n+1 );
    bvms[ 7*n+1 ]=true;
    vms.push_back( 7*n+6 );
    bvms[ 7*n+6 ]=true;
    ++n;
  }while(vms.back()<MAX);
}

void MakeVMSP(){
  for(int i = 1; i < vms.size(); ++i){
    //cout << vms[i] << endl;
    bool bvsmp=true;
    for(int j = 1; j < i && vms[j] <= sqrt(vms[i]); ++j){
      if( vms[i] % vms[j] == 0 && bvms[vms[i]/vms[j]] ){
	bvsmp=false;
	break;
      }
    }
    if(bvsmp){
      //cout << vms[i] << endl;
      vmsp.push_back( vms[i] );
    }
  }
}

void solve(int n){
  set<int> anss;
  for(int i = 0; i < vmsp.size(); ++i){
    if( n % vmsp[i] == 0 ){
      anss.insert( vmsp[i] );
    }
  }
  for(set<int>::iterator its=anss.begin(); its!=anss.end(); ++its){
    cout << " " << *its;
  }
  cout << endl;
}
int main(){
  MakeVMS();
  MakeVMSP();
  while(true){
    int n;
    cin>>n;
    if(n==1){
      break;
    }
    cout << n << ":";
    solve(n);
  }
  return 0;
}

Measured memory_bytes: 1944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
const ll mod = 1e9+7;

int n,m;

int main()
{
    int a,b;
    scanf("%d%d%d", &n, &a, &b);
    printf("%d\n", min(n*a, b));
    return 0;
}


Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import math


a,b = map(int, input().split())
s = str(input()).split("-")

if (len(s)==2) and (len(s[0])==a) and (len(s[1])==b):
  print("Yes")
else:
  print("No")

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

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (c % gcd(a, b)) cout << "NO" << '\n';
    else cout << "YES" << '\n';

    return 0;
}

Measured memory_bytes: 256
import itertools
N = int(input())
A = list(map(int, input().split()))
count = {}
for a in A:
  if a not in count:
    count[a] = 0
  count[a] += 1

def check(a):
  if count[a] > 1:
    return 0

  if 1 in count:
    if a == 1 and count[1] == 1:
      return 1
    return 0

  #print(a)
  ok = True
  sqr_a = 1 + int(a**0.5)
  for s in itertools.chain([2], range(3, sqr_a, 2)):
    if a % s:
      continue
    c = s
    while c < sqr_a:
      if a % c == 0 and (c in count or (a//c) in count):
        #print(a, c)
        ok = False
        break
      c *= 2
  return ok
  
ans = 0
for a in A:
  ans += check(a)
print(ans)
    
    



Measured memory_bytes: 122364
#include<stdio.h>//たてH cm よこ W cm の長方形を描くプログラム

int main(void){
 
	int a,b,i,j;

	while(1){
		scanf("%d %d",&a,&b);
		if(a==0&&b==0)
			break;
		for(i=0;i<a;i++){
			if(i%2==0){
				for(j=0;j<b;j++){
					if(j%2==0)
						printf("#");
					else printf(".");
				}
			}else {
				for(j=0;j<b;j++){
					if(j%2==0)
						printf(".");
					else printf("#");
				}
			}
				printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
n = int(input())
alp = ["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"]
name = ''
while n != 0:
    name += alp[(n-1) % 26]
    n = (n-1) // 26
print(name[::-1])

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define double long double
#define pb(a) push_back(a)
#define MAX (int)(pow(10,6) + 10)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,9);
ll modulo = pow(10,9)+7;


vector<ll> mult[MAX];
vector<ll> fw[MAX];
vector<ll> bc[MAX];
vector<ll> g[MAX];

void dfs1(ll hd, ll pr, ll m){
	mult[hd].pb(1);
	fw[hd].pb(1);
	for(auto hr : g[hd]){
		if(hr == pr)
			continue;
		dfs1(hr, hd, m);
		ll ans = fw[hr][fw[hr].size()-1] + 1;
		ans = ans % m;
		mult[hd].pb(ans);
		fw[hd].pb(fw[hd][fw[hd].size()-1] * ans % m);
	}
}

void dfs2(ll hd, ll pr, ll m){
	mult[hd].pb(1);
	fw[hd].pb(fw[hd][fw[hd].size()-1]);
	{
		ll n = fw[hd].size();	
		bc[hd].resize(n);
		bc[hd][n-1] = 1;
		for(ll i = n-2; i>-1; i--)
			bc[hd][i] = bc[hd][i+1] * mult[hd][i] % m;
	}
	ll index = 1;
	fori(g[hd].size()){
		auto hr = g[hd][i];
		if(hr == pr)
			continue;
		ll some_add_1 = fw[hd][index-1] * bc[hd][index+1] % m ;
		some_add_1 = (some_add_1 + 1) % m;
		mult[hr].pb(some_add_1);
		fw[hr].pb(fw[hr][fw[hr].size()-1] * some_add_1 % m);
		dfs2(hr, hd, m);
		++index;
	}
}
 
void deal(){
       ll n, m;
       cin>>n>>m;
       fori(n-1){
       	ll a , b;
       	cin>>a>>b;
       	--a, --b;
       	g[a].pb(b);
       	g[b].pb(a);
       } 
       dfs1(0, -1, m);
       dfs2(0, -1, m);
       fori(n)
       	cout<<fw[i][fw[i].size()-1]<<'\n';
}
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  deal();
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 120832
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;

const int maxn=1e4+5;
const ll INF=0x3f3f3f3f;
ll n,k;
int main(){
	cin>>n>>k;
	ll ans=0;
	for (ll b=n;b>k;b--){
		ll l=k,r=b-1;
		
		ll c=(n+1)/b;
		
		ans+=c*(r-l+1);
		if (l==0) ans--;
		
		l=k+c*b;
		if (l<=n){
			ans+=n-l+1;
		}
		
//		cout<<ans<<endl;
	}
	
	cout<<ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;

/*
最短路拆点，跑最短路；
*/

const int N=1e6+10;
const int INF=0x3f3f3f3f;

map<pair<int,int>,int>mp;

struct asd{
    int to;
    int w;
    int next;
};
int head[N*8],tol,dd;
asd q[N*8];
int num[N*8];
bool vis[N*8];
int dis[N*8];
int n,m;
int que[N];
int s,t;

int spfa()
{
    s=0;
    t=1;
    for(int i=1;i<=dd+1;i++)
    {
        dis[i]=INF;
        vis[i]=0;
        num[i]=0;
    }
    dis[1]=0;
    vis[1]=num[1]=1;
    que[s]=1;
    while(s<t)
    {
        int u=que[s];
        s++;
        vis[u]=0;
        for(int v=head[u];v!=-1;v=q[v].next)
        {
            int i=q[v].to;
            if(dis[i]>q[v].w+dis[u])
            {
                dis[i]=q[v].w+dis[u];
                if(!vis[i])
                {
                    num[i]++;
                    if(num[i]>=dd)
                        return -2;
                    vis[i]=1;
                    que[t]=i;
                    t++;
                }
            }
        }
    }
    if(dis[n]<INF)
        return dis[n]/2;
    else
        return -1;
}
int getid(int x,int y)
{
    if(mp.find({x,y})!=mp.end())
        return mp[{x,y}];
    return mp[{x,y}]=++dd;
}
void init()
{
    dd=n;
    tol=0;
    memset(head,-1,sizeof(head));
}
void add(int a,int b,int c)
{
    q[tol].w=c;
    q[tol].to=b;
    q[tol].next=head[a];
    head[a]=tol++;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        init();
        mp.clear();
        for(int i=0;i<m;i++)
        {
            int x,y,c;
            scanf("%d%d%d",&x,&y,&c);
            int xx=getid(x,c);
            int yy=getid(y,c);
            add(xx,yy,0);
            add(yy,xx,0);
            add(x,xx,1);
            add(xx,x,1);
            add(y,yy,1);
            add(yy,y,1);
        }
        printf("%d\n",spfa());
    }

    return 0;
}

Measured memory_bytes: 85120
#include<cstdio>
#include<algorithm>
#define Powered using
#define by namespace
#define Wshine std;
Powered by Wshine
 
long long k,n,a[200000],i,cnt=0,cot[200001]={0},j,x[200001],y=0,ans=0;
int vis[200001];
int main()
{
	scanf("%lld %lld",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		cot[a[i]]++;
		if(vis[a[i]]==0)
		{
			vis[a[i]]=1;
			cnt++;
		}
	}
	
	//printf("¹²ÓÐ %lld ¸ö²»Í¬µÄÊý×Ö\n",cnt);
	
	if(cnt<=k)
	{
		printf("0");
	}
	else
	{
		sort(cot,cot+n+1);
		for(i=0;i<n;i++)
		{
			if(cot[i]==0)
			{
				continue;
			} 
			else
			{
				//printf("cot[%lld] = %lld\t",i,cot[i]);
				
				x[y]=cot[i];
				
				//printf(" NOW x[%lld] = %lld\n",y,x[y]);
				
				y++;
			}
		}
		for(i=0;i<(cnt-k);i++)
		{
			ans+=x[i];
		} 
		printf("%lld",ans);
	}
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>

using namespace std;

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

    if(a>=13){
        cout << b << endl;
    }else if(a <= 12 & a >= 6){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S=[]
for _ in range(N):
    S.append(input())

print("AC x " + str(S.count("AC")))
print("WA x " + str(S.count("WA")))
print("TLE x " + str(S.count("TLE")))
print("RE x " + str(S.count("RE")))

Measured memory_bytes: 16276
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int M, N = 1, K;

signed main(){
    cin >> M >> K;
    for(int i = 0; i < M; i++){
        N *= 2;
    }
    if(K == 0){
        for(int i = 0; i < N; i++){
            printf("%lld %lld", i, i);
            if(i < N - 1)printf(" ");
        }
        printf("\n");
        return 0;
    }
    if(M < 2 || N <= K){
        printf("-1\n");
        return 0;
    }
    
    printf("%lld ", K);
    for(int i = 0; i < N; i++){
        if(i != K){
            printf("%lld ", i);
        }
    }
    printf("%lld", K);
    for(int i = N - 1; i >= 0; i--){
        if(i != K){
            printf(" %lld", i);
        }
    }
    printf("\n");



    return 0;
}
/*


*/

Measured memory_bytes: 1792
def main():
    if sub():
        print("Yay!")
    else:
        print(":(")


def sub() -> bool:
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    points = [a, b, c, d, e]
    k = int(input())

    for i in points:
        for j in points:
            if abs(i - j) <= k:
                continue
            else:
                return False
    return True


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    ll nn = n * (n + 1) / 2;

    auto sa = atcoder::suffix_array(s);
    auto lcp = atcoder::lcp_array(s, sa);
    for (ll x : lcp) {
        nn -= x;
    }
    cout << nn << endl;

}


Measured memory_bytes: 15628
import java.util.Scanner;

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

        sc.close();
        if (r < 1200) {
            System.out.println("ABC");
        } else if (r < 2800) {
            System.out.println("ARC");
        } else {
            System.out.println("AGC");
        }

    }
}


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

int main(){
  int k;
  cin >> k;
  string str;
  cin >> str;
  if(str.length()<=k){
    cout << str << endl;
  }
  else{
    for(int i=0;i<k;i++){
      cout << str[i];
    }
    cout << "..." << endl;
  }
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N;
	cin >> N;
	vector<uint64_t> a(N);
	vector<vector<uint64_t>> su(N, vector<uint64_t>(N, 0));
	vector<vector<uint64_t>> dp(N, vector<uint64_t>(N, numeric_limits<uint64_t>::max()));

	for (auto& ai : a)
		cin >> ai;

	forn(i, N)
	{
		su[i][i] = a[i];
		fore(j, i + 1, N - 1)
			su[i][j] = su[i][j - 1] + a[j];
	}

	forn(i, N)
		dp[i][i] = 0;
		
	fore(len, 1, N-1)
	{
		forn(i, N-len)
		{
			int j = i + len;
			fore(k, i, j - 1)
			{
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + su[i][k] + su[k + 1][j]);
			}
		}
	}
	cout << dp[0][N - 1] << endl;
	return 0;
}


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

using namespace std;

int main() {
    int x, y, s;

    while (cin >> x >> y >> s) {
        if (x == 0 && y == 0 && s == 0) { break; }
        int ans = 0;

        for (int i = 1; i < s; i++) {
            for (int j = 1; j < s; j++) {
                if (int(i * (100 + x) / 100.0) + int(j * (100 + x) / 100.0) == s) {
                    ans = max(ans, int(i * (100 + y) / 100.0) + int(j * (100 + y) / 100.0));
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define int long long 
using ldb = long double;
using pa = pair < int, int >;
#define F  first
#define S  second
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>q(n);
    map<int,int>maps;
    int ans = 0;
    f(i,0,n){
        cin >> q[i];
        maps[q[i]]++;  
    }
    for(auto s:maps){
    	ans += (s.S*(s.S-1)/2);
    }
   	// cout << ans << endl;
    f(i,0,n){
    	cout << ans - (maps[q[i]]-1) << endl; 
    }
    
    
    return 0;
}
 

Measured memory_bytes: 12288
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		
		if(N%2 == 0) System.out.println((double)(N/2)/N);
		else System.out.println((double)(N/2+1)/N);

	}

}

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

int mini[21][21];
const int Inf = 1e5;

int main(){

    int n,m;
    cin >> n >> m;

    for(int i=0;i<=n;++i){
        for(int j=0;j<=n;++j){
            if(i == j)mini[i][j] = 0;
            else mini[i][j] = Inf;
        }
    }

    for(int i=0;i<m;++i){
        int a,b,c,d;
        scanf("%d,%d,%d,%d",&a,&b,&c,&d);
        mini[a][b] = c;
        mini[b][a] = d;
    }

    int s,g,v,p;
    scanf("%d,%d,%d,%d",&s,&g,&v,&p);

    for(int k=1;k<=n;++k){
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                mini[i][j] = min(mini[i][j],mini[i][k]+mini[k][j]);
            }
        }
    }

    cout << v - (p+mini[s][g]+mini[g][s]) << endl;

    return 0;
}


Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
string str;
ll a[3];
int main(void){
    // Your code here!
    cin >> str;
    for (ll i = 0; i < str.length(); i++) a[str[i] - 'a']++;
    sort(a, a + 3);
    if (a[2] - a[0] > 1) cout << "NO" << endl;
    else cout << "YES" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n,L,a[300],ans=-1e9,cur=1e9;
int main()
{
    go;
    cin>>n>>L;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        a[i]=L+i-1;
        sum+=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cur=min(cur,abs(a[i]));
        if(cur==abs(a[i]))
            ans=sum-a[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
N,A,B=map(int, input().split())
a=[]

for i in range(N+1):
    j=i
    n=0
    while True:
        n+=i%10
        if i//10==0:
            break
        else:
            i=i//10
    if A<=n<=B:
        a.append(j)
    else:
        pass
print(sum(a))
        

Measured memory_bytes: 3408
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll n,x,t;
	cin >> n >> x >> t;
	if(n%x)
		cout << (n/x+1)*t << endl;
	else
		cout << n/x*t << endl;
}

Measured memory_bytes: 3592
from fractions import gcd
N,X=map(int, input().split())

x=list(map(int, input().split()))
L=[0]*N
for i in range(N):
    L[i]=abs(x[i]-X)
g=L[0]
for i in range(1,N):
    g=gcd(g,L[i])

print(g)

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

const ll INF = 1ll << 60;
ll MOD = 1000000007;
//ll MOD = 1000000007LL;

int main()
{

    string s;
    cin >> s;

    const int N = 13;
    vector<ll> dp(N);
    int mul = 1;
    dp[0] = 1;
    for (int i = s.length() - 1; i >= 0; --i)
    {
        vector<ll> nextDP(N);

        char c = s[i];
        if (c == '?')
        {
            for (int k = 0; k < 10; ++k)
            {
                for (int j = 0; j < N; ++j)
                {
                    nextDP[(k * mul + j) % N] += dp[j];
                    nextDP[(k * mul + j) % N] %= MOD;
                }
            }
        }
        else
        {
            int k = (int)(s[i] - '0');
            for (int j = 0; j < N; ++j)
            {
                nextDP[(k * mul + j) % N] += dp[j];
                nextDP[(k * mul + j) % N] %= MOD;
            }
        }
        mul *= 10;
        mul %= N;
        dp = nextDP;
    }
    cout << dp[5] << endl;

    return 0;
}

Measured memory_bytes: 512
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n ; scanf("%d",&n);
	vector<int> dp(3);
	
	for(int day = 0 ; day < n; day ++){
		vector<int> v(3) , newdp(3);
		for(auto &x : v ) scanf("%d",&x);
		
		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 3 ; j++){
				if(i != j)
					newdp[i] = max(newdp[i] , dp[j] + v[i] );
			}
		}
		dp = newdp;
	}
	printf("%d\n",max({dp[0],dp[1],dp[2]})) ;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*
lli power(lli x,lli y)
{
    lli res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
*/
int main()
{
//cout.precision(10);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   //freopen("input1.txt","r",stdin);
   //freopen("outputmid1.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli i,n,k,q,x,ans=0;
		cin>>n>>k>>q;
		lli arr[n]={0};
		for(i=0;i<q;i++)
		{
			cin>>x;
			arr[x-1]++;
		}
		for(i=0;i<n;i++)
		arr[i]=k-(q-arr[i]);
		for(i=0;i<n;i++)
		{
			if(arr[i]>0)
			cout<<"Yes"<<endl;
			else
			cout<<"No"<<endl;
		}
	}
}
/*
6
0 8 13 14 17 19
*/


Measured memory_bytes: 1408
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
  BC.append(list(map(int, input().split())))
BC = sorted(BC, key=lambda x:x[1],reverse=True)  
for b, c in BC:
  A.extend([c] * b)
  if len(A)>=2*N:
    break
A = sorted(A, reverse=True)
print(sum(A[:N]))

Measured memory_bytes: 37712
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


int main()
{
	string s;
	while(cin >> s)
	{
		vector<string> _s = split(s,',');
		vector<int> n;
		map<int,int> m;
		rep(i,_s.size())
		{
			n.push_back(atoi(_s[i].c_str()));
		}

		sort(n.begin(),n.end());
		
		rep(i,n.size())
		{
			m[n[i]]++;
		}

		if(m.size() == 2)
		{
			if(m[n[0]] == 1 || m[n[0]] == 4)
			{
				cout << "four card" << endl;
			}
			else
			{
				cout << "full house" << endl;
			}
		}

		else if(m.size() == 3)
		{
			bool flag = true;
			rep(i,n.size())
			{
				if(m[n[i]] == 3)
				{
					flag = false;
				}
			}

			if(flag)
			{
				cout << "two pair" << endl;
			}
			else
			{
				cout << "three card" << endl;
			}
		}

		else if(m.size() == 4)
		{
			cout << "one pair" << endl;
		}

		else if(m.size() == 5)
		{
			if(n[0] == 1 && n[1] == 10 && n[2] == 11 && n[3] == 12 && n[4] == 13)
			{
				cout << "straight" << endl;
			}
			else if(n[1] == n[0]+1 && n[2] == n[1]+1 && n[3] == n[2]+1 && n[4] == n[3]+1)
			{
				cout << "straight" << endl;
			}
			else
			{
				cout << "null" << endl;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 1216
// always test on samples :(
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
#define MAX_V 2000005

inline void mult(int &a, int b) {
    ll p = 1ll * a * b;
    if (p >= MOD) p %= MOD;
    a = (int)p;
}

//Fast Exponentiation
ll fexp(ll base, ll exp, ll mod) {
    if (base >= mod) base %= mod;
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) result = (result * base) % mod;
        exp >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

int fact[MAX_V], invfact[MAX_V];
int main() {
    int r1, c1, r2, c2; scanf("%d%d%d%d", &r1, &c1, &r2, &c2);

    fact[0] = 1;
    for (int i = 1; i < MAX_V; i++) {
        fact[i] = fact[i - 1];
        mult(fact[i], i);
    }

    invfact[MAX_V - 1] = fexp(fact[MAX_V - 1], MOD - 2, MOD);
    for (int i = MAX_V - 2; i >= 0; --i) {
        invfact[i] = invfact[i + 1];
        mult(invfact[i], i + 1);
    }

    int ans = 0;
    int cur = fact[r2 + c2 + 2];
    mult(cur, invfact[r2 + 1]);
    mult(cur, invfact[c2 + 1]);

    ans += cur;
    if (ans >= MOD) ans -= MOD;

    cur = fact[r2 + c1 + 1];
    mult(cur, invfact[r2 + 1]);
    mult(cur, invfact[c1]);

    ans += (MOD - cur);
    if (ans >= MOD) ans -= MOD;

    cur = fact[r1 + c1];
    mult(cur, invfact[r1]);
    mult(cur, invfact[c1]);

    ans += cur;
    if (ans >= MOD) ans -= MOD;

    cur = fact[r1 + c2 + 1];
    mult(cur, invfact[r1]);
    mult(cur, invfact[c2 + 1]);
    
    ans += (MOD - cur);
    if (ans >= MOD) ans -= MOD;

    ans %= MOD;
    if (ans < 0) ans += MOD;

    cout << ans;  
    return 0;
}

Measured memory_bytes: 15872
#include<queue>
#include<cstdio>
#include<cctype>
const int N=100007;
std::vector<int>e[N];std::queue<int>q;
int vis[N],mat[N],tam[N];
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
int dfs(int u,int root)
{
    for(int v:e[u]) if(vis[v]^root) if(vis[v]=root,!mat[v]||dfs(mat[v],root)) return mat[v]=u;
    return 0;
}
int main()
{
    int n=read();
    for(int i=1;i<n;++i) for(int j=read();j;--j) e[read()].push_back(i);
    for(int i=2;i<=n;++i) if(!dfs(i,i)) return puts("-1"),0;
    q.push(1);
    for(int i=1,u;i<=n;++i)
    {
	if(q.empty()) return puts("-1"),0;
	u=q.front(),q.pop();
	for(int v:e[u]) if(!tam[v]) tam[v]=u,q.push(mat[v]);
    }
    for(int i=1;i<n;++i) printf("%d %d\n",tam[i],mat[i]);
}


Measured memory_bytes: 8696
#include <stdio.h>          // printf(), getline()
#include <stdlib.h>         // exit(), malloc(), free(), strtol()
#include <string.h>         // memset()
#include <stdbool.h>
#include <errno.h>          // errno
#ifdef linux
 #include <error.h>         // error()
#endif

#define MAX_N 2000000
#define MAX_V 10000

const char NUL = '\0';
int lineno;
char* linebuff = NULL;
size_t linebuffsize = 0;

void
cleanup(int ecode)
{
	if (linebuff)
	{
		free(linebuff);
		linebuff = NULL;
		linebuffsize = 0;
	}

	exit(ecode);
}

bool
readline()
{
	errno = 0;
	if(getline(&linebuff, &linebuffsize, stdin) == -1) // read line
	{
		if(errno == 0)  // EOF?
			return false;

#ifdef linux
		error(0, errno, "Can't read line");
#else
		fprintf(stderr, "Can't read line\n");
#endif
		cleanup(1);
	}

	return true;
}

void
skip_sp(const char** p)
{
	while (**p == ' ')
		(*p)++;
}

int
main(int argc, char** argv)
{
	unsigned short *a, *b;
	int c[MAX_V + 1];
	char* nextp = NULL;
	int x;
	int n, i;

	readline();
	lineno = 1;
	const char* s = linebuff;
	n = strtol(s, &nextp, 10);
	s = nextp;

	a = malloc(sizeof(short) * n + 1);
	b = malloc(sizeof(short) * n + 1);
	memset(c, 0, sizeof(int) * MAX_V + 1);

	readline();
	s = linebuff;
	lineno++;

	int max = 0;
	for (i = 0; i < n; ++i)
	{
		skip_sp(&s);
		if (*s == NUL)
			cleanup(0);

		if (*s == '\n')
		{
			if (!readline())
				cleanup(0);

			lineno++;
			s = linebuff;
		}

		x = strtol(s, &nextp, 10);
		s = nextp;

		a[i + 1] = x;
		c[x]++;
		if (x > max)
			max = x;
	}

	for (i = 1; i <= max; ++i)
		c[i] = c[i] + c[i - 1];

	for (i = n; i >= 1; --i)
	{
		b[c[a[i]]] = a[i];
		c[a[i]]--;
	}

	for (i = 1; i <= n; ++i)
		printf("%d%c", b[i], (i != n) ? ' ' : '\n');

	free(a);
	free(b);
	return 0;
}

Measured memory_bytes: 17792
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner scan = new Scanner(System.in)) {

			int n = scan.nextInt();
			
			Integer[] l = new Integer[n];
			
			int ans = 0;
			for(int i=0; i<n; i++) {
				l[i] = scan.nextInt();
			}
			
			Arrays.sort(l, Comparator.reverseOrder());
			
			for(int i=0; i<n-2; i++) {
				for(int j=i+1; j<n-1; j++) {
					for(int k=j+1; k<n; k++)
					if(l[i] < l[j] + l[k]) {
						ans++;
					} else {
						break;
					}
				}
			}
			
			
			System.out.println(ans);
		}
	}
}

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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.141592653589793238462643383279;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} init;

// SegmentTree (0 - indexed)
// T: モノイド
template<typename T>
struct SegmentTree {
    int n;
    std::vector<T> data;

    // 要素数を指定して初期化
    SegmentTree(int n_) {
        n = 1;
        while (n < n_) { n <<= 1; }
        data.resize(2 * n, T());
    }

    // 元となるstd::vectorを用意して初期化
    SegmentTree(std::vector<T> source) {
        n = 1;
        while (n < source.size()) { n <<= 1; }
        data.resize(2 * n, T());
        std::copy(source.begin(), source.end(), data.begin() + n);
        for (int i = n - 1; i > 0; i--) { data[i] = data[2 * i] + data[2 * i + 1]; }
    }

    // [l, r)の区間和を取得
    T getSum(int l, int r) const {
        l += n, r += n;
        T ret = T();
        while (l < r) {
            if (l & 1) { ret += data[l], l++; }
            if (r & 1) { ret += data[r - 1]; }
            l >>= 1, r >>= 1;
        }
        return ret;
    }

    // 要素iをxに更新
    void update(int i, T x) {
        i += n;
        data[i] = x;
        while (i > 1) {
            i >>= 1;
            data[i] = data[2 * i] + data[2 * i + 1];
        }
    }
};

struct Magma {
    int val;

    Magma operator+(const Magma obj) {
        return Magma(min(val, obj.val));
    }

    Magma &operator+=(const Magma &obj) {
        val = (*this + obj).val;
        return *this;
    }

    Magma() : val(INT_MAX) {}

    Magma(int val) : val(val) {}
};

int N, x;
int a[2200], b[2200];
signed main() {
    cin >> N >> x;
    rep(i, N) { cin >> a[i]; }
    vector<Magma> aa;
    rep(i, N) { aa.push_back(a[i]); }
    rep(i, N) { aa.push_back(a[i]); }
    SegmentTree<Magma> st(aa);
    int ans = LLONG_MAX;
    rep(i, N) {
        int cur = i * x;
        rep(j, N) {
            cur += st.getSum(j - i + N, j + 1 + N).val;
        }
        chmin(ans, cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2,62);

int main(){
    ll n;cin >> n;
    ll mod = 1000000007;
    ll a = 10;
    rep(i, n-1){
        a = a*10;
        a = a%mod;
    }
    ll b = 8;
    rep(i,n-1){
        b = b*8;
        b = b%mod;
    }
    ll c = 9;
    rep(i,n-1){
        c = c*9;
        c = c%mod;
    }
    c = (2*c)%mod;
    ll ans = a - c + b;
    ans = ans%mod;
    cout << (ans+mod)%mod << endl;
}


Measured memory_bytes: 3596
import sys
from collections import Counter

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
A = rl()
A.sort(reverse=True)
c = Counter(A)
answer = 0
for x in A:
    target = (1 << x.bit_length()) - x
    while c[x] > 0:
        c[x] -= 1
        if c[target] > 0:
            c[target] -= 1
            answer += 1

print(answer)


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

fn main() {
    let input_string = read::<String>();
    let char_vec:Vec<char> = input_string.chars().collect();
    let mut prev_char = char_vec[0];
    for c in char_vec.into_iter().skip(1) {
        if prev_char == c {
            println!("Bad");
            return;
        }
        prev_char = c;
    }
    println!("Good");
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){	
	ll n;
	cin>>n;
	vector<ll>a(n);
	ll sum=0;
	rep(i,n){
		cin>>a[i];
		if(i%2==0)sum+=a[i];
		else sum-=a[i];
	}
	vector<ll>ans(n);
	ans[0]=sum;
	ll sub=a[0];
	for(int i=1;i<n;++i){
		sum-=a[i-1];
		sum*=-1;
		ans[i]=sum*2;
		if(i%2!=0)ans[i]+=ans[0];
		else ans[i]-=ans[0];
	}
	rep(i,n){
		if(i)cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
//#define INF (1e9+1)
#define INF (1LL<<59)

#define int ll

signed main(){
    int v,e;
    cin>>v>>e;
    int d[101][101];
    rep(i,101)rep(j,101)d[i][j] = INF;
    rep(i,101)d[i][i] = 0;
    
    
    rep(i,e){
        int s,t,c;
        cin>>s>>t>>c;
        d[s][t] = c;
    }
    
    rep(k,v){
        rep(i,v){
            rep(j,v){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    
    rep(i,v){
        if(d[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    
    rep(i,v){
        rep(j,v){
            if(j)cout<<" ";
            int res=d[i][j];
            if(res>=INF/2)cout<<"INF";
            else cout<<res;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3164
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_N (100005)
#define MOD (1000000007)
int N;
int T[MAX_N];
int A[MAX_N];

int main()
{
    scanf("%d", &N);
    for ( int i = 0; i < N; i++ ) {
	scanf("%d", &T[i]);
    }	

    for ( int i = 0; i < N; i++ ) {
	scanf("%d", &A[i]);
    }

    // 矛盾を探す
    bool contra = false;
    // 左から
    for ( int i = 0; i < N; i++ ) {
	if ( i == 0 ) {
	    if ( T[i] > A[i] ) {
		contra = true;
		break;
	    }
	}
	else {
	    if ( T[i] > T[i-1] ) {
		if ( T[i] > A[i] ) {
		    contra = true;
		    break;
		}
	    }
	}
    }

    // 右から
    for ( int i = N-1; i >= 0; i-- ) {
	if ( i == N-1 ) {
	    if ( A[i] > T[i] ) {
		contra = true;
		break;
	    }
	}
	else {
	    if ( A[i] > A[i+1] ) {
		if ( A[i] > T[i] ) {
		    contra = true;
		    break;
		}
	    }
	}
    }

    if ( contra ) {
	printf("0\n");
	return 0;
    }

    int max_n = A[0];
    int max_l = 0;
    int max_r = 0;

    for ( int i = 0; i < N; i++ ) {
	if ( T[i] == max_n ) {
	    max_l = i;
	    break;
	}
    }

    for ( int i = N-1; i >= 0; i-- ) {
	if ( A[i] == max_n ) {
	    max_r = i;
	    break;
	}
    }

    ll ans = 1;
    for ( int i = 1; i < max_l; i++ ) {
	if ( T[i] == T[i-1] ) {
	    ans *= T[i];
	    ans %= MOD;
	}
    }

    for ( int i = N-2; i > max_r; i-- ) {
	if ( A[i] == A[i+1] ) {
	    ans *= A[i];
	    ans %= MOD;
	}
    }

    for ( int i = max_l + 1; i < max_r; i++ ) {
	ans *= max_n;
	ans %= MOD;
    }

    printf("%lld\n", ans);

    return 0;
}


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

main()
{
    int n; cin>>n;
    int app[1<<20];
    fill(begin(app),end(app),-1);
    bool ok[1<<18];
    for(int i=0; i<n; i++)
    {
        ok[i]=true;
        int x; cin>>x;
        if(~app[x])
        {
            ok[app[x]]=false;
            ok[i]=false;
        }
        else
        {
            app[x]=i;
        }
    }
    for(int i=1; i<1<<20; i++)
    {
        if(~app[i])
        {
            for(int j=i*2; j<1<<20; j+=i)
            {
                if(~app[j]) ok[app[j]]=false;
            }
        }
    }

    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans+=ok[i];
    }
    cout << ans << "\n";

}


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

int main(){

  int n;

  while(cin >> n && n){

    int judge[4] = {0}, cnt = 1, step = 0;
    string str;

    for(int i = 0; i < n; i++){ 
      cin >> str;
      if(str == "lu"){
	if(judge[0] == 0){
	  judge[0] = 1;
	  judge[2] = 0;
	}
	else{
	  judge[0] = 0;
	  judge[2] = 1;
	}
      }else  if(str == "ru"){
	if(judge[1] == 0){
	  judge[1] = 1;
	  judge[3] = 0;
	}
	else{
	  judge[1] = 0;
	  judge[3] = 1;
	}
      }else  if(str == "ld"){
	if(judge[2] == 0){
	  judge[2] = 1;
	  judge[0] = 0;
	}
	else{
	  judge[2] = 0;
	  judge[0] = 1;
	}
      }else  if(str == "rd"){
	if(judge[3] == 0){
	  judge[3] = 1;
	  judge[1] = 0;
	}
	else{
	  judge[3] = 0;
	  judge[1] = 1;
	}
      }
      if(judge[0] == 1 && judge[1] == 1 && judge[2] == 0 && judge[3] == 0 && cnt % 2 == 1){
	cnt++;
	step++;
      }else if(judge[0] == 0 && judge[1] == 0 && judge[2] == 1 && judge[3] == 1 && cnt % 2 == 0){
	cnt++;
	step++;
      } 

    }
    cout << step << endl;

  }

  return 0;
}

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

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

    vector<vector<int>> abc(n+1, vector<int>(3));
    vector<vector<int>> dp(n+1, vector<int>(3));

    rep(i, 3){
        abc[0][i] = 0; //いらないかも
        dp[0][i] = 0;
    }

    rep(i, n) rep(j, 3) cin >> abc[i+1][j];
    //入力を入れてあげた．

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

    int ans;

    ans = max(dp[n][0], max(dp[n][1], dp[n][2]));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136