akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int turn = 0;
    while(1){
        c -= b;
        if(c<=0) break;
        turn++;
        a -= d;
        if(a <= 0) break;
        turn++;
    }
    cout << ((turn%2)?"No":"Yes") << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, k;
  cin >> n >> k;
  int res = 0;
  for(int i = 0; i < n; ++i) {
  	int x;
  	cin >> x;
  	if(x >= k) {
  		++res;
  	}
  }
  cout << res << endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n; 
    map<pair<int,int>, int> m;
    for(int i=1; i<n+1; i++){
        string s = to_string(i);
        auto e = pair<int, int>(s.front()-'0', s.back()-'0');
        m[e]++;
    }
    
    int ans = 0;
    for(int i=1; i<n+1; i++){
        string s = to_string(i);
        auto e = pair<int, int>(s.back()-'0', s.front()-'0');
        ans += m[e];
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    long int a,max,min,sum;

    cin>>a;
    long int x[a];

    for(int i=0; i<a; i++){
        cin>>x[i];
    }
    max=min=sum=x[0];
    for(int i=1; i<a; i++){
        if(max<x[i]){
            max=x[i];
        }
    }
    for(int i=1; i<a; i++){
        if(min>x[i]){
            min=x[i];
        }
    }

    for(int i=1; i<a; i++){
        sum=sum+x[i];
    }

    cout<<min<<' '<<max<<' '<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3148
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var text = Console.ReadLine();
            var ans = 0;
            for (var i = 0; num > i; i++)
            {
                if ((num - i) > 2)
                {
                    if ((text[i] == 'A') && (text[i + 1] == 'B') && (text[i + 2] == 'C')) ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main(void){
	int i;
    char s[]="abcdefghijklmnopqrstuvwxyz";
    char t='a';
    char u='a';

    scanf("%c",&t);
  
    for(i=0;i<26;i++){
        if(s[i] == t){
            u = s[i+1];
        }
    }

    printf("%c",u);
    
}

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

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

long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod)%1000000007;
}

int main(){
  long long int N;
  vector<long long int> x;
  cin >> N;
  long long int N_ex=1;
  for(int i=0;i<N;i++){
    long long int tmp; cin >> tmp;
    x.push_back(tmp);
  }
  for(int i=1;i<=N-1;i++){
    N_ex=(N_ex*i)%1000000007;
  }
  long long int ans = 0;
  for(long long int i=1;i<=N-1;i++){
    ans =(ans + (N_ex*modinv(i, 1000000007) % 1000000007*(x[N-1]-x[i-1]) % 1000000007)) % 1000000007;
  }
  //if(ans<0){ans=ans+1000000007;}
  cout << ans;
  return 0;
}


Measured memory_bytes: 1400
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
	do {\
		std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
		debug_impl(__VA_ARGS__);\
		std::cerr << std::noboolalpha;\
	} while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
	{ for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
	for (auto it = v.begin(); it != v.end(); it++)
		{os << (it != v.begin() ? "," : "") << *it;}
	return os << "}";
}

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<int> a(n); std::cin>>a;

	int max = *std::max_element(all(a));
	cmx(max, 3);
	std::vector<int> mul(max+1,0);
	for (int x : a) mul.at(x)++;

	int ans = 0;
	rep(i,0,max-1) {
		int now = std::accumulate(mul.begin()+i,mul.begin()+i+3,0);
		cmx(ans, now);
	}
	std::cout << ans << std::endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  a.insert(a.begin(), 0);
  a.push_back(0);
  ll init = 0;
  rep(i, n+1) init += abs(a[i+1]-a[i]);

  for(int i = 1; i <= n; ++i) cout << init-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i+1]-a[i-1]) << endl;
}

Measured memory_bytes: 1656
import math

line=input().split()
line=[int(i) for i in line]
time=line[2]*60+line[3]
xhour=line[0]*math.cos((2*math.pi*time)/720)
yhour=line[0]*math.sin((2*math.pi*time)/720)
xmin=line[1]*math.cos((2*math.pi*time)/60)
ymin=line[1]*math.sin((2*math.pi*time)/60)
ans=math.sqrt(((xhour-xmin)**2)+((yhour-ymin)**2))
print(ans)

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

