akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int TT,n,a[N],b[N],c,d,i,j,ans,deg[N];
struct tree{
vector<int>e[N],ee[N];bool b[N];int dad[N];
inline void clear(){for(int i=1;i<=n;++i)e[i].clear();}
inline void add(int x,int y){e[x].push_back(y);e[y].push_back(x);}
inline void ini(){for(int i=1;i<=n;++i)sort(e[i].begin(),e[i].end());}
void dfs(int x,int fa,const tree&B,bool bb){
	b[x]=bb;
	for(int y:e[x])if(y!=fa)
		dfs(y,x,B,bb && binary_search(B.e[x].begin(),B.e[x].end(),y));
}
void getfa(int x,int fa){dad[x]=fa;for(int y:e[x])if(y!=fa)getfa(y,x);}
int calc(int rt,tree&B){
	int i,cnt=0;for(i=1;i<=n;++i)ee[i].clear();
	memset(b+1,0,n);dfs(rt,0,B,1);
	getfa(rt,0);B.getfa(rt,0);
	for(i=1;i<=n;++i)if(!b[i]){
		for(int j:e[i])if(j!=dad[i])ee[j].push_back(i);
		for(int j:B.e[i])if(j!=B.dad[i])ee[i].push_back(j);
	}else ++cnt;
	static int d[N],q[N];int t=0,w=0;
	memset(d+1,0,n<<2);for(i=1;i<=n;++i)for(int x:ee[i])++d[x];
	for(i=1;i<=n;++i)if(!d[i])q[++w]=i;
	for(;t<w;)for(int v:ee[q[++t]])if(!--d[v])q[++w]=v;
	return w==n?n-cnt:N;
}
}A,B,T;
int main(){
	scanf("%d",&TT);
	for(;TT--;){
		scanf("%d",&n);A.clear(),B.clear();memset(deg+1,0,n<<2);
		for(i=1;i<n;++i)scanf("%d%d",a+i,b+i),++deg[a[i]],++deg[b[i]],A.add(a[i],b[i]);
		for(i=1;i<n;++i)scanf("%d%d",&c,&d),B.add(c,d);B.ini();
		ans=N;
		for(i=1;i<=n;++i)ans=min(ans,A.calc(i,B));
		for(i=1;i<=n;++i)if(deg[i]==1){
			T.clear();for(j=1;j<n;++j)if(a[j]!=i && b[j]!=i)T.add(a[j],b[j]);
			for(j=1;j<=n;++j)if(j!=i)A=T,A.add(j,i),ans=min(ans,A.calc(i,B)+1);
		}
		if(ans==N)ans=-1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0
#include<string.h>
int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


int main(void){
    int n; 
    cin >> n;
    vector<int>L(n),copy(n);
    rep(i,n){
        cin >> L[i];
    }
    ll ans = 0;
    if(n<3){
        cout << 0 <<endl;
        return 0;
    }
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(i==j || j==k || i==k)continue;
                if(L[i]!=L[j] && L[j]!=L[k] && L[i]!=L[k]){
                    copy[0]=L[i];
                    copy[1]=L[j];
                    copy[2]=L[k];
                    sort(copy.begin(),copy.begin());
                    if(abs(copy[1]-copy[2])<copy[0] && copy[0]<copy[1]+copy[2])ans++;
                    //cout << copy[0]<<  copy[1] <<copy[2] <<endl;
                }
            }
        }
    }
    cout << ans/6 <<endl;
    return 0;
}




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

bool same(vector<int> X,vector<int> Y){
  bool judge=true;
  for(int i=0;i<X.size();i++){
    if(X.at(i)!=Y.at(i)){
      judge=false;
    }
  }
  return judge;
}

int main() {
  int N;
  cin>>N;
  vector<int> P(N),Q(N),A(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  for(int i=0;i<N;i++){
    cin>>Q.at(i);
  }
  for(int i=0;i<N;i++){
    A.at(i)=i+1;
  }
  int p,q,count=0;
  do{
    if(same(P,A)){p=count;}
    if(same(Q,A)){q=count;}
    count++;
  }while (next_permutation(A.begin(),A.end()));
  cout<<abs(p-q)<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) if (n < 0) n = 0
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[n];
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		if (i % 2 == 0) {
			if (a[i] % 2 == 1) cnt++;
		}
	}
	cout << cnt << endl;
}

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

int N, L;

int main() {
    cin >> N >> L;

    vector<int> taste;
    for (int i = 0; i < N; i++) {
        taste.push_back(L + i);
    }

    int eat;
    if (taste[0] > 0) eat = taste[0];
    else eat = taste[N-1];
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (taste[i] == 0) eat = 0;
        ans += taste[i];
    }

    cout << ans - eat << endl;

    return 0;
}


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

