akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


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

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n,m;
cin>>n>>m;

ll di[n+1];
rep(i,n){
	di[i]=-1;
}

rep(i, m){
ll s,c;
cin>>s>>c;

if(di[s]!=-1 && di[s]!=c) {
	cout<<-1<<endl;
	return 0;
}

di[s]=c;

}

ll all=0;
rep(i, n){
	if(i==1 && di[i]==0 &&n!=1){
		cout<<-1<<endl;
		return 0;
	}
		if(i==1 && di[i]==0 &&n==1){
		cout<<0<<endl;
		return 0;
	}
if(i==1 && di[i]==-1 &&n!=1){
	di[i]=1;
	continue;
}
if(i==1 &&di[i]==-1 && n==1){
	cout<<0<<endl;
	return 0;
}
if(di[i]==-1){di[i]=0;
continue;}
}

ll ans=0;
rep(i, n){
ans+=di[i]*modpow(10,n-i,100000000000);
}

cout<<ans<<endl;
return 0;


}




Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=[]
a.sort()
b.sort()
c.sort()
def binary_search1(list,item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if low == high:
            if guess >= item:
                return mid
            else:
                return mid +1
        if guess >= item:
            high = mid
        else:
            low = mid + 1

def binary_search2(list,item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if low == high:
            if guess > item:
                return n-mid
            else:
                return n-1-mid
        if guess > item:
            high = mid
        else:
            low = mid + 1

ans=0
#print(a,b,c)
for i in range(n):
    #print(binary_search1(a,b[i]),binary_search2(c,b[i]),i)
    ans+=binary_search2(c,b[i])*binary_search1(a,b[i])

print(ans)

Measured memory_bytes: 29488
#include <stdio.h>
#define N 100000

int A[N];

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void partition(int p, int r){
  int x = A[r];
  int i = p - 1, j;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      swap(&A[i], &A[j]);
    }
  }
  swap(&A[i+1], &A[r]);
  for(j=p;j<=r;j++){
    if(j!= p) printf(" ");
    if(j == i+1) printf("[%d]", A[j]);
    else printf("%d", A[j]);
  }
  printf("\n");
}

main(){
  int n, i;
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &A[i]);
  partition(0, n-1);
  return 0;
}

Measured memory_bytes: 800
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == '?':
        break

    if op == '+':
        print(a + b)

    if op == '-':
        print(a - b)

    if op == '*':
        print(a *b)

    if op == '/':
        print(a // b)

Measured memory_bytes: 7660
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<100000;++i){
        if(int(i*1.08)==n){
            cout<<i;
            return 0;
        }
    }
    cout<<":(";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;

int main() {
	int n, h, w;
	cin >> n >> h >> w;
	vector<int>a(n), b(n);
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] >= h && b[i] >= w) {
			count++;
		}

	}
	cout << count << endl;
}
	

Measured memory_bytes: 256
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/23.
//  Copyright © 2019 yuya. All rights reserved.
//

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

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

Graph G;
vector<int> colvec;

void coloring(int v, int p, int c);

int main()
{
    int i;
    int N;
    int u,v,w;
    
    cin >> N;
    
    colvec.assign(N, 0);
    G.assign(N, vector<Edge>() );
    
    for(i=0;i<N-1;i++){
        cin >> u >> v >> w;
        u--;
        v--;
        
        G[u].push_back(Edge(v,w));
        G[v].push_back(Edge(u,w));
    }
    
    coloring(0,-1,0);
    for(auto c : colvec) cout << c << endl;
  
    return 0;
}

void coloring(int v, int p, int c)
{
    colvec[v] = c;
    for(Edge e : G[v]){
        if(e.first == p) continue;
        if(e.second & 1){
            coloring(e.first, v, !c);
        } else {
            coloring(e.first, v, c);
        }
    }
}



Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N, D; cin >> N >> D;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ll X, Y; cin >> X >> Y;
		if (X*X + Y * Y <= D * D) ans++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3600
//まずは、自明なケースを考える。
//・まず、長方形の対角線は2等分するので、対角線上の点ではWH/2が答え。
//・そして、対角線の交点（中心）を通る直線Lも2等分するので、L上の点ではWH/2が答え。
//・さらに、Lの集合は長方形全体を覆うので、任意の点でWH/2が答え。
//・中心は明らかに分割の仕方が複数ある。
//・中心以外について、中心を通らない直線は面積を2等分できない（要証明）ので、分割の仕方は1通り。
#include <iostream>
#define int long long
using namespace std;