const int MAX_N = 200005;
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
  bool operator==(const mint a) const { return x == a.x; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
} comb(MAX_N);

vector<int> to[MAX_N];

struct DP {
  mint dp;
  int t;
  DP(mint dp = 1, int t = 0) : dp(dp), t(t) {}
  DP operator+(const DP& a) const {
    return DP(dp * a.dp * comb(t + a.t, t), t + a.t);
  }
  DP operator-(const DP& a) const {
    return DP(dp / a.dp / comb(t, t - a.t), t - a.t);
  }
  DP addRoot() const { return DP(dp, t + 1); }
};

vector<DP> dp[MAX_N];
DP ans[MAX_N];

DP dfs(int v, int p = -1) {
  DP dpSum;
  dp[v] = vector<DP>(to[v].size());
  rep(i, to[v].size()) {
    int u = to[v][i];
    if (u == p) continue;
    dp[v][i] = dfs(u, v);
    dpSum = dpSum + dp[v][i];
  }
  return dpSum.addRoot();
}
void bfs(int v, const DP& dpP = DP(), int p = -1) {
  int deg = to[v].size();
  rep(i, deg) {
    if (to[v][i] == p) dp[v][i] = dpP;
    ans[v] = ans[v] + dp[v][i];
  }
  rep(i, deg) {
    int u = to[v][i];
    if (u == p) continue;
    DP d = ans[v] - dp[v][i];
    bfs(u, d.addRoot(), v);
  }
  ans[v] = ans[v].addRoot();
}

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  bfs(0);
  rep(i, n) cout << ans[i].dp << endl;
}

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

using namespace std;

const int MOD = 998244353;

long long int powmod(long long int x, long long int n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % MOD;
        x = (x * x) % MOD;
        n >>=1;
    }
    
    return res;
}