class Program
{
    static void Main()
    {
        string[] Input = Console.ReadLine().Split(' ');
        long N = long.Parse(Input[0]);

        //Hが縦、Wが横のほしい長さ
        long H = long.Parse(Input[1]);
        long W = long.Parse(Input[2]);

        //Aが縦、Bが横の最初の長さ
        long[] A = new long[N];
        long[] B = new long[N];

        for (int i = 0; i < N; i++)
        {
            string[] Input2 = Console.ReadLine().Split(' ');
            A[i] = long.Parse(Input2[0]);
            B[i] = long.Parse(Input2[1]);
        }
        //入力処理完了

        int count = 0;

        for (int i = 0; i < N; i++)
        {
            if (A[i] >= H && B[i] >= W)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}

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

int main(void) {
    vector<int> a(5);
    for (int i = 0; i < 5; i++) {
        cin >> a.at(i);
    }
    vector<int> ma(5);
    transform(a.begin(), a.end(), ma.begin(), [](double x) { return ceil(x / 10) * 10; });
    int sum = accumulate(ma.begin(), ma.end(), 0);
    int ans = 1e9;
    for (int i = 0; i < 5; i++) {
        ans = min(ans, sum - ma.at(i) + a.at(i));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    bool OK = false;
    for (int i=a;i<=b;i++){
        if (i%k == 0){
            OK = true;
        }
    }
    if (OK== true){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
     }
 

    

}

Measured memory_bytes: 3484
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

int n, m;
int w[121], v[121];
ll dp[121][100021];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &w[i], &v[i]);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (j < w[i]) {
                dp[i][j] = dp[i - 1][j];
                continue;
            }
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            // printf("%lld ", dp[i][j]);
        }
        // printf("\n");
    }
    printf("%lld\n", dp[n][m]);
    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=600001,INF=1<<30;

const ll B1=1000000007,B2=1000000009;
ll mo1,mo2;
vector<int> ok;

void contain(string a,string b){
    int al=a.length(),bl=b.length();
    if(al>bl) return;
    
    ll t1=1,t2=1;
    for(int i=0;i<al;i++){
        t1*=B1;
        t1%=mo1;
        //t2*=B2;
        //t2%=mo2;
    }
    
    ll ah1=0,ah2=0,bh1=0,bh2=0;
    for(int i=0;i<al;i++){
        ah1=(ah1*B1+(a[i]-'a'))%mo1;
        //ah2=(ah2*B2+(a[i]-'a'))%mo2;
        bh1=(bh1*B1+(b[i]-'a'))%mo1;
        //bh2=(bh2*B2+(b[i]-'a'))%mo2;
    }
    
    for(int i=0;i+al<=bl;i++){
        if(ah1==bh1&&ah2==bh2) ok.push_back(i);
        if(i+al<bl){
            bh1=(bh1*B1+(b[i+al]-'a')-((b[i]-'a')*t1)%mo1+mo1)%mo1;
            //bh2=(bh2*B2+(b[i+al]-'a')-((b[i]-'a')*t2)%mo2+mo2)%mo2;
        }
    }
    
    return;
    
}