int w, h, x, y;

signed main() {
	cin >> w >> h >> x >> y;
	printf("%.14f %d\n", w * h * 0.5, (x * 2 == w && y * 2 == h));
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"unicode"
)

func main() {
	var s string
	fmt.Scan(&s)
	if isUpper(s) {
		fmt.Println("A")
	} else {
		fmt.Println("a")
	}
}

func isUpper(v string) bool {
	r := rune(v[0])
	return unicode.IsUpper(r)
}

Measured memory_bytes: 1772
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

bool nibu;
vector<int> v[1010];
int a[1010];

void dfs(int x){
    for(auto to : v[x]){
        if(a[to]==-1){
            a[to]=!a[x];
            dfs(to);
        }
        else if(a[to]==a[x])nibu=false;
    }
}

void solve(int n,int m){
    rep(i,n){
        v[i].clear();
        a[i]=-1;
    }
    rep(i,m){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    nibu=true;
    a[0]=0;
    dfs(0);
    if(!nibu){
        cout<<0<<endl;
        return;
    }
    int s=0,t=0;
    rep(i,n){
        if(a[i])++s;
        else ++t;
    }
    set<int> ans;
    if(s%2==0)ans.insert(s/2);
    if(t%2==0)ans.insert(t/2);
    cout<<ans.size()<<endl;
    for(auto e : ans)cout<<e<<endl;
}

int main(){
    int n,m;
    while(cin>>n>>m,n)solve(n,m);
    return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include <algorithm>
#include <string>

int main()
{
  int N, L;
  std::cin >> N >> L;
  std::string S[N];
  for ( int i = 0; i < N; i++ ) std::cin >> S[i];
  std::sort(S, S+N);
  for ( int i = 0; i < N; i++ ) std::cout << S[i];
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string s;
    cin >> s;
    vector<int> b,w;
    for (int i = 0; i < (int)s.size(); i++){
        if (s[i] == 'B'){
            b.push_back(i);
        } else {
            w.push_back(i);
        }
    }
    sort(w.rbegin(), w.rend());
    int min_size;
    if ((int)b.size() < (int)w.size()){
        min_size = (int)b.size();
    } else {
        min_size = (int)w.size();
    }

    ll sum = 0;
    for (int i = 0; i < min_size; i++){
        if (w[i] - b[i] > 0){
            sum += w[i] - b[i];
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1660
n=int(input())
for i in range(n):
    ball=list(map(int,input().split()))
    b=0
    c=0
    flag=0
    for j in ball:
        if b>j and c>j:
            flag=1
            break
        elif b>j or j-c<j-b:
            c=j
        else:
            b=j
    print('YNEOS'[flag::2])


Measured memory_bytes: 5596
n=int(input())
a=list(map(int,input().split()))
counter = [0] * (10**5+1)
for i in a:
  counter[i] += 1
q=int(input())
res=sum(a)
for i in range(q):
  b,c=map(int,input().split())
  res += counter[b]*(c-b)
  counter[c] += counter[b]
  counter[b]=0
  print(res)

Measured memory_bytes: 21040
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 2333
typedef long long ll;
const ll inf=1LL<<50;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,cnt[N],S,T,vis[N],id[33][33],tot,Q,e_cnt,head[N];
ll dis[N];
vector<pair<ll,ll> > vec,ans;
struct Jew{
	int s,p;
	ll c;
	bool operator <(const Jew b)const{
		return s<b.s;
	}
}a[33][33];
queue<int> q;
struct Edge{
	int to,nxt,val;
	ll cost;
}edge[N<<6];
void Add(int a,int b,int c,ll d){
	edge[++e_cnt]={b,head[a],c,d};
	head[a]=e_cnt;
}
void adde(int a,int b,int c,ll d){
	Add(a,b,c,d),Add(b,a,0,-d);
}
bool SPFA(){
	memset(dis,0x3f,sizeof(dis));
	dis[S]=0,vis[S]=1;
	q.push(S);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		vis[u]=0;
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(edge[i].val&&dis[v]>dis[u]+edge[i].cost){
				dis[v]=dis[u]+edge[i].cost;
				if(!vis[v]){
					q.push(v),vis[v]=1;
				}
			}
		}
	}
	return dis[T]<inf;
}

int dfs(int u,int limit){
	if(u==T)return limit;
	int flow=0;
	vis[u]=1;
	for(int i=head[u];i&&limit;i=edge[i].nxt){
		int v=edge[i].to;
		if(edge[i].val&&dis[v]==dis[u]+edge[i].cost&&!vis[v]){
			int k=dfs(v,min(edge[i].val,limit));
			edge[i].val-=k;
			edge[i^1].val+=k;
			limit-=k;
			flow+=k;
		}
	}
	vis[u]=0;
	if(!flow)dis[u]=inf;
	return flow;
}
void Dinic(){
	int maxflow=0;
	while(SPFA()){
		maxflow=dfs(S,1e9);
		vec.emplace_back(dis[T],maxflow);
		if(maxflow>5e8)break;
	}
}
 main(){
	n=read(),e_cnt=1,S=998,T=S+1;
	for(int i=1;i<=n;++i){
		cnt[i]=read();
		for(int j=1;j<=cnt[i];++j){
			a[i][j].s=read(),a[i][j].p=read(),a[i][j].c=read();
		}
		sort(a[i]+1,a[i]+cnt[i]+1);
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=cnt[i]-1;++j){
			id[i][j]=++tot;
		}
		id[i][0]=S,id[i][cnt[i]]=T;
		for(int j=1;j<=cnt[i];++j){
			adde(id[i][j-1],id[i][j],a[i][j].p,0);
			adde(id[i][j-1],id[i][j],1e9,a[i][j].c);
		}
	}
	m=read();
	for(int i=1;i<=m;++i){
		int u=read(),v=read(),w=read();
		int k=1;
		for(int j=1;j<=cnt[v];++j){
			while(k<=cnt[u]&&a[u][k].s+w<a[v][j].s)++k;
			adde(id[v][j-1],id[u][k-1],1e9,0);
		}
	}
	Dinic();
	ll x=0,y=0;
	for(auto &t:vec){
		ans.emplace_back(x,y);
		x+=t.second;
		y+=t.first*t.second;
	}
	Q=read();
	while(Q--){
		ll A=read();
		int i=lower_bound(vec.begin(),vec.end(),make_pair(A,(ll)-inf))-vec.begin();
		printf("%lld\n",i==ans.size()?-1LL:ans[i].first*A-ans[i].second);
	}
	return 0;
}



Measured memory_bytes: 3872
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

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

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll res = a[0];
    for(int i=1;i<n;i++){
        res = gcd(res,a[i]);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
from heapq import heappop, heappush
from bisect import bisect
from collections import deque
inf = 10**5


N, M = map(int,input().split())
info = [list(map(int,input().split())) for _ in range(N)]
info = deque(sorted(info))

ans = 0
hq = []

for i in range(M-1,-1,-1):
    index = bisect(info, [M-i,inf])
    for _ in range(index):
        A, B = info.popleft()
        heappush(hq, -B)
    if hq:
        B = -heappop(hq)
        ans += B

print(ans)

Measured memory_bytes: 29276
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    string n;cin>>n;
    ll a=0;
    ll s =n.size();
    rep(i,s) {
        int k=(int)(n[i]-'0');
        a=(a+k)%9;
    }
    if(a==0) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<string> ss(n);
	vector<int> ts(n);
	FOR_LT(i, 0, n) {
		cin >> ss[i];
		cin >> ts[i];
	}

	string sl; cin >> sl;

	int ans = 0;
	bool is_s = false;
	FOR_LT(i, 0, n) {
		if (is_s) {
			ans += ts[i];
		}
		if (sl == ss[i]) is_s = true;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;
    bool f1 = 1, f2 = 1;
    for(int i = a; i < c; i++){
        if (s[i] == '#' && s[i+1] == '#') f1 = 0;
    }
    for(int i = b; i < d; i++){
        if (s[i] == '#' && s[i+1] == '#') f2 = 0;
    }

    if (c < d){
        if (f1&&f2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        bool f3 = 0;
        for(int i = b; i <= d; i++){
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') f3 = 1;
        }
        if (f1&&f2&&f3) cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}


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

#define ALL(obj) (obj).begin(), (obj).end()
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<=b; i++)
#define drep2(i,a,b) for(int i=a; i>=b; i--)
#define pb push_back


struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main()
{
  int n, q;
  cin >> n >> q;
  // unite 1
  // same  0
  
  struct UnionFind a(n);
  vector<int> c(q), x(q), y(q);
  rep(i,q) {
    cin >> c[i] >> x[i] >> y[i];
    if (c[i] == 0) {
      a.unionSet(x[i], y[i]);;
    } else {
      cout << a.findSet(x[i], y[i]) << endl;
    }
  }


}


Measured memory_bytes: 4024
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        a: i32, b: i32,
    }

    let min = (b as f64 / 0.10).floor() as i32;
    let max = (a as f64 / 0.08).ceil() as i32;
    let (min, max) = (min.min(max), max.max(min));

    if min > max {
        println!("-1");
    } else {
        for i in min..=max {
            if (i as f64 * 0.08) as i32 == a && (i as f64 * 0.10) as i32 == b {
                println!("{}", i);
                return;
            }
        }
        println!("-1");
    }
}


Measured memory_bytes: 2684
L=[]

while True:
    A=int(input())
    
    if A==0:
        break
    
    else:
        for i in  reversed (range(1001)):
            if A>=10**i:
                B=A//10**i
                A-=B*10**i
                L.append(B)

                
            else:
                L.append(0)

        print(sum(L))
        L=[]


Measured memory_bytes: 5600
(function(input) {
    var p = input.replace(/\n$/, '').split('\n');
    for (var i = 0; i < p.length; i++) {
        var args = p[i].split(' ').map(Number);
        var a = args[0];
        var b = args[1];
        var gcd = greatestCommonDivisor(a, b);
        var lcm = leastCommonMultiple(a, b);
        console.log('%s %s', gcd, lcm);
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function greatestCommonDivisor(a, b) {
    if (b > a) {
        var tmp = a;
        a = b;
        b = tmp;
    }
    if (b == 0) {
        return a;
    }
    return greatestCommonDivisor(a % b, b);
}

function leastCommonMultiple(a, b) {
    return a * b / greatestCommonDivisor(a, b);
}

Measured memory_bytes: 7904
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,v,o[100005]={},e[100005]={};
  cin >> n;
  map<int,int> mo;
  map<int,int> me;
  for(int i=0; i<n; i++) {
    int a;
    cin >> a;
    if((i+1)%2==1) {
      mo[a]++;
    }
    else {
      me[a]++;
    }
  }
  int Me=0,Mo=0,ei,oi,o2=0,e2=0;
  for(auto p:mo) {
    if(Mo<p.second) {
      o2=Mo;
      Mo=p.second;
      oi=p.first;
    }
    else {
      o2=max(o2,p.second);
    }
  }
  for(auto p:me) {
    if(Me<p.second) {
      e2=Me;
      Me=p.second;
      ei=p.first;
    }
    else {
      e2=max(e2,p.second);
    }
  }
  if(ei==oi) {
    cout << min(n-Me-o2,n-e2-Mo) << endl;
  }
  else {
    cout << n-Me-Mo << endl;
  }
}

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

int main() {
  int N, S = 0;
  cin >> N;
  vector<int> vec(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  vec.at(N) = 500;
  sort(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
    if (vec.at(i) < vec.at(i+1)) S += 1;
  }
  
  cout << S << endl;
}

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

long long powa(int n){
  int i,prod=1;
  for(i=0;i<n;i++)prod*=10;
  return prod;
}

long long pow2(int n){
  int i,prod=1;
  for(i=0;i<n;i++)prod*=2;
  return prod;
}

long long erase(long long A,int n,int k){
  return A%(powa(n-k));
}

long long f(long long A,int n){
  int i,j;
  long long cnt,sum=0;
  int a[n];
  for(i=0;i<n;i++){
    a[n-i-1]=(A/powa(i))%10;
  }
  sum+=A;
  for(i=1;i<n;i++){
    cnt=0;
    for(j=0;j<i;j++){
      cnt+=powa(i-j-1)*a[j];
    }
    sum+=cnt*pow2(n-i-1);
  }
  for(i=1;i<n;i++){
    sum+=f(erase(A,n,i),n-i);
  }
  return sum;
}

int main(){
  int i,j,cnt;
  string s;
  cin>>s;
  int a[s.size()];
  for(i=0;i<s.size();i++){
    a[i]=s[i]-'0';
  }
  long long A=0;
  for(i=0;i<s.size();i++){
    A+=powa(s.size()-i-1)*a[i];
  }
  cout<<f(A,s.size());
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ans=0;
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a%2==1)ans++;
    }
    if(ans%2==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main()
{
	int a,b,c,i,j,k,n;

	scanf("%d%d%d",&a,&b,&c);

	a=a-b;
	c-=a;
	if(c<0)
        c=0;
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define MAX_POINT_EXAM    50
#define MAX_POINT_REEXAM 100
#define EXAM_NOT_TAKEN    -1

#define TH_R 50

#define TH_D 30
#define TH_C 50
#define TH_B 65
#define TH_A 80

#define IS_EXAM_NOT_TAKEN(m, f) ( m == EXAM_NOT_TAKEN || f == EXAM_NOT_TAKEN )

#define IS_RANK_F(m, f, r) (                    (m + f) < TH_D || IS_EXAM_NOT_TAKEN(m, f)            )
#define IS_RANK_D(m, f, r) ( TH_D <= (m + f) && (m + f) < TH_C                                       )
#define IS_RANK_C(m, f, r) ( TH_C <= (m + f) && (m + f) < TH_B || (IS_RANK_D(m, f, r) && TH_R <= r ) )
#define IS_RANK_B(m, f, r) ( TH_B <= (m + f) && (m + f) < TH_A                                       )
#define IS_RANK_A(m, f, r) ( TH_A <= (m + f)                                                         )

#define IS_END(m, f, r)    ( m == EXAM_NOT_TAKEN && f == EXAM_NOT_TAKEN && r == EXAM_NOT_TAKEN       )

int main(void)
{
        int m, f, r;

        while(-1)
        {
                scanf("%d %d %d", &m, &f, &r);

                if(IS_END(m, f, r)) { break; }

                if(IS_EXAM_NOT_TAKEN(m, f)) { printf("F\n"); }
                else if(IS_RANK_A(m, f, r)) { printf("A\n"); }
                else if(IS_RANK_B(m, f, r)) { printf("B\n"); }
                else if(IS_RANK_C(m, f, r)) { printf("C\n"); }
                else if(IS_RANK_D(m, f, r)) { printf("D\n"); }
                else if(IS_RANK_F(m, f, r)) { printf("F\n"); }
        }

        return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>
int main(void)
{
        int a,b,x,y,z;
        scanf("%d%d",&a,&b);
        if((a+b>=a-b)&&(a+b>=a*b)) printf("%d\n",a+b);
        else if((a-b>=a*b)) printf("%d\n",a-b);
        else printf("%d\n",a*b);
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll a, b;
	cin >> a >> b;
	cout << a / gcd(a, b) * b << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
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 V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S, T;
    cin >> S >> T;
    T.pop_back();
    if (S == T)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#define mod (int)(1e9 + 7)

long long int MOD(long long int a){
	if(a < 0){
		MOD(a + mod);
	}
	else{
		return a % mod;
	}
}

int main(){
	int m, n, i;
	long long int x, y, sumn = 0, summ = 0;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; i++){
		scanf("%lld", &x);
		sumn = MOD(sumn + ((2 * i - 1 - n) * x)); 
	}
	for(i = 1; i <= m; i++){
		scanf("%lld", &y);
		summ = MOD(summ + ((2 * i - 1 - m) * y));
	}
	printf("%d\n", (sumn * summ) % mod);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  while(1){
    c -= b;
    if(c <= 0){
      printf("Yes\n");
      break;
    }
    a -= d;
    if(a <= 0){
      printf("No\n");
      break;
    }
  }
}


Measured memory_bytes: 1644
use std::collections::BTreeMap;

use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    }

    a.insert(0usize, 0i64);
    for i in 1..=n {
        a[i] += a[i - 1];
    }
    let a = a;

    let mut count = BTreeMap::<i64, u64>::new();
    for ai in a {
        *count.entry(ai).or_insert(0) += 1;
    }

    let mut res = 0;
    for (k, v) in count.iter() {
        if v == &0 {
            continue;
        }
        res += v * (v - 1) / 2;
    }

    println!("{}", res);
}


Measured memory_bytes: 11300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

vector<int> ans;
vector<int> to[200005];

void dfs(int v, int p=-1){
    for(int u: to[v]){
        if(u==p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main(){
    int n, q; cin >> n >> q;
    vector<P> tree;
    int a, b;
    rep(i, n-1){
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    int p, x;
    rep(i, q){
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    rep(i, n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 23424
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
int main(){
    int n; cin >> n;
    string s[n]; int t[n];
    rep(i,n){
        cin >> s[i] >> t[i];
    }
    string x; cin >> x;
    int ans=0;
    bool wa=0;
    rep(i,n){
        if(wa) ans+=t[i];
        if(s[i]==x) wa=1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)
i0 = min([i for i in range(N) if len(X[i]) == 1])

P = [-1] * N
Q = deque([i0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

mod = 10 ** 9 + 7
inv2 = (mod + 1) // 2
A = [1] * N
for i in R[::-1]:
    s = 0
    for j in X[i]:
        A[i] += A[j]

ans = 0
for i in range(N):
    s = pow(inv2, N - A[i], mod)
    t = 1 + (1-pow(inv2, N - A[i], mod)) * pow(2, N - A[i], mod)
    for j in X[i]:
        s = (s * pow(inv2, A[j], mod)) % mod
        t = (t + (1-pow(inv2, A[j], mod)) * pow(2, A[j], mod)) % mod
    ans = (ans + 1 - s * t) % mod

print(ans * inv2 % mod)

Measured memory_bytes: 93784
#include <iostream>
#include <string>
using namespace std;
int main()
{
 int n;
 string s;
 cin >> n;
 cin >> s;
 if(n%2==0 && s.substr(0,(n/2)).compare(s.substr(n/2))==0)
 cout << "Yes";
 else
 cout << "No";
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  bool bl = false;
  for (int i = 1; i < 10; i++) {
    if (N%i == 0 && N/i <= 9) {
      bl = true;
    }
  }
  if (bl) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3620
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second


int main(int argc, char const *argv[]) {
  int a[3][3], index[3][3]={{0},{0},{0}};
  int n, b;
  bool flag = false;

  REP(i,3) std::cin >> a[i][0] >> a[i][1] >> a[i][2];
  std::cin >> n;

  REP(i, n) {
    std::cin >> b;
    REP(j, 3) {
      REP(k, 3) {
        if (a[j][k] == b) {
          index[j][k] = 1;
        }
      }
    }
  }
  REP(i, 3) {
    if (index[i][0] == 1 && index[i][1] == 1 && index[i][2] == 1) flag=true;
    if (index[0][i] == 1 && index[1][i] == 1 && index[2][i] == 1) flag=true;
    if (index[0][0] == 1 && index[1][1] == 1 && index[2][2] == 1) flag=true;
    if (index[2][0] == 1 && index[1][1] == 1 && index[0][2] == 1) flag=true;
  }
  if (flag) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Data.Maybe (fromMaybe)
import Data.Int
import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Maybe
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

-- 有向グラフに閉路があるか判定し、閉路があれば Nothing を返す。
-- 閉路がなければ最長路の長さを返す。
solve :: V.Vector [Int] -> Maybe Int
solve edges = fmap (fromIntegral . U.maximum) $ runST $ runMaybeT $ do
  let !n = V.length edges  -- 頂点の個数
  vec <- UM.replicate n (-2 :: Int32) -- -2: new, -1: DFSの最中, 正: チェック済み
  let dfs !x = do
        s <- UM.read vec x
        case s of
          -2 -> do
            -- x を通る閉路があるかチェックする
            UM.write vec x (-1)
            v <- (+ 1) <$> foldM (\a y -> max a <$> dfs y) 0 (edges V.! x)
            UM.write vec x v
            return v
          -1 -> mzero  -- コールスタックのどこかで dfs x が呼ばれている。閉路
          v -> return v
  mapM_ dfs [0..n-1]
  U.unsafeFreeze vec

main = do
  n <- readLn
  xs <- V.replicateM n $ do
    U.map (subtract 1) . U.unfoldrN (n-1) (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let m = n * (n - 1) `quot` 2  -- グラフの頂点数
  let -- (i,j) (0 <= i < j < n) を 0 以上 m 未満の整数値にコードする
      makePair :: Int -> Int -> Int
      makePair i j | i' < j' = n * i' - (i' + 1) * i' `quot` 2 + j' - i' - 1
                   | otherwise = undefined
        where i' = min i j; j' = max i j
  -- 「試合 (i,j) よりも試合 (i',j') の方を後に行う場合に辺 makePair i j → makePair i' j' が存在する」ようなグラフを作る
  let edges :: V.Vector [Int]
      edges = V.create $ do
        e <- VM.replicate m []
        V.forM_ (V.indexed xs) $ \(i,ys) -> do
          U.forM_ (U.zip ys (U.tail ys)) $ \(a,b) -> do
            -- (i,a) -> (i,b)
            let !b' = makePair i b
            -- VM.modify e (b' :) (makePair i a)
            t <- VM.read e (makePair i a)
            VM.write e (makePair i a) $! b' : t
        return e
  print $ fromMaybe (-1) $ solve edges


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

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

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


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

//INSERT ABOVE HERE
signed main(){
  Int m,n;
  cin>>m>>n;
  vector<Int> p(m);
  for(Int i=0;i<m;i++) cin>>p[i];
  vector<Int> c(n),e(n);
  for(Int i=0;i<n;i++) cin>>c[i]>>e[i];

  sort(p.rbegin(),p.rend());
  p.emplace(p.begin(),0);
  partial_sum(p.begin(),p.end(),p.begin());
  
  auto dp=make_v<Int>(m+1);
  const Int INF = 1e12;
  fill_v(dp,INF);
  dp[0]=0;
  
  for(Int i=0;i<n;i++){
    for(Int j=m;j>=0;j--){
      Int nj=min(j+c[i],m);
      chmin(dp[nj],dp[j]+e[i]);
    }
  }
  for(Int j=m-1;j>=0;j--) chmin(dp[j],dp[j+1]);
  
  Int ans=0;
  for(Int i=0;i<=m;i++)
    chmax(ans,p[i]-dp[i]);

  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>

int main(void)
{
	int can;
	
	while(scanf("%d",&can) != EOF){
		can = can % 39;
		if(can == 0){
			printf("3C39\n");
		}
		else if(can < 10){
			printf("3C0%d\n",can);
		}
		else {
			printf("3C%d\n",can);
		}
	}
	
	return(0);
}

Measured memory_bytes: 608
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;

    if(n % 2 == 0){
        cout << 0.5 << endl;
    }
    else{
        cout << double((n+1)/2)/(n) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int main(){
	char s[120];
	cin>>s;
	int i;
	int flag=1;
	for(i=0;i<strlen(s);i++){
		if(i==strlen(s)-1&&s[i]=='h') flag=0;
		if(i%2==0&&s[i]!='h')  {flag=0;break;}
		if(i%2!=0&&s[i]!='i')  {flag=0;break;}
	}
	
	if(flag==0) cout<<"No"<<endl;
	else        cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
int main() {
    while (cin >> N) {
        vector<int> p(N);
        int res = 0;
        for (int i = 0;i < N; ++i) cin >> p[i];
        for (int i = 1; i +1 < N; ++i) {
            vector<int> a(3);
            a[0] = p[i-1];
            a[1] = p[i];
            a[2] = p[i+1];
            sort(a.begin(), a.end());
            if (a[1] == p[i]) ++res;
        }
        cout << res << endl;
    }
}














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

int main() {
  int N, L;
  cin >> N >> L;
  string data[N];
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  for (int i = 0; i < N; i++) {
    string minData = data[i];
  	for (int j = i + 1; j < N; j++) {
      string tmpI = data[i];
      string tmpJ = data[j];
      string minTmp = min(tmpI, tmpJ); 
      if (minTmp == tmpJ) {
      	minData = tmpJ;
        data[i] = tmpJ;
        data[j] = tmpI;
      }
    }
  }
  string result; 
  for (int i = 0; i < N; i++) {
    result += data[i];
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	Vec p(a), q(b), r(c);
	rep(i, a) cin >> p[i];
	rep(i, b) cin >> q[i];
	rep(i, c) cin >> r[i];
	sort(all(p), greater<>());
	sort(all(q), greater<>());
	rep(i, x) r.push_back(p[i]);
	rep(i, y) r.push_back(q[i]);
	sort(all(r), greater<>());
	int ans = 0;
	rep(i, x+y) ans += r[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5744
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
ans = 0
for i in a:
    while i % 2 == 0:
        ans += 1
        i //= 2
print(ans)


Measured memory_bytes: 40432
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//計算量はどちらもO(logN)
LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b) { return a/gcd(a,b)*b;}

LL N,Ma,Mb;
LL A[40],B[40],C[40];

LL ans = INF;

bool check_rate(LL a,LL b){
	if(a==0 || b==0) return false;
	LL gcd_ab = gcd(a,b);
	return (a/gcd_ab==Ma && b/gcd_ab==Mb);
}

void solve(){
	//dp[i][a][b]
	//i個目まで見た時、タイプAをa[g]、
	//タイプBをb[g]作れるならその最小コスト
	vector<vector<vector<LL>>> dp(N+1,vector<vector<LL>>(401,vector<LL>(401,INF)));
	dp[0][0][0] = 0;
	//ばらまく
	for(int i=0;i<=N-1;i++){
		for(int a=0;a<=399;a++){
			for(int b=0;b<=399;b++){
				if(dp[i][a][b]==INF) continue;
				//i個目を使う
				dp[i+1][a+A[i]][b+B[i]] = min(dp[i+1][a+A[i]][b+B[i]],dp[i][a][b]+C[i]);
				if(check_rate(a+A[i],b+B[i])) ans = min(ans,dp[i+1][a+A[i]][b+B[i]]);
				//i個目を使わない
				dp[i+1][a][b] = min(dp[i+1][a][b],dp[i][a][b]);
				if(check_rate(a,b)) ans = min(ans,dp[i+1][a][b]);
			}
		}
	}
	if(ans==INF) ans = -1;
}

int main(){
    cin >> N >> Ma >> Mb;
    for(int i=0;i<N;i++){
    	cin >> A[i] >> B[i] >> C[i];
    }

    solve();

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 53504
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX_N 105
#define MAX_C 25
#define INF (1e8)
vector<int> T[MAX_C],U[MAX_C];
int G[MAX_C][MAX_N][MAX_N];
int n,m,c,s,g;
int d[MAX_N];


void init(){
  for(int i=0;i<MAX_C;i++){
    T[i].clear();
    U[i].clear();
  }

  for(int i=0;i<MAX_N;i++){    
    d[i]=INF;
    for(int j=0;j<MAX_N;j++){
      for(int k=0;k<MAX_C;k++){
        if(i==j)G[k][i][j]=0;
        else G[k][i][j]=INF;
      }
    }
  }
}

int calc(int dist,vector<int> &t,vector<int> &u){
  int res=0;
  for(int i=0;i+1<(int)t.size();i++){
    if(t[i]<=dist&&dist<=t[i+1]){
      dist-=t[i];
      return res+dist*u[i];
    }else{

      res+=((t[i+1]-t[i])*u[i]);
    }
  }
  return res;
}

int solve(){
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push(P(0,s));
  d[s]=0;
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int pos=p.second,cost=p.first;
    //cout<<pos<<' '<<cost<<endl;
    if(pos==g)return cost;
    if(cost>d[pos])continue;

    for(int id=1;id<=c;id++){
      for(int to=1;to<=n;to++){
        if(G[id][pos][to]==INF)continue;
        int ncost=cost+calc(G[id][pos][to],T[id],U[id]);
        if(ncost<d[to]){
          d[to]=ncost;
          Q.push(P(d[to],to));
        }
      }
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>n>>m>>c>>s>>g;
    if(n==0&&m==0&&c==0&&s==0&&g==0)break;
    init();
    for(int i=0;i<m;i++){
      int x,y,d,c;
      cin>>x>>y>>d>>c;
      G[c][x][y]=min(G[c][x][y],d);
      G[c][y][x]=min(G[c][y][x],d);
    }

    for(int id=1;id<=c;id++){
      for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
          for(int j=1;j<=n;j++)
            G[id][i][j]=min(G[id][i][j],G[id][i][k]+G[id][k][j]);
      int a;
      cin>>a;
      T[id].resize(a+1);
      U[id].resize(a);
      T[id][0]=0;
      T[id][a]=INF;
    }
    for(int id=1;id<=c;id++){
      for(int i=1;i+1<(int)T[id].size();i++)cin>>T[id][i];
      for(int i=0;i<(int)U[id].size();i++)cin>>U[id][i];
    }

    cout<<solve()<<endl;

  }
  return 0;
}

Measured memory_bytes: 2400
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n;
	double w,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>w;
		sum+=1/w;
	}
	cout<<fixed<<1/sum<<endl;

	return 0;
}



Measured memory_bytes: 256