int main(void) {
    int n;
    cin >> n;
    vector<int> D(n);
    for (int i = 0; i < n; ++i) {
        cin >> D[i];
    }
    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    
    map<int, int> M;
    for (int i = 0; i < n; ++i) {
        ++M[D[i]];
    }
    if (M[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
  
    int pred = -1;
    vector<int> dcnt;
    for (auto itr = M.begin(); itr != M.end(); ++itr) {
        int curd = itr->first;
        if (curd != pred + 1) {
            cout << 0 << endl;
            return 0;
        }
        dcnt.push_back(itr->second);
        pred = curd;
    }
    
    long long res = 1;
    for (int i = 0; i < (int)dcnt.size() - 1; ++i) {
        res *= powmod(dcnt[i], dcnt[i + 1]);
        res %= MOD;
    }
    cout << res << endl;
    
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	pair<int, int> p[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>p[i].first;
		p[i].second=i;
	}
	sort(p, p+n);
	reverse(p, p+n);
	multiset<int> memo={-1,-1,n,n};
	long long ans=0LL;
	for (int i = 0; i < n; ++i)
	{
		auto itr=memo.insert(p[i].second);
		--itr;
		int l1=*itr;
		--itr;
		int l2=*itr;
		++itr,++itr,++itr;
		int r1=*itr;
		++itr;
		int r2=*itr;
		int cnt=(l1-l2)*(r1-p[i].second)+(p[i].second-l1)*(r2-r1);
		ans+=(long long)p[i].first*cnt;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5760
import numpy as np
n, k = map(int, input().split())
#nlist = np.array(list(map(int, input().split())))
#print(len(nlist[nlist>=k]))
nlist = list(map(int, input().split()))
cnt = 0
for i in nlist:
    if i >= k:
        cnt += 1
print(cnt)


Measured memory_bytes: 20904
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 3000;
double dp[mxn][mxn];
bool c[mxn][mxn];
int n;
double p[mxn];

double f(int i,int j)
{
	if(c[i][j])
		return dp[i][j];
	if(i == 0 && j == 0)
		dp[i][j] = (double)1;
	else if(i == 0)
		dp[i][j] = ((double)1 - p[i + j]) * f(i,j - 1);
	else if(j == 0)
		dp[i][j] = p[i + j] * f(i - 1,j);
	else
		dp[i][j] = p[i + j] * f(i - 1,j) + ((double)1 - p[i + j]) * f(i,j - 1);
	c[i][j] = 1;
	return dp[i][j];
}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	FOR(i,1,n)
		cin >> p[i];
	int k = (n + 1) / 2;
	double ans = 0;
	memset(c,0,sizeof(c));
	FOR(count,k,n)
		ans += f(count,n - count);
	cout << fixed << setprecision(12) << ans;	

	return 0;
}

Measured memory_bytes: 51072
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<iostream>
#define inf 1000000001LL
#define ll long long

using namespace std;

long long lx=inf,rx=-inf,uy=-inf,dy=inf;

long long _min(long long a,long long b){if(a<b)return a; return b;}
long long _max(long long a,long long b){if(a>b)return a; return b;}

struct node{ll y; ll x;}p[60];

int main(){
	int N,K,cnt;
	long long Ans=5e18;
	scanf("%d%d",&N,&K);
	int i,j,k,l,ii;
	
	for(i=1;i<=N;i++)
		scanf("%lld%lld",&p[i].x,&p[i].y);
	
	for(i=1;i<=N;i++)
		for(j=i;j<=N;j++)
			for(k=j;k<=N;k++)
				for(l=k;l<=N;l++){
					lx=_min(_min(p[i].x,p[j].x),_min(p[k].x,p[l].x));
					rx=_max(_max(p[i].x,p[j].x),_max(p[k].x,p[l].x));
					uy=_max(_max(p[k].y,p[l].y),_max(p[i].y,p[j].y));
					dy=_min(_min(p[i].y,p[j].y),_min(p[k].y,p[l].y));
					cnt=0;
					for(ii=1;ii<=N;ii++)
						if(p[ii].x>=lx&&p[ii].x<=rx&&p[ii].y>=dy&&p[ii].y<=uy)cnt++;
					//printf("%d\n",cnt);
					if(cnt>=K&&(rx-lx)*(uy-dy)<Ans)Ans=(rx-lx)*(uy-dy);
				}
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 256
/*
 *  Created by Andrei Arhire 02/08/2020
 *  Copyright © 2020 Andrei Arhire. All rights reserved.
 */
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long
#define llf __float128
#define lld long double
using namespace std;
const lll NR = 1e5 + 10  ,oo = 2e9 + 10, MOD = 1e9 + 7 ;
const long double pi = 2*acos(0.0);

lll cnt , d , n , x , y ;
map < int , int > mapp ;
int new_ , k ;
signed main () {
    int i ;

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0) ;
   cin >> k ;
   if ( 7 % k == 0 )    return cout << 1  , 0 ;
   new_ = 7 ;
   for ( i = 2 ; i <= 10000000 ; ++ i )    {
       new_ = ( new_ * 10 + 7 ) % k ;
       if ( mapp [ new_ ] ) return cout << -1 , 0 ;
       if ( new_ == 0 ) return cout << i << '\n' , 0 ;
    mapp [ new_ ] = 1 ;
   }
    return 0 ;
}


Measured memory_bytes: 50512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
    int N;
    cin >> N;
    vector<int> sea(N);
    vector<int> mt(N);
    vector<int> home(N);
    vector<vector<int>> dp(N,vector<int>(3)); 

    for(int i = 0;i < N;i++){
        cin >> sea[i] >> mt[i] >> home[i];
    }

    dp[0][0] = sea[0];
    dp[0][1] = mt[0];
    dp[0][2] = home[0];
    for(int i = 1;i < N;i++){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + sea[i];
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + mt[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + home[i];
    }

    cout << *max_element(dp[N-1].begin(),dp[N-1].end()) << endl;
    return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> num(n+1,0);
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  rep(i,n){
    num[a[i]]++;
  }
  int res=0;
  rep1(i,n){
    res+=num[i]*(num[i]-1)/2;
  }
  res-=num[a[0]]-1;
  cout<<res<<"\n";
  rep1(i,n-1){
    res+=num[a[i-1]]-1;
    res-=num[a[i]]-1;
    cout<<res<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 5760
str = input()
chars = list(str)
input_len = len(chars)

count = 0
if input_len % 2 == 0:
  mid = input_len//2
  s1 = chars[0:mid]
  s2 = chars[mid:input_len]
  for x, y in zip(s1,s2[::-1]):
    if x != y:
      count += 1

else:
  mid = (input_len//2) + 1
  s1 = chars[0:mid-1]
  s2 = chars[mid:input_len]
  for x, y in zip(s1,s2[::-1]):
    if x != y:
      count += 1
print(count)

Measured memory_bytes: 3064
import Data.List
main=do
 getLine
 a<-map(negate.read).words<$>getLine
 bc<-map((\[b,a]->(-a,b)).map read.words).lines<$>getContents
 let x=sort$bc++zip a(repeat 1)
 print$negate$f x(length a)
f((a,c):x)t
 |t>c=a*c+f x(t-c)
 |otherwise=a*t

Measured memory_bytes: 123260
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define mem(x,val) memset(x,val,sizeof(x))
//#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int,pii>
 
const int mod=1e9+7;
const int N=1e5+10;
const int MAXN=2e6+10;
const int INF=1e18;

int a[2*N];

void solve(){
    int n;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
    }
    int ans=0,mx=a[1];
    rep(i,2,n){
        if(a[i]<mx){
            ans+=(mx-a[i]);
        }
        mx=max(mx,a[i]);
    }
    cout<<ans<<endl;
}


int32_t main()
{
//     #ifndef ONLINE_JUDGE
//         freopen("inputf.in", "r", stdin);
//         //freopen("outputf.in", "w", stdout);
//     #endif
    SPEED;
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {  
        //cout<<"Case #"<<t1<<": ";
        solve();
        t1++;
        if(t1>T)
            break;
    }
}


Measured memory_bytes: 5216
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
 
int main() {
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> a2b;
 
    for (int i=0; i < n; i++){
        int a, b;
        cin >> a >> b;
        a2b[a].push_back(b);
    }
 
    priority_queue<int> pri_que;
    int ans = 0;
 
    for (int day=m; day>=0; day--) {
        int deadline = m - day;
        if (deadline >= 0) {
            vector<int> rewards = a2b[deadline];
            for(auto r: rewards) pri_que.push(r);
            if(!pri_que.empty()){
                ans += pri_que.top();
                pri_que.pop();
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int64_t x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<int64_t> a(x), b(y), c(z);
    for (auto& e : a) cin >> e;
    for (auto& e : b) cin >> e;
    for (auto& e : c) cin >> e;
    vector<int64_t> ab;
    for (auto& e : a) {
        for (auto& f : b) {
            ab.push_back(e + f);
        }
    }
    sort(ab.begin(), ab.end(), greater<int64_t>());
    vector<int64_t> abc;
    for (int64_t i = 0; i < min(k, (int64_t) ab.size()); i++) {
        for (auto& e : c) {
            abc.push_back(ab[i] + e);
        }
    }
    sort(abc.begin(), abc.end(), greater<int64_t>());
    for (int64_t i = 0; i < k; i++) {
        cout << abc[i] << endl;
    }
}

Measured memory_bytes: 42856
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int N;

	cin >> N;
	vector<int> X(N),sorted(N);

	for (int i = 0; i < N; i++) {
		cin >> X[i];
		sorted[i] = X[i];
	}

	sort(sorted.begin(), sorted.end());

	for (int i = 0; i < N; i++) {
		if (lower_bound(sorted.begin(), sorted.end(), X[i])- sorted.begin() < N / 2 ) {
			cout << sorted[N / 2] << endl;
		}
		else {
			cout << sorted[N / 2-1] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3712
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
int main()
{
	string s;
	int chk,l;
	map <char,int> mp;
	cin>>s;
	if(s.size()<26)//长度少于26，直接在后面加"尾巴 "
	{
		for(int i=0;i<s.size();i++) mp[s[i]]++;//有过的是1，没有出现过的是0 
		for(char j='a';j<='z';j++) 
			if(!mp[j])//发现最小的一个是0的，输出 
			{
				cout<<s<<j;
				rt0;
			}
	}//长度少于26的一定会有结果，不用写else
	
	for(int i=s.size()-1;i>=0;i--)//从后往前试着改 
	{
		for(char k=s[i]+1;k<='z';k++)//看当时的最后一个字符可以改成比它大的哪一个字符 
		{
			for(l=0;l<s.size();l++)//排除重复的字符 
				if(k==s[l])	break;
			if(l==s.size())//循环自然结束，找到结果 
			{
				s.pop_back();//弹飞要改的那一个 
				cout<<s<<k;
				rt0;
			}
		}
		s.pop_back();//弹飞没用的 
	}
	cout<<"-1";//没找到就输出无解 
    rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A,B,M;
  cin>>A>>B>>M;
  vector<int> a(A);
  for(int i=0;i<A;i++)
    cin>>a.at(i);
  vector<int> b(B);
  for(int i=0;i<B;i++)
    cin>>b.at(i);
  vector<vector<int>> c(M,vector<int>(3));
  for(int i=0;i<M;i++){
    for(int j=0;j<3;j++)
      cin>>c.at(i).at(j);
  }
  long long min=a.at(0)+b.at(0);
  for(int i=0;i<M;i++){
    if(a.at(c.at(i).at(0)-1)+b.at(c.at(i).at(1)-1)-c.at(i).at(2)<min)
      min=a.at(c.at(i).at(0)-1)+b.at(c.at(i).at(1)-1)-c.at(i).at(2);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(a.at(0)+b.at(0)<min)
    min=a.at(0)+b.at(0);
  cout<<min<<endl;

}


Measured memory_bytes: 9484
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var js = new int[h[0]].Select(_ => Read()).ToLookup(j => j[0], j => j[1]);

		var r = 0;
		var pq = PQ<int>.Create(null, true);
		for (var i = 1; i <= h[1]; i++)
		{
			foreach (var b in js[i]) pq.Push(b);
			if (pq.Any()) r += pq.Pop();
		}
		Console.WriteLine(r);
	}
}

class PQ<T> : List<T>
{
	public static PQ<T> Create(T[] vs = null, bool desc = false)
	{
		var c = Comparer<T>.Default;
		return desc ?
			new PQ<T>(vs, (x, y) => c.Compare(y, x)) :
			new PQ<T>(vs, c.Compare);
	}

	Comparison<T> c;
	public T First => this[0];

	PQ(T[] vs, Comparison<T> _c)
	{
		c = _c;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j) { var o = this[i]; this[i] = this[j]; this[j] = o; }
	void UpHeap(int i) { for (int j; i > 0 && c(this[j = (i - 1) / 2], this[i]) > 0; Swap(i, i = j)) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count;)
		{
			if (j + 1 < Count && c(this[j], this[j + 1]) > 0) j++;
			if (c(this[i], this[j]) > 0) Swap(i, i = j); else break;
		}
	}

	public void Push(T v)
	{
		Add(v);
		UpHeap(Count - 1);
	}
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


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

using namespace std;


int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    
    long long x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    long long ans = min(k, x / d);
    k -= ans;
    x -= d * ans;
    if(k != 0){
        if(k % 2 == 0)
            cout << x;
        else
            cout << d - x;
    } else
        cout << x;


}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)
#define f first
#define se second
#define M 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<long long, long long>
#define vi vector<int>
#define ll long long


int main(){
 ll n,k;
 cin>>n>>k;
 ll cc[n+1],pos[n+1],vis[n+1]={0};
 for(int i=1;i<=n;i++){
	 cin>>pos[i];
 }
 int t=0,st=1,c_st,c_size;
 cc[1]=0;
 while(1){
	 if(t==k){
		 cout<<st;
		 return 0;
	 }
	 if(vis[pos[st]]==1){
		 c_st=pos[st];
		 c_size=cc[st]-cc[c_st]+1;
		 break;
	 }
	 vis[st]=1;
	 st=pos[st];
	 cc[st]=t+1;
	 t++;
 }
 //cout<<c_size<<endl;
 k-=max((ll)0,cc[c_st]);
 k=k%c_size;
 for(int i=1;i<=k;i++){
	 c_st=pos[c_st];
 }
 cout<<c_st;
} 


Measured memory_bytes: 8312
#include<stdio.h>
int main()
{
	int x,y,z,i,a;
	scanf("%d%d%d",&x,&y,&z);
	i=1;
	x=x-z*2;
	a=x;
	while(a>0){
		a=x-i*y-(i-1)*z;
		if(a<0){
			break;
		}
		i+=1; 
  	}
	printf("%d",i-1);
}

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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
const ll M = 1000000007;
signed main() {
    ll n;
    string s,t;
    cin>>n>>s>>t;
    ll a=1;
    REP(i,n){
        if(i==0){
            a*=3;
            if(s[i]!=t[i]){
                a*=2;
                i+=1;
            }
        }else{
            // 12 12 13 13 11 | 11 12
            // 12 13 23 24 22 | 23 33
            if(s[i]==t[i]){
                if(s[i-1]==t[i-1])a*=2;
            }else{
                if(s[i-1]==t[i-1])a*=2;
                if(s[i-1]!=t[i-1])a*=3;
                i+=1;
            }
        }
        a%=M;
    }
    cout<<a<<endl;
}


Measured memory_bytes: 256
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) begin(x),end(x)
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
string s;
int main(){
    fast,cin>>s;
    int A = 0,B = 0;
    for(int i=0;i<s.size();i++){
        A += (s[i] == 'A');
        B += (s[i] == 'B');
    }
    if(!A || !B) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;

vector<ll> a;
vector<vector<int> > g;  // to

bool dfs(int par, int curr, ll& ans)
{
    int siz=(int)g[curr].size();
    int i;
    ll sum=0;
    int cnt=0;
    ll max=0;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(par==next) continue;

        cnt++;
        ll ret=0;
        if(!dfs(curr, next, ret)) {
            return false;
        }
        max=MAX(max,ret);
        sum+=ret;
    }
    if(cnt==0) {
        ans=a[curr];
    }
    else if(curr==0 && cnt==1) {
        ans=a[curr]-sum;
    }
    else {
        ans=a[curr]*2-sum;
        max=MAX(max,ans);
        if(max>a[curr]) {
            return false;
        }
    }
    if(ans<0) {
        return false;
    }
    return true;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    a.resize(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    g.resize(n);
    for(i=0; i<n-1; i++) {
        int p,q;
        scanf("%d%d", &p, &q); p--; q--;
        g[p].push_back(q);
        g[q].push_back(p);
    }
    ll ret=0;
    bool ok=dfs(-1,0,ret);
    if(!ok || ret!=0) {
        printf("NO\n");
    }
    else {
        printf("YES\n");
    }

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
ll inf = 1e10;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int f[n+1][11];
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= 10; ++j) cin >> f[i][j];
  }
  int p[n+1][11];
  for(int i = 1; i <= n; ++i){
    rep(j, 11) cin >> p[i][j];
  }
  ll ans = inf*(-1);
  for(int i = 1; i < (1<<10); ++i){
    ll benefit = 0;
    for(int j = 1; j <= n; ++j){
      int cnt = 0;
      for(int k = 1; k <= 10; ++k) if(i & (f[j][k] << (k-1))) cnt++;
      benefit += p[j][cnt];
    }
    ans = max(ans, benefit);
  }
  cout << ans << "\n";
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef pair<ll, ll> pll;

const int INF = 1000000010;
const ll MOD = 1000000007;

int main() {FIN
	
	ll n, i, t, m = 0, s = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> t;
		s += max(m-t, 0LL);
		m = max(m, t);
	}
	cout << s << "\n";
		
	return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20200719AtCorder
{
    class Class1
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').ToArray();
            var result = Math.Sqrt(int.Parse(nums[0] + nums[1]));

            if (result == (int)result)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main(){
  int r, d , x;
  cin >> r >> d >> x;
  
  int sum = x;
  for(int i = 0; i < 10; i++){
    sum = sum*r - d;
    cout << sum << endl;
  }
}

  
  

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S;
  cin >> S;
  if (S[0] == S[1] && S[1] == S[2]) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  if (N <= 9){
    cout << N << endl;
  } else if(N >= 10 && N <= 99){
      cout << 9 << endl;
  } else if(N >= 100 && N <= 999){
      cout << 9 + (N - 99) << endl;
  } else if (N >= 1000 && N <= 9999){
      cout << 909 << endl;
  } else if (N >= 10000 && N <= 99999){
      cout << 909 + (N - 9999) << endl;
  } else if (N == 100000){
      cout << 90909 << endl;
  }   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rin(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rin(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 a,p;
  cin >> a >> p;
  p += a * 3;
  cout << p / 2 << endl;
}


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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1)
    cout << '1' << endl;
  else if (H%2 && W%2) {
    cout << H*(W-1)/2+H/2+1 << endl;
  }
  else {
    cout << H*W/2 << endl;
  }
}


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

int main() {
    int K, S;
    cin >> K >> S;
    int X, Y, Z;

    int sum = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            X = i;
            Y = j;
            Z = S - X - Y;
            if(0 <= Z && Z <= K){
                sum++;
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }

    val buka = a.groupBy { it }.mapValues { it.value.size }
    (1..n).map {
        buka.getOrDefault(it, 0)
    }.joinToString("\n")
})

Measured memory_bytes: 109592
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <string.h>
 
long long int sub(long long int n)
{
  long long int d=1;
  int i;
for(i=1;i<=2;i++)
{
  d=d*(n-i+1)/i;
}
  return d;
}
int main(void)
{
  long long int x,y,a=0,b=0,i;
  
  scanf("%lld %lld",&x,&y);
  
  if(x>2)
  {
    a=sub(x);
  }
  else if(x==2)
  {
    a=1;
  }
    
    
  if(y>2)
  {
    b=sub(y);
  }
  else if(y==2)
  {
    b=1;
  }
  
  i=a+b;
  
  
  printf("%lld",i);
  
  return 0;
}

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

using namespace std;

long long n;

int main(){
    while(cin >> n, n){
	long long a = 5;
	long long res = 0;
	while(a <= n){
	    res += n / a;
	    a *= 5;
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n,k;
    cin>>n>>k;
    vector<int> v(n);


    rep(i,n){
        cin>>v[i];

    }

    int ans=0;
    int lim=min(n,k);
    vector<int> lt;
    int sum1=0;


    for(int l=0;l<=lim;l++){
        if(l!=0){lt.push_back(v[l-1]);sum1+=v[l-1];}
        vector<int> rt;
        rt=lt;
        int sum2=sum1;


        for(int r=0;r<=lim-l;r++){

            if(r!=0){
                sum2+=v[n-r];
                rt.push_back(v[n-r]);
            }

          int sum=sum2;

            int a=k-(l+r);
            int b=rt.size();

            sort(rt.begin(),rt.end());
            for (int tt = 0; tt <= min(a, b); tt++) {
                if(tt!=0){ sum-= rt[tt-1];}
                if (ans < sum) {
                    ans = sum;
                }
            }
            //cout<<l<<" "<<r<<" "<<ans<<endl;
        }
    }

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
 
  ll N , M ;
  cin >> N >> M ;
  ll ans[N][2] ;
  rep(i,N) ans[i][0] = 0 ;
  rep(i,N) ans[i][1] = 0 ;
  vector<ll> A(M) ;
  vector<string> B(M) ;
  rep(i,M){
    cin >> A.at(i) >> B.at(i) ;
    //cout << A.at(i) << B.at(i) <<endl;
    if(B.at(i)=="AC") ans[A.at(i)-1][0] = 1 ;
    if(B.at(i)=="WA"){
      if(ans[A.at(i)-1][0] != 1 ) ans[A.at(i)-1][1] = ans[A.at(i)-1][1] + 1 ;
    }
  }
  ll ans1 = 0 ;ll ans2 = 0 ;
  rep(i,N) ans1 += ans[i][0]  ;
  rep(i,N) if(ans[i][0] == 1 ) ans2 += ans[i][1]  ;
  cout << ans1 << endl;
  cout << ans2 << endl;
}

Measured memory_bytes: 8064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

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

int main() {
	int n, m;
	int *a;
	cin >> n >> m;
	LL mm = (LL)(m);
	a = new int[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		a[i] /= 2;
	}
	LL lcm = (LL)(a[0]);
	for (int i = 1; i < n; ++i) {
		LL g = gcd(lcm, a[i]);
		lcm = (lcm * (LL)(a[i])) / g;
		if (lcm > mm) {
			cout << "0" << endl;
			return 0;
		}
	}
	int lc = (int)(lcm);
	for (int i = 0; i < n; ++i) {
		if (lc % (2 * a[i]) == 0) {
			cout << "0" << endl;
			return 0;
		}
	}
	cout << ((m - lcm) / (2 * lcm) + 1) << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main{
	static int INF=(int)1e9;

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt();
		int K=sc.nextInt();
		int []h=new int [n];
		for(int i=0;i<n;i++)
			h[i]=sc.nextInt();
		
		int []dp=new int [n];
		Arrays.fill(dp, INF);
		dp[n-1]=0;
		for(int i=n-2;i>=0;i--) {
			for(int j=1;j<=K && i+j<n;j++) {
				
				dp[i]=Math.min(dp[i], dp[i+j]+Math.abs(h[i]-h[i+j]));
				}
//			out.println(dp[i]);
		}
		
		out.println(dp[0]);
		
		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 35852
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,K,count=0;
  vector<int> h(111111);
  cin>>N>>K;
  for(int i=0;i<N;i++){cin>>h.at(i);if(h.at(i)>=K)count++;}
  cout<<count<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void) {
   int N;
   scanf("%d", &N);

   int n = N / 100;
   int zzz = n * 111;

   if(zzz < N) {
      N = (n+1)*111;
   } else {
      N = zzz;
   }
   
   printf("%d\n", N);
   return 0;
   
}


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

const int bm = 2 * (int)(1e5) + 5;
bool mode[bm];
int deg[bm][2];
int nbNoeuds, nbLiens;
vector<int> adj[bm];
bool vu[bm];

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

    for (int iNod = 1; iNod <= nbNoeuds; ++iNod) {
        char lettre;
        cin >> lettre;
        mode[iNod] = (lettre == 'B');
    }
    for (int iLien = 0; iLien < nbLiens; ++iLien) {
        int nod1, nod2;
        cin >> nod1 >> nod2;
        adj[nod1].push_back(nod2);
        if (nod1 != nod2) adj[nod2].push_back(nod1);
        deg[nod1][mode[nod2]]++;
        if (nod1 != nod2) deg[nod2][mode[nod1]]++;
    }

    stack<int> pile;
    for (int iNod = 1; iNod <= nbNoeuds; ++iNod) {
        if (deg[iNod][0] == 0 || deg[iNod][1] == 0) {
            pile.push(iNod);
            vu[iNod] = true;
        }
    }
    int fini = 0;
    while (! pile.empty()) {
        int nod = pile.top();
        pile.pop();
        ++fini;
        for (int vo : adj[nod]) {
            if ((--deg[vo][mode[nod]]) == 0 && vu[vo] == false) {
                vu[vo] = true;
                pile.push(vo);
            }
        }
    }

    if (fini != nbNoeuds) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 12544
N = int(input())
ls = [[int(i) for i in input().split()] for j in range(N)]
now = 0
ls = sorted(ls,key=lambda x:x[1])
ans = 'Yes'
for l in ls:
    now += l[0]
    if now > l[1]:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 42716
using System;

public class ITP1_2_D
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        string[] str = Console.ReadLine().Split(' ');

        int w = int.Parse(str[0]);
        int h = int.Parse(str[1]);
        int x = int.Parse(str[2]);
        int y = int.Parse(str[3]);
        int r = int.Parse(str[4]);

        Solve(w, h, x, y, r);
    }

    private static void Solve(int w, int h, int x, int y, int r)
    {
        if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}



Measured memory_bytes: 19880
#include <bits/stdc++.h>
using namespace std;
int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    bool inn = true;
    if (0 > x-r) {
        inn = false;
    }
    else if (W < x+r) {
        inn = false;
    }
    else if (0 > y-r) {
        inn = false;
    }
    else if (H < y+r) {
        inn = false;
    }
    if (inn) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3092