int par[MAX],size[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        size[root(a)]+=size[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}

int main(){
    
    srand((unsigned int)time(NULL));
    
    mo1=rand();
    mo2=rand();
    
    string preS,T,S;cin>>preS>>T;
    int L=T.size();
    
    while(int(S.size())<2*int(T.size())+int(preS.size())) S+=preS;
    
    contain(T,S);
    
    init(int(preS.size()));
    
    for(int i:ok){
        if(i>=preS.size()) break;
        int j=(i+L)%int(preS.size());
        if(check(i,j)){
            cout<<-1<<endl;
            return 0;
        }
        unite(i,j);
        //cout<<i<<endl;
    }
    
    int ans=-1;
    
    for(int i=0;i<preS.size();i++){
        ans=max(ans,size[root(i)]-1);
    }
    
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 20100
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, P;
	cin >> A >> P;
	
	cout << (3 * A + P) / 2 << endl;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

constexpr long long mod = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;

    ll cnt = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

const int dx[4] = {0,  0, 1, -1};
const int dy[4] = {1, -1, 0,  0};

const int N = 2002;

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll n;
	ll sum = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		sum += i;
		if (sum >= n){
			cout << i << endl;
			return 0;
		}
	}
  	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;
 
void solve() {
    int N;
    double D; cin>>N>>D;
    double dist[N];
    ll x, y;
    for(int i=0;i<N;i++) {
        cin>>x>>y;
        dist[i] = sqrt(x*x + y*y);
    }
    sort(dist, dist + N);
    int ind = upper_bound(dist, dist + N, D) - dist;
    if(ind == N) cout<<N<<"\n";
    else {
        cout<<ind<<"\n";
    }
}
 
int main() {
    fast 
    // input output
    int t=1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

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


using namespace std;
double pi=3.14159265358979323846264338;

string s;
int lnth;
long long ans,cur;
void dfs(long long a,int b){
	if(b==lnth-1){
		if(a!=0)ans+=cur+a*10+(long long)(s[lnth-1]-'0');
		ans+=cur+a+(long long)(s[lnth-1]-'0');
		return;
	}
	if(a!=0)dfs(a*10+(long long)(s[b]-'0'),b+1);
	cur+=a;
	dfs((long long)(s[b]-'0'),b+1);
	cur-=a;
}

int main(){
	cin>>s;
	ans=0;
	cur=0;
	lnth=s.length();
	dfs(cur,0);
	cout<<ans<<endl;
			
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
  int num;
  scanf("%d",&num);
  num=num-1;
  int far[num], start[num], inter[num], i, time,j;
  for(i=0; i<num; i++)
  {
    scanf("%d",&far[i]);
    scanf("%d",&start[i]);
    scanf("%d",&inter[i]);
  }
  for(j=0; j<num; j++)
  {
    time=0;
  for(i=j; i<num; i++)
  {
    if(time<start[i])
    {
      time=start[i]+far[i];
    }
    else
    {
      while(time%inter[i]!=0)
      {
        time++;
      }
      time=time+far[i];
    }
  }
    printf("%d\n",time);
  }
  printf("0");
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  for (int i = 0; i < 3; ++i) {
    char c; cin >> c;
    if (c == '1') cout << 9;
    else          cout << 1;
  }
  cout << endl;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
#define INF 0x3f3f3f3f
//_______
vector<pii> G[102];
bool used[102];

int prim()
{
   priority_queue < pii, vector<pii>, greater<pii> > pq;
   pq.push( mkp(0,0) );
   int sum = 0;

   while( !pq.empty() ){
      const pii  tmp = pq.top(); pq.pop();
      if( used[ tmp.se ]++ )continue;
      sum += tmp.fi;

      rep(j, G[tmp.se].size() )
         pq.push( mkp( G[tmp.se][j].fi, G[tmp.se][j].se ) );
   }
   return (sum);
}

signed main()
{
   FAST();
   int N; cin >> N;

   rep(i, N)rep(j, N){
      int v; cin >> v;
      if( v != -1 ) G[i].pb( mkp(v,j) );
   }
   outl( prim() );
}




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

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

    int N;
    cin >> N;

    for(int i = 0; i <= N; i++) {
        if((double)i * 1.08 >= N && (double)i * 1.08 < N + 1) {
            cout << i;
            return 0;
        }
    }

    cout << ":(";
    return 0;
}


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

	
int main(){
	long long int n=0;
	long long int m=0;
	long long int x=0;
	cin>>n>>m;
	x=m-2*n;
	if(x<0){
		cout<<m/2;
	}else{
		cout<<n+x/4;
	}
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll x;
    cin>>x;
    
    if(x<=6) {cout<<1;return 0;}
    if(x<=11) {cout<<2;return 0;}
    ll q = x/11;
    ll r = x%11;
    if(r)
    {
        if(r<=6) cout<<2*q + 1;
        else cout<<2*q + 2;
    }
    else
    {
        cout<<2*q;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define VI vector<int>
#define PB(x) push_back(x)
#define SZ(x) end(x) - begin(x)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void CO(auto &a) {REP(i, SZ(a)) cout << i << ": " << a[i] << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	double s,k;	cin >> s >> k;
	double ans = 0,a;
	FOR(i,1,s+1){
		if (i > k){
			ans += (s-k);
			DEBUG(s-k);
			break;
		}
		a = ceil(log2f(k/i));
		DEBUG(a);
		ans += pow(0.5,ceil(log2l(k/i)));
		DEBUG(ans);
	}
	cout << ans/s << endl;
return 0;
}


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

int main()
{
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N+1);
    for (int i=1; i<N+1; i++) {
        cin >> H.at(i);
    }
    int index = 1;
    float value = abs(A -(T - H.at(1) * 0.006));
    for (int i=2; i<N+1; i++) {
        float tmp = abs(A - (T - H.at(i)*0.006));
        if (tmp < value){
            value = tmp;
            index = i;
        } 
    }
    cout << index << endl;
}


Measured memory_bytes: 256
#include<iostream>

int main()
{
    std::string in;
    std::cin >> in;

	if (in.size() % 2 == 1)
		std::cout << "No" << std::endl;
	else {
      int i = 0;
      for (i = 0; i < in.size(); i+= 2) {
        if (in.substr(i, 2) != "hi")
          break;
      }
      
      if (i == in.size())
		std::cout << "Yes" << std::endl;
      else
        std::cout << "No" << std::endl;
    }
  
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while (!(buf = br.readLine()).equals("-1")) {
				double q = Double.parseDouble(buf);
				
				double x = q/2;
				double A = Math.pow(x,3)-q;
				while (Math.abs(A)>=0.00001*q) {
					x -= A/(3*Math.pow(x,2));
					A = Math.pow(x,3)-q;
				}
				System.out.println(x);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16940
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp;
  if (((n[0] == n[1]) && (n[1] == n[2])) || ((n[1] == n[2]) && (n[2] == n[3]))) {
    writeln("Yes");
  }  else {
    writeln("No");
  }
}


Measured memory_bytes: 256
k,n = (int(x) for x in input().split() )
list = list(map(int,input().split()))

list_distance=[]
for i in range(n-1):
    list_distance.append(list[i+1]-list[i])
list_distance.append(k-(list[n-1]-list[0]))
print(k-max(list_distance))

Measured memory_bytes: 26444
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  ld N, K, a = 0;
  ci(N, K);
  repi(i, 1, N + 1){
    int j = i;
    if(i > K){
      a += 1 / N;
    }
    else{
      int b = 0;
      wh(j < K){
        j *= 2;
        b++;
      }
      a += 1 / N * 1 / pow(2, b);
    }
  }
  sp(10);
  co(a);
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        s: chars,
    }

    let a = s[0] as i32 - 48;
    let b = s[1] as i32 - 48;
    let c = s[2] as i32 - 48;
    let d = s[3] as i32 - 48;

    let n = 1<<3;
    for i in 0..n {
        let mut now = a;
        let mut ans: String = a.to_string();
        if i & 1 == 1 {
            now += b;
            ans.push_str("+");
        } else {
            now -= b;
            ans.push_str("-");
        }
        ans.push_str(&b.to_string());
        if i>>1 & 1 == 1 {
            now += c;
            ans.push_str("+");
        } else {
            now -= c;
            ans.push_str("-");
        }
        ans.push_str(&c.to_string());
        if i>>2 & 1 == 1 {
            now += d;
            ans.push_str("+");
        } else {
            now -= d;
            ans.push_str("-");
        }
        ans.push_str(&d.to_string());
        if now == 7 {
            println!("{}{}", ans, "=7");
            return;
        }
    }
}


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

int main() {
    ifstream fin("serv_monster.in");
    ofstream fout("serv_monster.out");
    int h, a;
    int counter = 0;
    cin >> h >> a;

    while(h > 0) {
        counter++;
        h-=a;
    }

    cout << counter << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;cin>>n;
  	string s,t;cin>>s>>t;
  	int cs=0,ct=0;
  
  while(cs<s.size()){
  	if(s.at(cs)==t.at(ct)){
    	cs++; ct++;
    }else{
   		if(ct!=0) ct=0; 
      	else cs++;
    }
  }
    cout<<(s.size())*2-ct<<endl;
}

Measured memory_bytes: 256
import numpy as np
from statistics import median

N = int(input())
A = list(map(int, input().split()))
list_n = list(range(1, (N+1), 1))
A_tmp = np.array(A)
list_n_tmp = np.array(list_n)
list_diff = A_tmp - list_n_tmp
b = median(list_diff)
Xtmp = 0

for n in range(0, N, 1):
    Xtmp += abs(A[n] - (b + n + 1))

print(int(Xtmp))


Measured memory_bytes: 42016
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

int main(){
    int L;
    cin >> L;
    double d = L/3.l;
    printf("%.12f\n",pow(d,3));
    return 0;
}

// int main() {
//     int L;
//     cin >> L;
 
//     double d = L / 3.l;
//     // double ans = );
 
//     printf("%.12f\n", pow(d,3));
 
//     return 0;
// }

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;

ll ans = 0;
const int MAX_N = 400;
vector<string>clr;
int H, W;
int visited[MAX_N][MAX_N];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll numB = 0, numC = 0;

void dfs(int x, int y){
   visited[x][y] = 1;
   if(clr[x][y] == '#') numB++;
   else numC++;
   for(int d = 0; d < 4; d++){
      int nx = x + dx[d];
      int ny = y + dy[d];
      if(nx < 0 || nx >= H || ny < 0 || ny >=W) continue;
      if(clr[x][y] == clr[nx][ny]) continue;
      if(visited[nx][ny] == 1) continue;
      dfs(nx, ny);
   }
}

int main(){
   cin >> H >> W;
   clr.resize(H);
   for(int i = 0; i < H; i++) cin >> clr[i];
   for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
         if(visited[i][j] != 1 && clr[i][j] == '#'){
            dfs(i, j);
         }
         ans += numB*numC;
         numB = 0; numC = 0;
      }
   }
   cout << ans << endl;
}



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

