akhauriyash/Code-Regression huggingface dataset:
INF = float('inf')


def Bellmanford(node, edges, source):
    d = [INF] * node  # ある頂点までのコストを保存するリスト
    d[source] = 0

    for i in range(node):
        for start, goal, cost in edges:
            # 辺の始まりの頂点までのコストが INF でなく
            # 辺の向かう先の頂点のコストが、より軽くなる場合に、
            # リストを更新する
            if d[start] != INF and d[start] + cost < d[goal]:
                d[goal] = d[start] + cost
                if i == node-1 and goal == node-1:
                    return 'inf'
    return -d[node-1]


N, M = map(int, input().split())
abc = [map(int, input().split()) for _ in range(M)]
Edges = [None] * M

for i in range(M):
    ai, bi, ci = abc[i]
    Edges[i] = (ai-1, bi-1, -ci)


ans = Bellmanford(N, Edges, 0)
print(ans)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  
  vi ans(n);
  int a_sum = SUM(a);
  int x = 0;
  rep(i,n) {
    if (i%2 == 1) x += a[i];
  }

  ans[0] = a_sum - 2*x;
  rep(i,n-1) {
    ans[i+1] = 2*a[i] - ans[i];
  }
  rep(i,ans.size()) printf("%d%c", ans[i], i==ans.size()-1?'\n':' ');
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int>r(n),g(n),b(n);
  r[0]=0;
  g[0]=0;
  b[0]=0;
  if(s[0]=='R')r[0]=1;
  if(s[0]=='G')g[0]=1;
  if(s[0]=='B')b[0]=1;
  for(int i=1;i<n;i++){
    r[i]=r[i-1];
    g[i]=g[i-1];
    b[i]=b[i-1];
    if(s[i]=='R')r[i]++;
    if(s[i]=='G')g[i]++;
    if(s[i]=='B')b[i]++;
  }
  long long kotae=0;
  for (int i = 0; i < n-2; i++) {
    for (int j = i+1; j < n-1; j++) {
      if(s[i]=='R'){
        if(s[j]=='G'){
          kotae+=b[n-1]-b[j];//RGB
          if(s[2*j-i]=='B'&&2*j-i<n)kotae--;
        }else if(s[j]=='B'){
          kotae+=g[n-1]-g[j];//RBG
          if(s[2*j-i]=='G'&&2*j-i<n)kotae--;
        }
      }else if(s[i]=='G'){
        if(s[j]=='R'){
          kotae+=b[n-1]-b[j];//GRB
          if(s[2*j-i]=='B'&&2*j-i<n)kotae--;
        }else if(s[j]=='B'){
          kotae+=r[n-1]-r[j];//GBR
          if(s[2*j-i]=='R'&&2*j-i<n)kotae--;
        }
      }else if(s[i]=='B'){
        if(s[j]=='G'){
          kotae+=r[n-1]-r[j];//BGR
          if(s[2*j-i]=='R'&&2*j-i<n)kotae--;
        }else if(s[j]=='R'){
          kotae+=g[n-1]-g[j];//BRG
          if(s[2*j-i]=='G'&&2*j-i<n)kotae--;
        }
      }
    }
  }
  cout << kotae << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  vector<int> b(n);
  rep(i, n) { b[a[i] - 1] = i + 1; }
  rep(i, n - 1) { cout << b[i] << " "; }
  cout << b[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1664
n = int(input())
s = str(input())

h = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
h = h.upper()
ans = str("")

for i in range(len(s)):
    for j in range(26):
        if s[i] == h[j]:
            ans +=h[j+n]
            continue

print(ans)


Measured memory_bytes: 3060
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:isize,
    }
    let mut b:isize=1;
    let mut c:isize=1;
    let mut d:isize=1;
    for i in 0..a {
        b*=10;
        b%=1000000007;
        c*=9;
        c%=1000000007;
        d*=8;
        d%=1000000007;
    }
    println!("{}",(b-c*2+d+2000000014)%1000000007)
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power_mod(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl

//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//product of minimum 9 prime numbers is above 1e9


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int n, k; cin >> n >> k;
    
    
    /*
     青玉をi箇所に分ける
     青玉k個
     仕切りi-1個?
     いや、1個以上にしな
     
     a1 + a2 + ... + ai = k
     a >= 1
     
     a >= 0にしたい
     (a1 - 1) + (a2 - 1) + ... + (ai - 1) = k - i
     
     k-i + i-1Ci-1
     =k-1Ci-1
     
     赤玉は端はおいても置かなくても
     b1 + b2 + ... + bi+1 = n - k
     b1, bi+1 >= 0
     b2, ..., bi >= 1
     
     b1 + (b2 - 1) + ... + (bi - 1) + bi+1 = n - k - (i - 1)
     b >= 0
     
     
     
     */
    
    rep3(i, 1, k + 1) {
        out((COM(k - 1, i - 1) * COM(n - k - i + 1 + i, i)) % mod);
    }
}


