akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define inf 100000000
#define _GLIBCXX_DEBUG
// typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

vector<ll> memo(100);


ll saiki(int n){
    if (memo[n] != 0) return memo[n];
    memo[n] = saiki(n - 1) + saiki(n - 2) ;
    return (memo[n]);
}

int main(){
    memo[0] = 2;
    memo[1] = 1;
    int n;
    cin>>n;
    cout <<saiki(n)<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n; 
	cin>>n;
	vi a(n+1, 0);
	rep(i,0,n+1) cin>>a[i];

	if(a[0]>1) {
		cout<<-1<<endl;
	}
	else {
		vector<ll> x(n+1, 0);
		if(a[0]>0) x[0] = 0;
		else x[0] = 1;
		rep(i,1,n+1) {
			ll tmp = x[i-1]*2-a[i];
			if(tmp > (ll)1e14) tmp = (ll)1e14;
			x[i] = tmp;
		}
		//rep(i,0,n+1) cout<<x[i]<<endl;

		ll ans = a[n];
		ll b = a[n];
		per(i,0,n) {
			if(b/2+(b&1)>x[i]) {
				ans = -1;
				break;
			}
			else {
				if(b >= x[i]) 
					b = x[i] + a[i];
				else 
					b = b + a[i];
				ans += b;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;

int t;

int main()
{
	cin >> t;
	string s;
	int val;
	map<string, int> verdict;
	vector<string> order;
	order.push_back("AC");
	order.push_back("WA");
	order.push_back("TLE");
	order.push_back("RE");

	for (string s : order) {
		verdict[s] = 0;
	}
	
	while (t--) {
		cin >> s;
		val = verdict[s];
		verdict[s] = val + 1;
	}
	

	for (string s : order) {
		cout << s << " x " << verdict[s] << endl;
	}
	return 0;
}



Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	sum := 0

	if a > b {
		sum += a
		a--
	} else {
		sum += b
		b--
	}

	if a > b {
		sum += a
		a--
	} else {
		sum += b
		b--
	}

	fmt.Printf("%d\n", sum)
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int S, h, m, s;
	
	cin >> S;
	
	h = S / 3600;
	m = (S % 3600) / 60;
	s = (S % 3600) % 60;
	
	cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}

Measured memory_bytes: 1168
// AGC 018 A
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define ll long long
using namespace std;

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N,0);
    REP(i,N){
        cin >> A[i];
    }
    int t = A[0];
    REP(i,N){
        t = gcd(t,A[i]);
    }
    int M = *max_element(A.begin(),A.end());
    if(K<=M && K%t==0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var D = sc.nextInt();
        var ans = N / ((D * 2) + 1);
        if (N % ((D * 2) + 1) != 0) {
            ans++;
        }
        WriteLine(ans);
    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)

struct Graph {
  struct edge {
    int to;
    i64 cap;
    i64 rev;
  };

  int n;
  vector<vector<edge>> edges;

  Graph(int N) {
    n = N;
    edges.resize(n, vector<edge>());
  }

  int size() const { return n; }

  vector<edge> &operator[](int v) { return edges[v]; }
};

struct Dinic {
  int N;
  vector<int> level;
  vector<int> itr;
  Graph G;

  Dinic(int n) : G(n) { N = n; }

  void add_edge(int from, int to, int cap, int rev_cap) {
    G[from].push_back({to, cap, (int)G[to].size()});
    G[to].push_back({from, rev_cap, (int)G[from].size() - 1});
  }

  bool g_level(int s, int t) {
    level.assign(N, -1);
    queue<int> que;
    que.push(s);
    level[s] = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (auto &e : G[v]) {
        if (e.cap > 0 && level[e.to] == -1) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
    return level[t] >= 0;
  }

  i64 dfs(int v, int t, i64 f) {
    if (v == t)
      return f;

    for (int &i = itr[v]; i < G[v].size(); i++) {
      auto &e = G[v][i];
      if (e.cap > 0 && level[e.to] > level[v]) {
        i64 mi_f = dfs(e.to, t, min(f, e.cap));
        if (mi_f > 0) {
          e.cap -= mi_f;
          G[e.to][e.rev].cap += mi_f;
          return mi_f;
        }
      }
    }
    return 0;
  }

  i64 max_flow(int s, int t) {
    i64 result = 0;
    i64 flow;
    while (g_level(s, t)) {
      itr.assign(N, 0);
      while ((flow = dfs(s, t, 1e9)) > 0)
        result += flow;
    }
    return result;
  }
};

/*

checked
    http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2723921#1
*/

int h;
int w;
int sx,sy,tx,ty;

vector<int> H[100],W[100];
int main(){
	cin >> h >> w;
	rep(i,0,h - 1){
		string s;
		cin >> s;
		rep(j,0,w - 1){
			if(s[j] == 'S'){
				sx = i;
				sy = j;
				H[i].push_back(j);
				W[j].push_back(i);
			}
			if(s[j] == 'T'){
				tx = i;
				ty = j;
				H[i].push_back(j);
				W[j].push_back(i);
			}
			if(s[j] == 'o'){
				H[i].push_back(j);
				W[j].push_back(i);
			}
		}
	}
	if(sx == tx || sy == ty){
		cout << -1 << endl;
		return 0;
	}
	Dinic dinic(h * w * 2 + 10);
	int MAX = h * w;
	for(int i = 0;i < MAX;i++){
		dinic.add_edge(i ,i + MAX,1,0);
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < H[i].size();j++){
			for(int k = j + 1;k < H[i].size();k++){
				int i1 = i * w + H[i][j];
				int i2 = i * w + H[i][k];
				dinic.add_edge(i1 + MAX, i2, 1000, 0);
				dinic.add_edge(i2 + MAX,i1, 1000, 0);
			}
		}
	}
	for(int i = 0;i < w;i++){
		for(int j = 0;j < W[i].size();j++){
			for(int k = j + 1;k < W[i].size();k++){
				int i1 = i + w * W[i][j];
				int i2 = i + w * W[i][k];
				dinic.add_edge(i1 + MAX, i2, 1000, 0);
				dinic.add_edge(i2 + MAX,i1, 1000, 0);
			}
		}
	}
	int s = sx * w + sy + MAX;
	int t = tx * w + ty;
	cout << dinic.max_flow(s,t) << endl;
}


Measured memory_bytes: 122240
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/join.hpp
#ifndef JOIN_HPP
#define JOIN_HPP


namespace tools {
  template <typename Iterator>
  std::string join(const Iterator begin, const Iterator end, const std::string delimiter) {
    std::ostringstream ss;
    std::string current_delimiter = "";
    for (Iterator it = begin; it != end; ++it) {
      ss << current_delimiter << *it;
      current_delimiter = delimiter;
    }
    return ss.str();
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/floor.hpp
#ifndef FLOOR_HPP
#define FLOOR_HPP


/*
usage:

tools::floor(5, 3) // => 1 (i.e., floor(5 / 3))
*/

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 K;
  std::cin >> K;

  const i64 N = 50;
  std::array<i64, N> a;
  for (i64 i = 0; i < K % N; ++i) {
    a[i] = 2 * N - 1 + tools::ceil(K, N) - K % N;
  }
  for (i64 i = K % N; i < N; ++i) {
    a[i] = N - 1 + tools::floor(K, N) - K % N;
  }

  std::cout << N << std::endl;
  std::cout << tools::join(a.begin(), a.end(), " ") << std::endl;
  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-11)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define MAX 17
int m,n;
double p[MAX][MAX];

double memo[MAX][1<<MAX]; // memo[今いる部屋の番号][倒された猫の状態] := この状態から最適な順番で猫を送り出して全ての敵を倒す確率の最大値

inline double dfs(int room_id, int cat_state) {
  if( room_id >= n ) {
    return 1.0;
  }
  double &cur_p = memo[room_id][cat_state];
  if( LTE(0,cur_p) ) return cur_p;
  cur_p = 0.0;
  rep(i,m) if( !( (cat_state>>i) & 1 ) ) {
    double q = 1.0, tmp = 0;
    REP(j,room_id,n) {
      // lose
      tmp += ( dfs(j,cat_state|(1<<i)) * q * ( 1.0 - p[i][j] ) );
      q = q * p[i][j];
    }
    // all win
    tmp += q;
    if( LT(cur_p,tmp) ) cur_p = tmp;
  }
  return cur_p;
}

void solve() {
  rep(i,n+1) rep(j,(1<<m)) memo[i][j] = -1;
  double maxi = dfs(0,0);
  printf("%.10f\n",maxi);
}

int main() {
  cin >> m >> n;
  rep(i,m) rep(j,n) cin >> p[i][j];
  rep(i,m) p[i][n] = 0.0; // 猫が全ての敵を倒した時用
  solve();
  return 0;
}



Measured memory_bytes: 11984
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;

typedef pair<int , int> P;
typedef pair<P,P> P2;

int h,w;
int g[30][30];
int d[30][30][25];

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

int r[4][6] = { {1,5,2,3,0,4},
		{3,1,0,5,4,2},
		{4,0,2,3,5,1},
		{2,1,5,0,4,3} };

vector<int> trans(int n){
  vector<int> res;
  while(n>0){
    res.push_back(n%6);
    n/=6;
  }
  while(res.size()<6)res.push_back(0);
  return res;
}

int rot(int n,int dir){
  int tmp[6];
  vector<int> die = trans(n);
  for(int i=0;i<6;i++)tmp[i] = die[r[dir][i]];

  int res = 0, k = 1;
  for(int i=0;i<6;i++){
    res += tmp[i] * k;
    k *= 6;
  }
  return res;
}

int main(){
  while(cin >> h >> w , h||w){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cin >> g[i][j];
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<25;k++)d[i][j][k] = 10000000;
      }
    }

    int sy,sx,gy,gx;
    cin >> sy >> sx >> gy >> gx;
    
    priority_queue<P2,vector<P2>,greater<P2> > q;
    map<int,int> m1,m2;
    m1[44790] = 1;
    m2[1] = 44790;
    q.push(P2(P(0,1),P(sy,sx)));
    d[sy][sx][1] = 0;
    int cnt = 2;

    int hoge = 0;
    while(!q.empty()){
      P2 p = q.top();q.pop();
      int s = p.first.first , num = p.first.second;
      int y = p.second.first , x = p.second.second;

      //cout << num << endl;

      for(int i=0;i<4;i++){
	int ny = y+dy[i], nx = x+dx[i];
	if(ny<0 || nx<0 || h<=ny || w<=nx)continue;
	int nnum = rot(m2[num],i);

	vector<int> die = trans(nnum);
	if(!m1[nnum]){
	  m1[nnum] = cnt;
	  m2[cnt] = nnum;
	  cnt++;
	}
	nnum = m1[nnum];

	if(d[ny][nx][nnum] > d[y][x][num] + g[ny][nx]*(die[5]+1)){
	  d[ny][nx][nnum] = d[y][x][num] + g[ny][nx]*(die[5]+1);
	  q.push(P2(P(d[ny][nx][nnum],nnum),P(ny,nx)));
	}
      }
    }

    int m = 10000000;
    for(int i=0;i<25;i++)m = min(m,d[gy][gx][i]);
    cout << m << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200005],n,k;
map<ll,ll> p;
bool check(ll x){
    ll num=0;
    for(ll i=1;i<n;i++){
        if(a[i]*a[i+1]>x&&a[i]*a[n]>x) continue;
        if(a[i]==0){
            num+=n-i;continue;
        }
        ll l=1,r=n-i;
        while(r>=l){
            ll mid=(l+r)/2;
            if(a[i]>0){
                if(a[i]*a[i+mid]>x) r=mid-1;
                else l=mid+1;
            }
            else{
                if(a[i]*a[n-mid+1]>x) r=mid-1;
                else l=mid+1;
            }
        }
        num+=r;
    }
    return num<k;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        p[a[i]]=1;
    }
    sort(a+1,a+1+n);
    ll l=-1e18,r=1e18;
    while(r>=l){
        ll mid=(l+r)/2;
        if(check(mid)) l=mid+1;
        else r=mid-1;
    }
    cout<<l<<endl;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

struct Edge{
    ll t, w;
    Edge(ll t, ll w): t(t), w(w){}
    bool operator<(const Edge &e){
        return w < e.w;
    }
};

int V, E;
vector<Edge> es[10010];
ll prim(int s){
    priority_queue<pll, vector<pll>, greater<pll>> Q;
    vi used(V);
    Q.push(pll(0, s));

    ll res = 0;
    while(!Q.empty()){
        auto p = Q.top(); Q.pop();
        ll cost = p.fi, v = p.se;
        if(used[v]) continue;
        used[v] = 1;
        res += cost;
        for(auto e : es[v]){
            Q.push(pll(e.w, e.t));
        }
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> V >> E;
    rep(i,E){
        ll s,t,w;
        cin >> s >> t >> w;
        es[s].emplace_back(t, w);
        es[t].emplace_back(s, w);
    }
    cout << prim(0) << endl;
    return 0;
}


Measured memory_bytes: 12488
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  set_ = set()
  for i in range(N):
    set_.add(input()[:-1])

  print(len(set_))

if(__name__ == '__main__'):
  main()


Measured memory_bytes: 89480
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

string S, T;
int dist[212345][26];

int main() {
	cin >> S >> T;
	int N = S.size();
	
	memset(dist, -1, sizeof(dist));
	
	S += S;
	for (int i = S.size() - 1; i >= 0; i--) {
		REP(j, 26) dist[i][j] = dist[i + 1][j];
		dist[i][S[i]-'a'] = i + 1;
	}
	
	ll ans = 0;
	int pos = 0;
	
	REP(i, T.size()) {
		int cur = dist[pos][T[i]-'a'];
		if (cur == -1) { ans = -1; break; }
		
		ans += cur - pos;
		pos = (cur - 1) % N + 1;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 22400
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    bool v = false;
    F0R(i, sz(s) - 1) if(s[i] == s[i + 1]) v = true;
    cout << (v ? "Bad" : "Good");
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,x;
  cin >> a >> b >> x;
  cout << (b / x) - (a / x) + (a % x == 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()
 
int main() {
  int A, P;
  cin >> A >> P;
  cout << (3 * A + P) / 2 << endl;
}

Measured memory_bytes: 3552
#include <stdio.h>

int main (void){

	long long int x;
	scanf("%lld", &x);

	long long int ans = 0;
	long long int syo = 0, amari = 0;

	syo = x / 11;
	amari = x % 11;		
	ans = syo * 2 + 1;

	if(amari == 0){
		printf("%lld\n", ans - 1);
		return 0;
	}else if(0 < amari && amari < 7){
		printf("%lld\n", ans);
		return 0;
	}else{
		printf("%lld\n", ans + 1);
		return 0;
	}
	 

}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	int n;
	vector<int>maxd, mind;
	while (cin >> n) {
		if (n == 0)break;
		int maxs, mins;
		maxs = 0;
		mins = 500;
		for (int k = 0; k < n; k++){
			int a = 0, b;
			for (int i = 0; i < 5; i++) {
				cin >> b;
				a += b;
			}
			maxs = max(maxs, a);
			mins = min(mins, a);
		}
		maxd.push_back(maxs);
		mind.push_back(mins);
	}
	for (int i = 0; i != maxd.size(); i++){
		cout << maxd[i] << ' ' << mind[i] << endl;
	}
	char c;
	cin >> c;
	return 0;
}

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void) {
  int i, j, k;
  char s[100010];
  scanf("%s%d", s, &k);
  for(i = 0; i < strlen(s) && k; ++i) {
    if(s[i] == 'a') continue;
    if('a' + 26 - s[i] <= k) k -= 'a' + 26 - s[i], s[i] = 'a';
  }
  k %= 26;
  s[strlen(s) - 1] += k;
  printf("%s", s);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	map<string, int> map;
	for(int a = 1; a <= n; a++) {
		string s = to_string(a);
		char FIRST = s[0];
		char SECOND = s.back();
		s.clear();
		s += FIRST;
		s += SECOND;
		++map[s];
	}
	assert((int) map.size() <= 100);
	long long answer = 0;
	for(pair<string, int> p : map) {
		string s = p.first;
		if(s[0] == s[1]) {
			int x = p.second;
			answer += (long long) x * x;
		}
		else {
			swap(s[0], s[1]);
			answer += (long long) p.second * map[s];
		}
	}
	cout << answer << endl;
}


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

int main(){

    int N;
    cin >> N;

    int index;
    vector<int> x(N), y(N), h(N);
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0) index = i;
    }

    int Cx, Cy, H;
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            int Hij = h[index] + abs(x[index] - i) + abs(y[index] - j);
            bool flag = true;
            for(int k = 0; k < N; k++){
                if(max(Hij - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                Cx = i;
                Cy = j;
                H = Hij;
            }
        }
    }

    cout << Cx << " " << Cy << " " << H << endl;

    return 0;
}

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

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

    long D[100005];
    for (long i = 0; i < n; i++) {
        cin >> D[i];
    }
    sort(D, D + n);

    long ans;
    ans = D[n / 2] - D[n / 2 - 1];

    cout << ans << endl;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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 bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    bool is4 = false;
    rep(i, n) {
      char s;  cin >> s;
      if (s == 'Y') {
        is4 = true;
        break;
      }
    }
    if (is4) {
      cout << "Four" << '\n';
    } else {
      cout << "Three" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int f(int num){
    if(num%2==1){
        return num*3+1;
    }
    else if(num%2==0){
        return num/2;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int d;
    vector<int> q;
    q.push_back(n);
    q.push_back(f(n));
    while(1){
        d=f(q[q.size()-1]);
        q.push_back(d);
        for(int i=0;i<q.size();i++){
            if(q[i]==d && i!=q.size()-1){
                if(i<q.size()){
                    cout << q.size() << endl;
                    return 0;
                }
                else if(i>q.size()){
                    cout << i+1 << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1000001/* your task*/
#define L 14
#define FALSE -1

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
   long sum = 0, p = 1, i;
   for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */key % M; }
int h2(int key){ return /* your task */1 + (key % (M-1)); }

int find(char str[]){

  /* your task */
  long long i,j,k;
  k = getKey(str);
  for(i=0; ;i++){
    j = (h1(k)+i*h2(k))%M;
    if(strcmp(H[j],str) == 0)return 1;
    else if(strlen(H[j]) == 0)return 0;
  }
  return 0;
}

int insert(char str[]){

  /* your task */
  long long i,j,k;
  k = getKey(str);
  for(i=0; ;i++){
    j = (h1(k)+i*h2(k))%M;
    if(strcmp(H[j],str) ==0)return 1;
    else if(strlen(H[j]) ==0){
      strcpy(H[j],str);
      return 0;
    }
  }
  
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if ( find(str) ==1 ){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



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

using namespace std;

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

int main(){
  int n;
  cin >> n;
  unordered_map<string, uint64_t> m;
  REP(i, n){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ++m[s];
  }
  uint64_t r = 0;
  for(auto it: m){
    r += it.second * (it.second - 1) / 2;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 10660
#include <stdio.h>

int main(){
  int n, a, b, c, d, i, j, k, h[5][4][11] = {};
  scanf("%d", &n);
  while(n--){
    scanf("%d%d%d%d", &a, &b, &c, &d);
    h[a][b][c] += d;
  }

  for(i = 1;i < 5;i++){
    for(j = 1;j < 4;j++){
      for(k = 1;k < 11;k++) printf(" %d", h[i][j][k]);
      puts("");
    }
    if(i != 4){
      for(k = 0;k < 20;k++) putchar('#');
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  int N, M; cin >> N >> M;

  int even = 0;
  int odd = 0;
  if (N > 1) even = N * (N - 1) / 2;
  if (M > 1) odd = M * (M - 1) /2;

  cout << even + odd << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; j <= n; j++ {
			if n < i+j {
				continue
			}

			if y == (10000*i + 5000*j + 1000*(n-(i+j))) {
				fmt.Printf("%d %d %d\n", i, j, n-(i+j))
				return
			}
		}
	}
	fmt.Println("-1 -1 -1")
}


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

int main() {
  string s; cin >> s;
  int blue = 0;
  
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) - '0' == 1) blue++;
  }
  
  cout << min(blue, (int)s.size() - blue) * 2 << endl;
}

Measured memory_bytes: 512
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = il()
    A = list(map(lambda x:x*-1, A))
    heapq.heapify(A)

    for _ in range(M):
        mn = heapq.heappop(A)*-1
        heapq.heappush(A, (mn//2)*-1)
    print(sum([a*-1 for a in A]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12884
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <set>
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+1>=c){
        cout<<b+c<<endl;
    }else{
        cout<<(a+b)+b+1<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[100005];
int main()
{
	int n;
   int k;
     while(scanf("%d",&n)!=EOF)
     {
     	k=0;
     	for(int i=0;i<n;i++)
     	{
     		scanf("%d",&a[i]);
     		k+=a[i];
		 }
		 printf("%d\n",k-n);
	 }
	return 0;
 } 

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

int main()
{

  int n;
  cin >> n;
  int a[n];
  rep(i, n){
    cin >> a[i];
  }
  int ans = 0;
  sort(a, a + n);
  rep(i, n){
    rep(j, n){
      rep(k, n){
        if(a[i] < a[j] && a[j] < a[k] && a[k] < a[i] + a[j]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main(){
  int N,K,R,cnt=0;
  bool boot[50][50],kigen[50];
  string str;
  memset(boot,false,sizeof(boot));
  memset(kigen,false,sizeof(kigen));
  cin >> N >> K;
  for(int i=0,n;i<K;i++){
    cin >> n;
    for(int j=0,a;j<n;j++){
      cin >> a;
      boot[i][a-1]=true;
    }
  }
  cin >> R;
  for(int i=0,a,b;i<R;i++){
    cin >> a >> b;
    for(int j=0;j<K;j++){
      if(boot[j][a-1]==true&&boot[j][b-1]==true){
	kigen[a-1]=kigen[b-1]=true;
	break;
      }
    }
  }
  for(int i=0;i<N;i++) if(kigen[i])cnt++;
  cout << cnt << endl;
}
//ソース適当(迫真

Measured memory_bytes: 1164
A, B = map(int, raw_input().split())

def f(X):
  if X<0:
    return 0
  a = 0
  for b in range(60):
    if b==0 and ((X+1)/2%2==1) or b>0 and (X>>b&1)==1 and (X&1)==0:
      a |= 1<<b
  return a

print f(B)^f(A-1)


Measured memory_bytes: 2568
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
char Maze[21][21];
int D[21][21];

int BFS(int sx,int sy,int gx,int gy){
	queue<P> que;
	int dx[]={1,0,-1,0};
	int dy[]={0,1,0,-1};
	REP(i,N)REP(j,M){
		D[i][j]=INF;
	}
	que.push(P(sx,sy));
	D[sx][sy]=0;
	while(!que.empty()){
		P p=que.front();
		que.pop();
		if(p.first==gx && p.second==gy){
			break;
		}
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i];
			int ny=p.second+dy[i];
			if(0<=nx && nx<N && 0<=ny && ny<M && Maze[nx][ny]!='#' && D[nx][ny]==INF){
				que.push(P(nx,ny));
				D[nx][ny]=D[p.first][p.second]+1;
			}
		}
	}
	return D[gx][gy];
}

signed main(){
	cin>>N>>M;
	REP(i,N){
		cin>>Maze[i];
	}
	int d=0;
	REP(i,N){
		REP(j,M){
			REP(k,N){
				REP(l,M){
					if(Maze[i][j]=='#')continue;
					if(Maze[k][l]=='#')continue;
					int dis=BFS(i,j,k,l);
						d=max(d,dis);
				}
			}
		}
	}
	cout<<d<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
  } else if (h % 2 == 0 || w % 2 == 0) {
    cout << h * w / 2 << endl;
  } else {
    cout << (h - 1) * w / 2 + (w + 1) / 2 << endl;
  }
}


Measured memory_bytes: 256
def generate_id(p, x):
    return str(p).zfill(6) + str(x).zfill(6)

N, M = map(int, input().split())

A = []
B = {}
C = {}

for _ in range(M):
    a = tuple(map(int, input().split()))
    A.append(a)

    if a[0] in B:
        t = B[a[0]]
        t.append(a[1])
        B[a[0]] = t
    else:
        B[a[0]] = [a[1]]

for k, vs in B.items():
    vs = sorted(vs)
    for i, v in enumerate(vs):
        C[(k, v)] = i + 1

for a in A:
    print(generate_id(a[0], C[a]))


Measured memory_bytes: 49836
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#define long long int
using namespace std;
int main()
{
	string a;
	cin>>a;
	int s=0;
	for(int i=0;i<a.size();i++)
	{
		int k=a[i]-48;
		s=s+k;

	}
	if(s%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
		
}


Measured memory_bytes: 3672
#C
A, B, H, M= map(int,input().split())
import math
theta_S=-(30*H+(1/2)*M)+90
theta_L=-(6*M)+90
S_x=A*math.cos(math.radians(theta_S))
S_y=A*math.sin(math.radians(theta_S))
L_x=B*math.cos(math.radians(theta_L))
L_y=B*math.sin(math.radians(theta_L))
distance=((S_x-L_x)**2+(S_y-L_y)**2)**0.5
print(distance)

Measured memory_bytes: 9584
n = int(input())
count = 0
for i in range(105, n + 1):
    insu = 0
    if i % 2 == 0:
        continue
    for j in range(1, i + 1):
        if i % j == 0:
            insu += 1
    if insu == 8:
        count += 1
print(count)


Measured memory_bytes: 2940
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W = MAP()
s = [input() for _ in range(H)]

cnt = [[-1]*W for _ in range(H)]

if s[0][0] == ".":
	cnt[0][0] = 0
else:
	cnt[0][0] = 1

dy = [0, 1]
dx = [1, 0]

q = deque([(0, 0)])
while q:
	y, x = q.popleft()
	for i in range(2):
		ny = y + dy[i]
		nx = x + dx[i]
		if ny < H and nx < W and cnt[ny][nx] == -1:
			if s[ny][nx] == s[y][x]:
				cnt[ny][nx] = cnt[y][x]
				q.appendleft((ny, nx))
			else:
				cnt[ny][nx] = cnt[y][x] + 1
				q.append((ny, nx))

if s[H-1][W-1] == "#":
	ans = (cnt[H-1][W-1]+1)//2
else:
	ans = (cnt[H-1][W-1])//2
print(ans)


Measured memory_bytes: 10484
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int l,r;
  cin>>l>>r;
  if(l<=2019&&2019<=r){
    cout<<0<<endl;
  }else if(r<2019){
    int ans=2019;
    FOR(i,l,r+1){
      FOR(j,i+1,r+1){
        ans=min(ans,(i*j)%2019);
      }
    }
    cout<<ans<<endl;
  }else{
    int ans=2019;
    for(int i=l;i<=min(l+2019,r);i++){
      for(int j=i+1;j<=min(l+2019,r);j++){
        ans=min(ans,(i*j)%2019);
      }
    }
    cout<<ans<<endl;
  }

}




Measured memory_bytes: 256
def solve(A, B):
    from math import sqrt
    M = A * B
    cnt = 0

    x, y = A, B
    if y - x >= 1:
        z = int(sqrt(M))
        x = z
        y = M // x if M % x else M // x - 1
        cnt += z - A
    cnt += y - 1

    x, y = B, A
    if y - x >= 1:
        z = int(sqrt(M))
        x = z
        y = M // x if M % x else M // x - 1
        cnt += z - B
    cnt += y - 1

    return cnt


Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]

for A, B in Query:
    print(solve(A, B))


Measured memory_bytes: 38256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();
      int M = sc.nextInt();
      List<Entry> entryList = new LinkedList<>();
      for ( int j = 0; j < M; j++ ) {
        int P = sc.nextInt();
        int Y = sc.nextInt();
        entryList.add(new Entry(j+1, P, Y));
      }
      List<Entry> calcList = new LinkedList<>(entryList);
      Collections.sort(calcList
          , new Comparator<Entry>() {
                public int compare(Entry o1, Entry o2) {
                  return o1.Y - o2.Y;
                }
          }
          );
      Map<Integer,Integer> orderMap = new HashMap<Integer,Integer>();
      for ( Entry entry : calcList ) {
        int P = entry.P;
        Integer order = orderMap.get(P);
        if ( order == null ) {
          order = 1;
        }
        else {
          order = order.intValue() + 1;
        }
        entry.setIdBy(order);
        orderMap.put(P, order);
      }
      for ( Entry entry : entryList ) {
        System.out.println(entry.id);
      }
    }
  }
  
  private static class Entry {
    private final int i;
    private final int P;
    private final int Y;
    
    private volatile String id;
    
    public Entry(int i, int P, int Y) {
      this.i = i;
      this.P = P;
      this.Y = Y;
    }
    
    public void setIdBy(int x) {
      id = String.format("%06d%06d", P, x);
    }
  }
}

Measured memory_bytes: 172560
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        int smin=n;
        for(int z=0; z*z*z<=n; z++){
            int diff = n-z*z*z;
            int y = sqrt(diff);
            int x = diff - y*y;
            smin = min(x+y+z ,smin);
        }
        cout << smin << endl;
    }
    return 0;
}

Measured memory_bytes: 3016
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int n,m, ns,tu; int ans = 0;
	string na;
	cin >> n >> na;
	ns = na.size();
	for (int i = 0; i < n; i++) {
		string ka;
		cin >> ka;
		int kas = ka.size();
		int ok = 0;
		for (int hab = 1; (hab*(ns-1) < kas) and ok == 0; hab++) {
			for (int j = 0; ok == 0 and hab*(ns - 1)+ j < kas; j++) {
				ok = 1;
				for (int ch = 0; ok == 1 and ch<ns; ch++) {
					if (na[ch] != ka[j + hab * ch]) {
						ok = 0;
					}
				}
			}
		}
		ans = ans +ok;
	}
	cout << ans<<endl;
}



Measured memory_bytes: 3196