using namespace std;

int main() {
    array<int, 3> a;
    cin >> a[0] >> a[1] >> a[2];
    set<array<int, 3>> used;
    while (a[0] % 2 == 0 && a[1] % 2 == 0 && a[2] % 2 == 0) {
        used.insert(a);
        long long sum = a[0] + (long long)a[1] + a[2];
        a[0] = (sum - a[0]) / 2;
        a[1] = (sum - a[1]) / 2;
        a[2] = (sum - a[2]) / 2;
        if (used.count(a)) 
            break;
    }
    if (used.count(a)) 
        cout << -1 << "\n";
    else 
        cout << int(used.size()) << "\n";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
int a[5],x,n;
double dp[305][305][305];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&x),a[x]++;
	for (int i=0;i<=a[3];i++)//三的个数 
		for (int j=0;j<=n-i;j++)//二的个数 
			for (int k=0;k<=n-i-j;k++){ //一的个数 
				if (i+j+k==0) continue;
				int t=n-i-j-k;double now=1;
				if (i) now+=dp[i-1][j+1][k]*1.0*i/n;
				if (j) now+=dp[i][j-1][k+1]*1.0*j/n;
				if (k) now+=dp[i][j][k-1]*1.0*k/n;
				if (t)
					dp[i][j][k]=now/(1-1.0*t/n);
				else dp[i][j][k]=now;
			}
	printf("%.10lf",dp[a[3]][a[2]][a[1]]);
}