Measured memory_bytes: 12160
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

struct edge {
	ll to;
	ll cost;
};

vector<bool> used(100001, false);
vector<ll> d(100001, -1);
bool f = true;
void dfs(ll a, const unordered_multimap<ll, edge>& graph) {
	if (used[a]) { return; }
	used[a] = true;

	auto p = graph.equal_range(a);
	for (auto itr = p.first; itr != p.second; ++itr) {
		if (d[itr->second.to] == -1) {
			d[itr->second.to] = d[a] + itr->second.cost;
			dfs(itr->second.to, graph);
		} else if (d[itr->second.to] != d[a] + itr->second.cost) {
			f = false;
			return;
		}
	}}

int main() {
	int n, k;
	cin >> n >> k;
	map<ll, ll> mp;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		if (mp.find(tmp) != mp.end()) {
			++mp[tmp];
		} else {
			mp[tmp] = 1;
		}
	}
	vector<PAIR> mpc;
	mpc.reserve(mp.size());
	REPC(x, mp) {
		mpc.emplace_back(x.second, x.first);
	}
	sort(ALL(mpc));

	k = std::min(k, (int)mp.size());
	ll ans = 0;
	auto itr = mpc.begin();
	REP(i, mp.size() - k) {
		ans += itr->first;
		++itr;
	}
	cout << ans << endl;
}

Measured memory_bytes: 16640
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
use proconio::marker::*;

fn type_of<T>(_: T) -> String{
    let a = std::any::type_name::<T>();
    return a.to_string();
}

#[fastout]
fn main() {
    input! {
        a:i32,b:i32,c:i32,
    }
    println!("{}",if a+b>=c{"Yes"}else{"No"});
}