Measured memory_bytes: 219392
n = int(input())
V = list(map(int, input().split()))

import sys
from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]

minV = min(V)
if all([v == minV for v in V]):
    print(len(V)//2)
    sys.exit()

if n0 == n1:
    if C0.most_common()[1][1] >= C1.most_common()[1][1]:
        n0 = C0.most_common()[1][0]
    else:
        n1 = C1.most_common()[1][0]
    
count = 0
for v in V[0::2]:
    if v != n0:
        count += 1

for v in V[1::2]:
    if v != n1:
        count += 1
print(count)

Measured memory_bytes: 102692
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    std::ios::sync_with_stdio(false);

    int N, W;
    cin >> N >> W;

    // value, weight
    vector<pair<int, int> > item;
    for(int i=0; i<N; i++)
    {
        pair<int, int> temp;
        cin >> temp.first >> temp.second;
        item.push_back(temp);
    }

    // DP初期化
    vector<vector<int> > dp(N+2, vector<int>(W+2,-1));
    for(int w=0; w<=W; w++)
    {
        // 0個の商品が対象なら絶対価値0にしかならない
        dp.at(0).at(w) = 0;
    }

    // DPループ
    // i番目の商品を足すか確認する
    for(int i=0; i<N; i++)
    {
        // wの値のチェック
        for(int w=0; w<=W; w++)
        {
            // cout << item.at(i).second << endl;
            if((w >= item.at(i).second) && (w - item.at(i).second <= W))
            {
                // 単品で選んでも重量が超えない場合
                // 商品を選ぶ場合か、選ばない場合かを確認
                // 選ばない場合は1個前の商品選びのパターンと同じ
                dp.at(i+1).at(w) = max(dp.at(i).at(w-item.at(i).second) + item.at(i).first, dp.at(i).at(w));
                // cout <<"i+1: " << i+1 << ", w: " << w << ", DP: " << dp.at(i+1).at(w) << endl;
            }
            else
            {
                // 1個で重量超えの場合は選べない
                dp.at(i+1).at(w) = dp.at(i).at(w);
                // cout <<"i+1: " << i+1 << ", w: " << w << ", DP: " << dp.at(i+1).at(w) << "...weight over!!" << endl;
            }
        }
    }

    cout << dp.at(N).at(W) << endl;
    return 0;
}


Measured memory_bytes: 6844
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=n;1<=i;i--){
        int m = 2;
        int cnt = 0;
        while(i*m<=n){
            cnt += b[m*i-1];
            m++;
        }
        if(m==2) b[i-1] = a[i-1];
        else b[i-1] = abs(a[i-1]-cnt)%2;
    }
    bool flag = 0;
    for(int i=0;i<n;i++){
        if(b[i]==-1) flag = 1;
        if(b[i]==1) cnt++;
    }
    if(flag){
        cout << -1 << endl;
        return 0;
    } 
    cout << cnt << endl;
    for(int i=0;i<n;i++){
        if(b[i]==1) cout << i+1 << ' ';
    }
    cout << endl;
}

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

const int MOD = (int)1e9+7;

int main(){
	int N,K;
	string S;
	cin >> N >> K >> S;
	
	vector<int> x;
	int count=1;
	for(int i=1;i<N;i++){
		if(S.at(i)==S.at(i-1))	count++;
		else{
			x.push_back(count);
			count=1;
		}
	}
	x.push_back(count);
	//for(int i=0;i<x.size();i++)	cout << x.at(i) << ",";
	
	vector<int> sum(x.size()+1);
	sum.at(0)=0;
	for(int i=1;i<sum.size();i++){
		sum.at(i)=sum.at(i-1)+x.at(i-1);
	}
	//for(int i=0;i<sum.size();i++)	cout << sum.at(i) << ",";
	
	int ans=0;
	if(S.at(0)=='0'){
		for(int i=0;i+2*K<sum.size();i+=2){
			int a=sum.at(i+2*K)-sum.at(i);
			if(i>0)	a=sum.at(i+2*K)-sum.at(i-1);
			ans=max(ans,a);
			if(S.at(N-1)=='0' && i+2*K+2>=sum.size()){
				int b=sum.at(i+2*K+1)-sum.at(i+1);
				ans=max(ans,b);
			}
		}
	}
	else if(S.at(0)=='1'){
		for(int i=0;i+1+2*K<sum.size();i+=2){
			int a=sum.at(i+1+2*K)-sum.at(i);
			ans=max(ans,a);
			if(S.at(N-1)=='0' && i+1+2*K+2>=sum.size()){
				int b=sum.at(i+1+2*K+1)-sum.at(i+2);
				ans=max(ans,b);
			}
		}
	}
	if(S.at(0)=='0' && S.at(N-1)=='0' && 2*K-1>=x.size())	ans=N;
	else if(S.at(0)=='0' && S.at(N-1)=='1' && 2*K>=x.size())	ans=N;
	else if(S.at(0)=='1' && S.at(N-1)=='0' && 2*K>=x.size())	ans=N;
	else if(S.at(0)=='1' && S.at(N-1)=='1' && 2*K+1>=x.size())	ans=N;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1272
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int main(){
    int n;cin>>n;
    vector<P> v;
    vector<ll> a(n),b(n);
    ll sa=0,sb=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        v.push_back(P(a[i],i));
        v.push_back(P(b[i],i));
        sa+=a[i];
        sb+=b[i];
    }
    ll ans=min(sa,sb);
    ll s=0;
    sort(all(v));
    bool f=false;
    vector<int> co(n,0);
    for(int i=0;i<n;i++){
        s+=v[i].first;
        co[v[i].second]++;
        if(co[v[i].second]==2){
            f=true;
        }
    }
    if(f){
        cout<<min(ans,s)<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        if(co[i]==0){
            ans=min(ans,s-v[n-1].first-v[n-2].first+a[i]+b[i]);
        }else{
            if(v[n-1].second!=i){
                ans=min(ans,s-v[n-1].first+max(a[i],b[i]));
            }else{
                ans=min(ans,s-v[n-2].first+max(a[i],b[i]));
            }
        }
    }
    cout<<ans<<endl;
}   


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct UF {
  vint data;
  UF(int n):data(n, -1){}
  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }
};