Measured memory_bytes: 2164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] h = new int[n + 1][3];
		for(int i = 1; i <= n; i++) {
			for(int j = 0; j < 3; j++) {
				h[i][j] = sc.nextInt();
			}
		}
		int[][] dp = new int[n + 1][3];
		dp[1][0] = h[1][0];
		dp[1][1] = h[1][1];
		dp[1][2] = h[1][2];
		
		for(int i = 2; i <= n; i++) {
			dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][2]) + h[i][0];
			dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + h[i][1];
			dp[i][2] = Math.max(dp[i - 1][0], dp[i - 1][1]) + h[i][2];
		}
		System.out.println(Math.max(Math.max(dp[n][0], dp[n][1]), dp[n][2]));
	}

}


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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<unsigned long long> a(n);
    unsigned long long max = 0;
    unsigned long long sum = 0;

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

    for (int i = 0; i < n; i++) {
        if (a[i] < max) sum += max - a[i];
        else max = a[i];
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 4412
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------


int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N, K, X, Y;
	LL ans = 0;
	cin >> N >> K >> X >> Y;

	FOR(i, 0, N) {
		if (i < K)
			ans += X;
		else
			ans += Y;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 200100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
const int inf=1e9;
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;++dg[u];}
int n,c[MAX],fa[MAX],sz[MAX];ll ans;
int S[MAX],top;
char s[MAX];
int d1[MAX];//子树中距离最远的一个点
int d2[MAX];//同上，可以从父亲转移
int d3[MAX];//子树中有经过至少一个黑点的最远点
int d5[MAX];//上界
int d6[MAX];//下界
void dfs1(int u,int ff)
{
	fa[u]=ff;sz[u]=c[u];
	if((u!=1&&dg[u]==1)||(u==1&&!dg[u]))//叶子节点
	{
		d1[u]=0;d3[u]=c[u]?0:inf;
		return;
	}
	int mx=0,mx2=inf;
	for(int i=h[u];i;i=e[i].next)
	{
		int v=e[i].v;if(v==ff)continue;
		dfs1(v,u);sz[u]+=sz[v];
		mx=max(mx,d1[v]);
		if(d3[v]<inf)mx2=min(mx2,d1[v]);
	}
	d1[u]=mx+1;d3[u]=mx2+1;
	if(c[u])d3[u]=min(d3[u],d1[u]);
}
void dfs2(int u,int ff)
{
	d2[u]=max(d2[u],(ff!=0)+d2[ff]);//从父亲转移过来
	if(ff)d5[u]=max(d5[u],d2[u]-1);//维护上界
	top=0;for(int i=h[u];i;i=e[i].next)if(e[i].v!=ff)S[++top]=e[i].v;
	for(int i=1,mx=-1;i<=top;++i)//前缀其他儿子转移一下
	{
		int v=S[i];
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(int i=top,mx=-1;i>=1;--i)//后缀其他儿子转移一下
	{
		int v=S[i];
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff)dfs2(e[i].v,u);
}
int main()
{
	n=read();
	for(int i=1;i<n;++i)
	{
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	scanf("%s",s+1);int tot=0;
	for(int i=1;i<=n;++i)tot+=(c[i]=s[i]-48);
	if(!tot){puts("0");return 0;}
	memset(d3,63,sizeof(d3));
	dfs1(1,0);dfs2(1,0);
	for(int i=1;i<=n;++i)
	{
		if(c[i])d6[i]=0;//可以涂色的点
		else d6[i]=min(d3[i],(sz[i]==sz[1])?inf:d2[i]);
		//不能涂色的点考虑下界
		int u=max(d1[i],d2[i])-1;//u为上界，初始为最短点距离减一
		for(int j=h[i];j;j=e[j].next)
		{
			int v=e[j].v;
			if(v==fa[i])u=min(u,d1[i]+1);//如果从父亲转移过来，
			else u=min(u,d5[v]+1);
		}
		if(u>=d6[i])ans+=u-d6[i]+1;
	}
	cout<<ans+1<<endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  double ans = vec.at(0)*pow(0.5,n-1);
  for(int i=1; i<n; i++){
    ans += vec.at(i)*pow(0.5,n-i);
  }
  cout << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n,k;
	cin>>n;
	vector<ll> a(n),b(n),c(n);
	for(int i=0;i<n;i++)
	cin>>a[i]>>b[i]>>c[i];
	vector<vector<ll>> ans(n+1,vector<ll>(3,0));
	for(int i=1;i<(n+1);i++){
		ans[i][0]=max(a[i-1]+ans[i-1][1],a[i-1]+ans[i-1][2]);
		ans[i][1]=max(b[i-1]+ans[i-1][0],b[i-1]+ans[i-1][2]);
		ans[i][2]=max(c[i-1]+ans[i-1][0],c[i-1]+ans[i-1][1]);
//		cout<<ans[i][0]<<endl;
	}
	cout<<max(ans[n][0],max(ans[n][1],ans[n][2]));
}

Measured memory_bytes: 11024
n, m = input().split()
n, m = int(n), int(m)

if n==1 or m==1:
  ans = 1
elif m%2==1:
  d = (m+1)/2
  if n%2==0:
    ans = (d+d-1)*n/2
  else:
    ans = (d+d-1)*(n-1)/2 + d
else: # even
  ans = n * m/2
print(int(ans))


Measured memory_bytes: 3060
import heapq

A = []
heapq.heapify(A)

while True:
    arr = input().split()

    if arr[0] == 'end':
        break

    if arr[0] == 'insert':
        key = int(arr[1]) * -1
        heapq.heappush(A, key)

    if arr[0] == 'extract':
        max = heapq.heappop(A) * -1
        print(max)



Measured memory_bytes: 45304
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
ll mod = 1e9 + 7;
int main()
{
	static ll n, k, a[2010],b[4020], i, j, l;
	ll g1 = 0, g2 = 0;
	cin >> n >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		b[i] = b[i + n] = a[i];
	}
	//puts("グループ1");
	for (i = 1; i < n; i++)
	{
		for (j = i+1; j <=n; j++)
		{
			if (i<j && a[i]>a[j])
			{
				//printf("(i%d,j%d)%d,%d\n",i,j, a[i], a[j]);
				g1++;
			}
		}
	}
	//puts("グループ1と2");
	for (i = 1; i <= n; i++)
	{
		for (j = n + 1; j <= 2*n; j++)
		{
			if (b[i]>b[j])
			{
				//printf("(i%d,j%d)%d,%d\n", i, j, b[i], b[j]);
				g2++;
			}
		}
	}
	//printf("g1%lld,g2%lld\n", g1, g2);
	g1 %= mod, g2 %= mod;
	long long ans = g1 * k + (k * (k - 1)/2   % mod )* g2;
	ans %= mod;
	cout << ans << endl;
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;

  vector<int> child(S.size());

  int i = 0;

  while (i < S.size()){
    if(S.at(i)=='R'){
      for (int j = 0; j < S.size()-i; j++)
      {
        if (S.at(i + j) == 'L')
        {
          if (j % 2 == 1)
          {
            child.at(i + j - 1) += j/2+1;
            child.at(i + j ) += j / 2 ;
          }
          else
          {
            child.at(i + j - 1) += j / 2;
            child.at(i + j) += j / 2;
          }
          i = i + j;
          break;
        }
      }
    }
    else{
      for (int j = 0; j < S.size()-i; j++)
      {
        if (S.at(i + j) == 'R')
        {
          if (j % 2 == 1)
          {
            child.at(i) += j / 2 + 1;
            child.at(i - 1) += j / 2;
          }
          else
          {
            child.at(i) += j / 2;
            child.at(i - 1) += j / 2;
          }
          i = i + j;
          break;
        }
        else if(i+j==S.size()-1){
          if (j % 2 == 1)
          {
            child.at(i) += j / 2 + 1;
            child.at(i - 1) += j / 2+1;
          }
          else
          {
            child.at(i) += j / 2+1;
            child.at(i - 1) += j / 2;
          }
          i = i + j+1;
          break;
        }
      }
    }

    /*  if(i==S.size()-1){
      for (int j = 1; j < S.size(); j++)
      {
        if (S.at(i - j) == 'R')
        {
          if (j % 2 == 1)
          {
            child.at(i) += j / 2 + 1;
            child.at(i - 1) += j / 2;
          }
          else
          {
            child.at(i) += j / 2;
            child.at(i - 1) += j / 2;
          }
          break;
        }
      }
      i++;
    }*/
  }

  /*for (int i = 0; i < S.size();i++){
    if(S.at(i)=='R'){
      for (int j = 1; j < S.size();j++)
      {
        if(S.at(i+j)=='L'){
          if(j%2==1){
            child.at(i + j - 1)++;
          }
          else
            {
              child.at(i + j)++;
            }
            break;
        }
      }
    }
    else{
      for (int j = 1; j < S.size();j++){
        if(S.at(i-j)=='R'){
          if (j % 2 == 1)
          {
            child.at(i - j + 1)++;
          }
          else
          {
            child.at(i - j)++;
          }
          break;
        }
      }
    }
  }*/

  for (int i = 0; i < S.size();i++){
    cout << child.at(i) << " ";
  }
  cout << "" << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> P(N),Q(N),R(N);
  int i;
  for(i=0;i<N;i++){
    cin >> P[i];
    R[i]=i+1;
  }
  for(i=0;i<N;i++){
    cin >> Q[i];
  }
  int a,b,c=1;
  bool Pflag,Qflag;
  do{
    Pflag=true;Qflag=true;
    for(i=0;i<N;i++){
      if(P[i]!=R[i])Pflag=false;
      if(Q[i]!=R[i])Qflag=false;
    }
    if(Pflag)a=c;
    if(Qflag)b=c;
    c++;
  }while(next_permutation(R.begin(),R.end())); 
  cout << abs(a-b) <<endl;
}

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

/*alias*/
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using ll=long long;

using namespace std;

/*input*/
int n,k;

/*funcs*/


/*main*/
int main(){
    cin>>n>>k;
    if(k==1){
        cout<<0;
    }else{
        cout<<n-k;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n; string s,t; cin>>n>>s >>t;
    rep(i,n)cout<<s[i]<<t[i];
    cout<<endl;return 0;
}


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

int main() {
  int p,q,r,s;
  p = q = r = s = 0;
  int x,y,z;
  while(cin>>x>>y>>z) {
    vector<int> v(3);
    v[0] = x, v[1] = y, v[2] = z;
    sort(v.begin(), v.end());

    x = v[0], y = v[1], z = v[2];
    if (z >= x+y) {
      cout<<p<<" "<<q<<" "<<r<<" "<<s<<endl;
      break;
    }

    p++;
    if (x*x + y*y == z*z) {
      q++;
    } else if (x*x + y*y > z*z) {
      r++;
    } else {
      s++;
    }
  }
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e;
    int A,B;
    
    cin >>a>>b>>c>>d>>e;
    
    A=a*e;
    
    if(c>=e) B=b;
    else B=b+(e-c)*d;
    
    if(A>B) cout <<B<<endl;
    else cout <<A<<endl;
}



Measured memory_bytes: 3104
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
using mint = modint998244353;
struct S {
    mint a;
    mint base;
};
S op(S l,  S r) { return S{l.a+r.a,l.base+r.base} ;}

S e() { return S{0,0}; }

S mapping(int l, S r) { if(l!=0) return S{r.base*l,r.base}; else return S{r.a,r.base};}

int composition(int l, int r) { if(l==0)return r; else if(r==0) return l; else return l;}

int id() { return 0; }
int main() {
    int n,l;
    cin>>n>>l;
    vector<S> a(300001);
    mint j=1;
    rep(i,n)    a[i]=S{j,j},j=j*10;
    lazy_segtree<S, op, e, int, mapping, composition, id> seg(a);
    
    rep(i,l){
        int p,q,r;
        cin>>p>>q>>r;
        p--;q--;
        p=n-1-p;
        q=n-1-q;
        seg.apply(q,p+1,r);
        cout<<seg.all_prod().a.val()<<"\n";
    }
    return 0;
}


Measured memory_bytes: 15964
h,w = map(int,input().split())
grid = []
grid.append(["."]*(w+2))
for i in range(h):
    grid.append(["."]+list(input())+["."])
grid.append(["."]*(w+2))
dx = [0,1,0,-1]
dy = [1,0,-1,0]
for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j] == "#":
            ok = False
            for k in range(4):
                if grid[i+dy[k]][j+dx[k]] == "#":
                    ok = True
            if not ok:
                print("No")
                exit()
print("Yes")

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

int main()
{
  int n, m, x;
  int c[200000];
  int a[20][20] = { 0 };
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++)
  {
    cin >> c[i];
    for (int j = 0; j < m; j++)
    {
      cin >> a[i][j];
    }
  }

  int mincost = -1;
  for (int bit = 0; bit < (1 << n); ++bit)
  {
    vector<int> al(m, 0);
    int cost = 0;
    for (int i = 0; i < n; i++)
    {
      if (bit & (1 << i))
      {
        cost += c[i];
        for (int j = 0; j < m; j++)
        {
          al[j] += a[i][j];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < m; i++)
    {
      if (al[i] < x)
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      if (mincost == -1)
      {
        mincost = cost;
      }
      else
      {
        mincost = min(cost, mincost);
      }
    }
  }
  cout << mincost << endl;
}

Measured memory_bytes: 3648
S = list(input())
guu = []
kis = []
for i in range(len(S)):
    if i%2 == 0:
        guu.append(S[i])
    else:
        kis.append(S[i])
if "L" in guu or "R" in kis:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  cout<<(H-h)*(W-w)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; ++i) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	int longest = l.back();
	int sumOfRest = accumulate(l.begin(), l.end() - 1, 0);
	cout << (longest < sumOfRest ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    n =int(input())
    s = list(input())
    x = 0
    ans = 0
    for i in s:
        if i =='I':
            x += 1
            if ans < x:
                ans = x
        else:
            x -=1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


// const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  ll calc = 0, tmp = 0;;
  for(int i = 0; i < N - 1; i++) {
    tmp = A[i] * 2 - tmp;
    calc += tmp;
  }
  vector<ll> ans;
  ans.push_back(sum - calc);
  for(int i = 0; i < N - 1; i++) {
    ll x = ans[ans.size() - 1];
    ans.push_back((A[i] - x / 2) * 2);
  }

  for(int i = 0; i < ans.size(); i++) {
    if(i == 0) cout << ans[i];
    else cout << " " << ans[i];
  }cout << endl;
  return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

pair<double,int> a[100];
int main()
{
	int n;
	int ans=0;
	double av=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		double d;
		cin>>d;
		a[i]=make_pair(d,i);
		av+=d;
	}
	av/=(double)n;
	double md=999;
	int mdin=0;
	for(int i=0;i<n;i++)
	{
		double t=abs(a[i].first-av);
		if(t<md)
		{
			mdin=i;
			md=t;
		}
	}
	
	cout<<mdin<<endl;
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 109, M = 509, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int fr[N];

int main(){
    init();

    int n, m;   cin >> n >> m;
    for(int i = 0;i < m;i++){
        int a, b;   cin >> a >> b;
        fr[a]++;
        fr[b]++;
    }

    for(int i = 1;i <= n;i++)   cout << fr[i] << '\n';
}

Measured memory_bytes: 256
N, W = map(int, input().split())
v_arr, w_arr = [], []
for _ in range(N):
    v, w = map(int, input().split())
    v_arr.append(v)
    w_arr.append(w)

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
dp[0][W] = 0
for i in range(N):
    for w in range(W+1):
        if w >= w_arr[i]:
            dp[i+1][w] = max(dp[i][w - w_arr[i]] + v_arr[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])



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

int main()
{
    int n, k; scanf("%d%d", &n, &k);
    int ans = 0;
    for(; n--;)
    {
        int x; scanf("%d", &x);
        ans += x >= k ? 1 : 0;
    }
    printf("%d\n", ans);
    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

struct UF {
  vi e;
  UF(int n) : e(n, -1) {}
  bool sameSet(int a, int b) { return find(a) == find(b); }
  int size(int x) { return -e[find(x)]; }
  int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
  bool join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b]; e[b] = a;
    return true;
  }
};

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >>  cw >> dh >> dw;
  --ch;--cw;--dh;--dw;

  UF uf(h*w);

#define id(i, j) ((i)*w) + j
#define in(i,j) ((i) >=0  and (i) < h and (j) >= 0 and (j) < w)

  vector<string> grid(h);
  rep(i,0,h) cin >> grid[i];


  rep(i,0,h) rep(j,0,w) if (grid[i][j] == '.') rep(di,-1,2) rep(dj,-1,2) {
    if (abs(di) + abs(dj) != 1) continue;
    int ni = i+di, nj = j+dj;
    if (not in(ni, nj)) continue;
    if (grid[ni][nj] != '.') continue;

    uf.join(id(i,j), id(ni,nj));
  }

  vector<set<int>> g(h*w);

  rep(i,0,h) rep(j,0,w) if (grid[i][j] == '.') rep(di,-2,3) rep(dj,-2,3) {
    int ni = i+di, nj = j+dj;
    if (not in(ni, nj)) continue;
    if (grid[ni][nj] != '.') continue;
    int ca = uf.find(id(i,j));
    int cb = uf.find(id(ni,nj));
    g[ca].insert(cb);
    g[cb].insert(ca);
  }

  int s = uf.find(id(ch, cw));
  int t = uf.find(id(dh, dw));

  if (s==t) return cout << 0 << '\n', 0;

  queue<int> q;
  q.push(s);
  vi vis(h*w);
  vi dist(h*w);

  vis[s] = 1;
  dist[s] = 0;

  while (not q.empty()) {
    int u = q.front(); q.pop();
    if (u==t) {
      return cout << dist[u] << '\n', 0;
    }

    for (auto v: g[u]) {
      if (vis[v]) continue;
      vis[v] = 1;
      q.push(v);
      dist[v] = dist[u]+1;
    }
  }

  cout << -1 << '\n';

}

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

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? " " : "");
  outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? "\n" : "");
  outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
  return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
  return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

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

  var(int, N, M);
  vector<int> x(M);
  rep(i, M) input(x[i]);

  if (N >= M) {
    outl(0);
    return 0;
  }

  sort(all(x));
  priority_queue<int> que;
  reps(i, 1, M - 1) {
    que.emplace(x[i] - x[i-1]);
  }

  N--;
  while (N--) {
    que.pop();
  }

  i64 res = 0;
  while (que.size()) {
    res += que.top();
    que.pop();
  }

  outl(res);

  return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)