using Graph = vector<vint>;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  Graph graph(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  UF uf(n);
  vint path;
  function<void(int)> dfs = [&](int u) {
    for(int v : graph[u]) {
      if(uf.same(u, v)) continue;
      uf.unite(u, v);
      path.push_back(v);
      dfs(v);
      break;
    }
  };
  int cnt = 0;
  path.push_back(0);
  for(int v : graph[0]) {
    if(uf.same(0, v)) continue;
    uf.unite(0, v);
    path.push_back(v);
    dfs(v);
    cnt++;
    reverse(all(path));
    if(cnt == 2) break;
  }
  cout << path.size() << endl;
  rep(i, path.size()) {
    if(i) cout << " ";
    cout << path[i]+1;
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 22260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>


int main() {

	std::string s;

	std::cin >> s;

	long long ans = 0;
	char pre = '\0';

	for (long long  i = 0; i < s.length(); i++)
	{
		if (pre == '\0' || s[i] != pre) {
			pre = s[i];
			ans++;
		}
		else {
			if (i + 1 < s.length()) {
				i++;
				ans++;
				pre = '\0';
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


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

void bubbleSort(int A[], int N){
  int flag, t, change_num = 0;

  flag = 1;
  for(; flag;){
    flag = 0;
    for(int j = N-1; j > 0; j--){
      if (A[j] < A[j-1]){
        t = A[j];
        A[j] = A[j-1];
        A[j-1] = t;
        flag = 1;
        change_num += 1;
      }
    }
  }
  for(int i = 0; i < N; i++){
    if(i == N-1) cout << A[i] << endl;
    else cout << A[i] << " ";
    }
  cout << change_num << endl;
}

int main(){
  int N,A[100];
  cin >> N;
  for(int i = 0; i < N; i++) cin >> A[i];
  bubbleSort(A, N);

  return 0;
}

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define MOD 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  int x[n], y[m];
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < m; i++) cin >> y[i];
  auto f = [](int n, int x[]) {
    int res = 0;
    for (int i = 0; i < n; i++) {
      int pls = 1LL * x[i] * i % MOD;
      int mns = 1LL * x[i] * (n-1-i) % MOD;
      res = (1LL * res + pls - mns) % MOD;
    }
    return res < 0 ? res + MOD : res;
  };
  cout << 1LL * f(n, x) * f(m, y) % MOD << endl;
}

Measured memory_bytes: 1024
/*
    Author: Mohammad faisal
    Problem: AtCoder Beginner Contest 999.
    Date: 07/08/2019

*/
// #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
using namespace std;
// long long gcd(long long a,long long b)
// {
//   if(b)
//     return gcd(b,a%b);
//   else
//     return a;
// }
int main()
{
  string s;
  cin >> s;

  if(s[0]=='1')
    s[0]='9';
  else if(s[0]=='9')
    s[0]='1';

  if(s[1]=='1')
    s[1]='9';
  else if(s[1]=='9')
    s[1]='1';  

  if(s[2]=='1')
    s[2]='9';
  else if(s[2]=='9')
    s[2]='1';

  cout<<s<<endl;
    return 0;
}

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

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

using namespace std;

int main() {
    int n[5];
    rep(i, 5){
        cin >> n[i];
    }
    int digit[5];
    rep(i, 5){
        digit[i] = (n[i] % 100) % 10;
    }
    int sum, ans = 0;
    rep(i, 5){
        sum += digit[i];
    }
    if(sum == 0){
        rep(i, 5){
            ans += n[i];
        }
        cout << ans << endl;
        return 0;
    }
    int index = -1;
    for(int i = 1; i < 10; i++){
        rep(j, 5){
            if(digit[j] == i){
                index = j;
                break;
            }
        }
        if(index != -1){
            break;
        }
    }
    rep(i, 5){
        if(i == index){
            continue;
        }
        if(digit[i] != 0){
            n[i] += (10 - digit[i]);
        }
        ans += n[i];
    }
    ans += n[index];
    cout << ans << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BBishop {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h, w;
        in >> h >> w;
        ll res = min(h, w) > 1 ? ((ll) h * w + 1) / 2 : 1;
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BBishop solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toLong()
    
    var ans = Long.MAX_VALUE
    
    for (i in LongRange(1L, Math.sqrt(N.toDouble()).toLong() + 1L)) {
        if (N % i == 0L) {
            ans = Math.min(ans, i - 1L + (N / i) - 1L)
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 32032
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,x,y,a[10010],val[10010],sum=0,id;
vector <int> g[10010];
vector <pii> v;

void dfs(int pos,int no)
{
	val[pos]=a[id--];
	rep(i,g[pos].size()) if(g[pos][i]!=no) dfs(g[pos][i],pos);
}

int main()
{
	cin>>n;
	rep(i,n-1)
	{
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	rep(i,n) scanf("%d",&a[i]),sum+=a[i];
	sort(a,a+n);
	cout<<sum-a[n-1]<<endl;
	id=n-1;
	dfs(1,0);
	repn(i,n) cout<<val[i]<<' ';
	cout<<endl;
	rt0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#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>
#include <random>

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

using namespace std;
class UnionFind
{
public:
	UnionFind(int min, int max)
		: elems_(max - min + 1)
		, min_(min)
		, rank_(max - min + 1)
	{
		for (int i = min; i <= max; i++) {
			Elem& elem = this->elems_[i - min];
			elem.i = i;
			elem.num = 1;
		}
	}

	int find(int i) {
		int idx = i - this->min_;
		if (this->elems_[idx].i == i) return i;

		int root = this->find(this->elems_[idx].i);
		this->elems_[idx].i = root; // 簡略化
		return root;
	}

	int size(int i) {
		int root = this->find(i);
		int idx = root - this->min_;
		return this->elems_[idx].num;
	}

	int rank() {
		return rank_;
	}

	void merge(int i, int j) {
		int i_root = this->find(i);
		int j_root = this->find(j);
		if (i_root == j_root) return;

		int i_idx = i_root - this->min_;
		int j_idx = j_root - this->min_;

		int i_size = this->elems_[i_idx].num;
		int j_size = this->elems_[j_idx].num;

		if (i_size < j_size) {
			this->elems_[i_idx].i = j_root;
			this->elems_[j_idx].num += this->elems_[i_idx].num;
		}
		else {
			this->elems_[j_idx].i = i_root;
			this->elems_[i_idx].num += this->elems_[j_idx].num;

		}
		this->rank_--;
	}

private:
	struct Elem {
		int i;
		int num; // root 以外は無効
	};

	vector<Elem> elems_;
	int          min_;
	int          rank_;
};

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

	int n, m; cin >> n >> m;
	UnionFind uf(1, n);
	REP(m) {
		int a, b; cin >> a >> b;
		uf.merge(a, b);
	}
	int ans = 0;
	FOR_LE(i, 1, n) {
		ans = max(ans, uf.size(i));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=-1,z=0,w=0,n=0,m=0;
string s="";
std::cin >>s;
rep(i,s.size()){
if(s[i]=='A'&&y<0){
  y=i;
}else if(s[i]=='Z'){

if(i-y>z)z=i-y;
}
}
std::cout <<z+1 << '\n';

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;
const int N=100005;
vector<int> e[N];
int dis[N],dep[N],n,k,ans;
void dfs(int x,int fa){
	dis[x]=dep[x];
	for (int i:e[x]){
		dep[i]=dep[x]+1; dfs(i,x);
		dis[x]=max(dis[x],dis[i]);
	}
	if (fa!=1&&x!=1&&dis[x]-dep[x]==k-1)
		++ans,dis[x]=0;
}
int main(){
	scanf("%d%d",&n,&k);
	For(i,1,n){
		int x; scanf("%d",&x);
		if (i==1) ans+=(x!=1);
		else e[x].PB(i);
	}
	dfs(1,0);
	printf("%d",ans);
}

Measured memory_bytes: 12800
while True:
    a , op , b = map(str,input().split())
    a = int(a)
    b = int(b)
    if op == '?':
        break
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    else:
        print(a // b)


Measured memory_bytes: 5592
import bisect
while(1):
    [N,M]=[int(x) for x in raw_input().split()]
    if N==0:
        break
    else:
        hlist=[]
        wlist=[]
        bef=[]
        for i in range(N):
            newh=int(raw_input())
            news=[newh+a for a in bef]
            hlist+=news
            hlist.append(newh)
            bef=news+[newh]
        bef=[]
        for i in range(M):
            neww=int(raw_input())
            news=[neww+a for a in bef]
            wlist+=news
            wlist.append(neww)
            bef=news+[neww]
        hlist.sort()
        #print hlist,wlist
        ans=0
        for w in wlist:
            ans+=bisect.bisect(hlist,w)-bisect.bisect_left(hlist,w)
        print ans

Measured memory_bytes: 68836
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int n,ans=0,d,x,ar[105];
int32_t main(){
	cin>>n>>d>>x;
	ans = x;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		for(int j=1;j<=d;j+=ar[i]){
			ans++;
		}
	}
	cout<<ans;
}


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

using namespace std;

map<string, int> table;

int main(){
	string word, frequent, longest;
	size_t N = 0;
	while (cin >> word){
		table[word]++;
		if (table[word] > N){
			N = table[word];
			frequent = word;
		}
		if (word.size() > longest.size())
			longest = word;
	}
	cout << frequent << " " << longest << endl;
}

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

int main(){

    int n;
    cin>>n;
        if(n==9||n==19||n==29||n==39||n==49||n==59||n==69||n==79||n==89||n==90||n==91||n==92||n==93||n==94||n==95||n==96||n==97||n==98||n==99){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

return 0;
}


Measured memory_bytes: 3636