int main()
{
    fast;
     string s;
     map<string,int>mp;
     int a[4]={0};
    w(t)
    {

        cin>>s;
       // mp[s]++;
       if(s=="AC")a[0]++;
       else if(s=="WA")a[1]++;
       else if(s=="TLE")a[2]++;
       else if(s=="RE")a[3]++;
    }
    cout<<"AC x "<<a[0]<<endl;
    cout<<"WA x "<<a[1]<<endl;
    cout<<"TLE x "<<a[2]<<endl;
    cout<<"RE x "<<a[3]<<endl;


}



Measured memory_bytes: 3660
N = input()
H = list(map(int, input().split()))

Hk = set([0])
for h in H:
  Hk.add(h)
Hk = sorted(Hk)

def po(h, s, e):
  posS = s
  cnt = 0
  for posE in range(s, e+1):
    if posE >= e or H[posE] <= Hk[h]:
      if posS < posE:
        cnt += po(h+1, posS, posE)
      posS = posE + 1
  if h > 0:
    cnt += Hk[h] - Hk[h-1]
  return cnt

print(po(0, 0, len(H)))


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

signed main(){
  int R;
  cin>>R;
  if(R<1200)cout<<"ABC"<<endl;
  if(R<2800&&R>=1200)cout<<"ARC"<<endl;
  if(R>=2800)cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int K;
	char S[301];
	scanf("%s", S);
	scanf("%d", &K);
	
	int i, l;
	char T[301];
	for (l = 0; S[l] != 0; l++);
	for (i = 0, T[l] = 0; i < l; i++) T[i] = S[l-i-1];
	if (K >= l / 2) {
		printf("%d\n", l);
		fflush(stdout);
		return 0;
	}
	
	int j, k, dp[151][301][301] = {};
	for (i = 1; i <= l; i++) {
		for (j = 1; j <= l; j++) {
			for (k = 0; k <= K; k++) {
				if (dp[k][i-1][j] > dp[k][i][j]) dp[k][i][j] = dp[k][i-1][j];
				if (dp[k][i][j-1] > dp[k][i][j]) dp[k][i][j] = dp[k][i][j-1];
				if (S[i-1] == T[j-1] && dp[k][i-1][j-1] >= dp[k][i][j]) dp[k][i][j] = dp[k][i-1][j-1] + 1;
				if (dp[k][i-1][j-1] >= dp[k+1][i][j]) dp[k+1][i][j] = dp[k][i-1][j-1] + 1;
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i <= l - 1; i++) {
		for (k = 0; k <= K; k++) {
			if (dp[k][i][l-i] * 2 > ans) ans = dp[k][i][l-i] * 2;
			if (dp[k][i][l-i-1] * 2 + 1 > ans) ans = dp[k][i][l-i-1] * 2 + 1;
		}
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 55168
import math

a, b, x = map(int,input().split())
lb = 0
ub = 90

while ub - lb > 0.5 * 10**-6:
    theta = (lb+ub) / 2
    tt = math.tan(math.radians(theta))
    tt9 = math.tan(math.radians(90 - theta))
    
    if b * tt9 >= a:
        y = a*a*b - a * a*a*tt/2 - x
        if y < 0:
            ub = theta
        else:
            lb = theta
    else:
        y = a * b*b*tt9/2 - x
        if y < 0:
            ub = theta
        else:
            lb = theta
print(theta)

Measured memory_bytes: 9460
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, t: usize, ct: [[usize; 2]; n]);

    let min = ct.iter().filter(|x| (*x)[1] <= t).map(|x| x[0]).min();

    println!(
        "{}",
        if min.is_some() {
            min.unwrap().to_string()
        } else {
            "TLE".to_string()
        }
    );
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

int main()
{
	sync;
	string s;
	cin>>s;
	string arr[3]={"Sunny","Cloudy","Rainy"};
	for(ll i=0;i<3;i++)
	{
		if(arr[i]==s)
		cout<<arr[(i+1)%3];
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
vi g[100010];
bool was[100010];
int f[100010];
int dfs(int nw){
	if(was[nw])return f[nw];
	was[nw]=1;
	for(int i=0;i<g[nw].size();i++){
		f[nw]=max(f[nw],dfs(g[nw][i])+1);
	}
	return f[nw];
}
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 8192
<?php
$s = str();
for($i = 0; $i <= 5; $i++){
    if(str_repeat("hi", $i)==$s){
        echo "Yes";
        exit;
    }
}
echo "No";
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  ll N, K;
  cin >> N>>K;
  vector<ll> H(N);
  rep(i,N) cin >>H[i];
  sort(all(H));
  if(K<N){
    ll tot = 0;
    rep(i,N-K) tot += H[i];
    cout << tot << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll lcs = c * d / __gcd(c, d);
    ll sum = b - a + 1;
    sum -= b / d;
    sum += a / d;
    if (a % d == 0) sum--;
    sum -= b / c;
    sum += a / c;
    if (a % c == 0) sum--;
    sum += b / lcs;
    sum -= a / lcs;
    if (a % lcs == 0) sum++;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3560
from networkx.utils import UnionFind
N,Q=map(int,input().split())
uf = UnionFind()
for i in range(Q):
  t,u,v = map(int,input().split())
  if t:print(1 if uf[u]==uf[v] else 0)
  else:uf.union(u,v)

Measured memory_bytes: 68740