akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
int main()
{
   int n,s=0;
   cin>>n;
   int a[n+1],b[n+1];
   for(int i = 1; i <= n; i++)
   {
       cin>>a[i];
   }
   for(int i= 1; i <= n; i++)
   {
       cin >> b[i];
   }

   for(int i =1; i <= n; i++ )
   {
       if(a[i] > b[i])
        s=s+a[i] - b[i];
   }
    cout<<s<<endl;
return 0;
}


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

int main() {

    long long a, b, x;
    scanf("%lld %lld %lld", &a, &b, &x);

    if (a == 0)
        printf("%lld", b/x+1);
    else
        printf("%lld", b/x - (a-1)/x);
}


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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll x,y;
    cin >> x >> y;
    
    vector<ll> a;
    a.push_back(x);
    for(int i = 0;;i++){
        a.push_back(a[i]*2);
        if(a[i+1]>y){
            a.pop_back();
            break;
        }
    }
    cout << a.size() << endl;
}


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

string s;

bool is_pal(const string& ss)
{
	const int n = ss.length();
	int i=0, j=n-1;
	while(i<j){
		if(ss[i]!=ss[j]) return false;
		i++,j--;
	}
	return true;
}

void solve()
{
	if(is_pal(s)){
		cout<<0<<'\n';
		return;
	}
	string t;
	for(char c : s)if(c!='x')t+=c;
	if(is_pal(t)){
		const int n = t.length();
		int i = 0, j = n-1;
		int a = 0, b = s.length()-1;
		int ans = 0;
		while(i<=j){
			int cnt1 = 0, cnt2 = 0;
			while(s[a]=='x') cnt1++,a++;
			while(s[b]=='x') cnt2++,b--;
			a++, b--;
			ans+=abs(cnt1-cnt2);
			i++,j--;
		}
		cout<<ans<<'\n';
		
	}else{
		cout<<-1<<'\n';
	}
}

int main()
{
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>//万能文件头
using namespace std;
int main(){
    int n;
    int l,r,ans=0;//按照题定义
    cin>>n;//输入
    for(int i=1;i<=n;i++){
        cin>>l>>r;//输入公式里两个数
        ans+=r-l+1;//套公式环节
    }
    cout<<ans<<endl;//输出结果
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

int main(){
   ll a, b;
   cin>>a>>b;

   ll l=lcm(a, b);
   cout<< l <<endl;
   return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>

int main(){
  int i,j,k;
  int A,B,C;
  
  scanf("%d %d %d",&A,&B,&C);
  
  if(A *C<=B){
    printf("%d\n",C);
    return 0;
  }
  else
  {
    printf("%d\n",B/A);
    return 0;
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,p;
long long c[55][55];
int main()
{
	scanf("%d%d",&n,&p);
	c[0][0]=1ll;
	c[1][0]=1ll;
	c[1][1]=1ll;
	for(int i=2;i<=n;i++)
	{
		c[i][0]=1ll;
		c[i][i]=1ll;
		for(int j=1;j<i;j++)c[i][j]=c[i-1][j-1]+c[i-1][j];
	}
	long long ans=1ll;
	int s=0;
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		if(x&1)s++;else ans=ans*2ll;
	}
	long long res=0;
	for(int i=p;i<=s;i+=2)res=res+c[s][i];
	ans=ans*res;
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=b-1;i>=a;i--)

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll h,w,k;
  cin >> h >> w >> k;
  vector<vl> c(h,vl(w,0));
  REP(i,h){
    string s;
    cin >> s;
    REP(j,w){
      if(s[j]=='.') c[i][j] = 0;
      else c[i][j] = 1;
    }
  }
  ll ans = 0;

  ll th = 1;
  REP(i,h) th *= 2;
  ll tw = 1;
  REP(i,w) tw *= 2;
  REP(thi,th){
    REP(twj,tw){
      vector<vl> tmp(h,vl(w,0));
      REP(i,h) REP(j,w) tmp[i][j] = c[i][j];
      ll cthi = thi;
      ll ctwj = twj;
      REP(i,h){
        if(cthi%2==1){
          REP(j,w) tmp[i][j] = 0;
        }
        cthi /= 2;
      }
      REP(j,w){
        if(ctwj%2==1){
          REP(i,h) tmp[i][j] = 0;
        }
        ctwj /= 2;
      }
      ll count = 0;
      REP(i,h) REP(j,w) count += tmp[i][j];
      if(count==k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
struct UnionFind{
    vector<int> parent;
    vector<int> s;
 
    UnionFind(int n){
        parent.resize(n);
        s.resize(n, 1);
        for(int i = 0; i < n; i++) parent[i] = i;
    }
 
    int root(int node){
        if(parent[node] == node){
            return node;
        } else {
            return parent[node] = root(parent[node]);
        }
    }
 
    void unite(int x, int y){
        int rootx = root(x);
        int rooty = root(y);
        if(rootx == rooty) return;
        if(s[rootx] < s[rooty]) swap(rootx, rooty);
        s[rootx] += s[rooty];
        parent[rooty] = rootx;
    }
 
    bool isSame(int x, int y){
        return root(x) == root(y);
    }
 
    int size(int x){
        return s[root(x)];
    }
};
int main(void){
    ll n, m;
    cin >> n >> m;

    vector<vector<ll>> lang(m + 1);

    rep(i, n){
        ll k;
        cin >> k;
        rep(j, k){
            ll tmp;
            cin >> tmp;
            lang[tmp].push_back(i);
        }
    }

    UnionFind uf(n);

    for(int i = 1; i <= m; i++){
        for(int j = 0; j < (int)lang[i].size() - 1; j++){
            uf.unite(lang[i][j], lang[i][j + 1]);
        }
    }

    if(uf.size(0) == n){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 4736
<?php
$str = trim(fgets(STDIN));
$stack = [];
for($i = 0; $i < strlen($str); $i++){
    if($str[$i] == "0"){
        $stack[] = "0";
    }elseif($str[$i] == "1"){
        $stack[] = "1";
    }else{
        @array_pop($stack);
    }
}
echo implode("", $stack);


Measured memory_bytes: 4728
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var ok = makeClone(list);
	ok.sort(function(a,b){
		return a - b;
	});
	if(JSON.stringify(ok) == JSON.stringify(list)){
		myout("YES");
		return;
	}
	for(var i = 0; i < N; i++){
		for(var j = i + 1; j < N; j++){
			var tmplist = makeClone(list);
			var tmp = tmplist[i];
			tmplist[i] = tmplist[j];
			tmplist[j] = tmp;
			var isOK = true;
			for(var k = 0; k < N; k++){
				if(tmplist[k] != ok[k]){
					isOK = false;
				}
			}
			if(isOK){
				myout("YES");
				return;
			}
		}
	}
	myout("NO");
}


Measured memory_bytes: 33828
#include<bits/stdc++.h>
using namespace std;
#define str string
#define rep(x) for(int y=0;y<x;y++)
#define all(x) begin(x),end(x)
int main(){
    int A,B,C,D;
    vector<char>s(19);
    cin>>A>>B>>C>>D;
    cout<<max(A*B,C*D)<<endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n: usize = read!(usize);
    let mut a: Vec<usize> = read![[usize]];

    a.sort();
    let mut s = Vec::with_capacity(n);
    s.push(a[0]);
    for i in 1..n {
        let prev_s = s[i - 1];
        s.push(prev_s + a[i]);
    }

    let mut a_rev = a.clone();
    a_rev.reverse();

    let mut ans = 1; // 一番大きい大きさをもつ生物は必ず最後まで残ることが可能

    for i in 1..n {
        // i番目(0-based)に大きい生物が最後まで残る可能性があるのは、この生物よりも小さい生物を全部合体した状況で、自分より1つ大きいやつを食えるかどうかで決まる
        if i == n - 1 {
            if a_rev[i] * 2 >= a_rev[i - 1] {
                ans += 1;
            }
        } else if (a_rev[i] + s[n - i - 2]) * 2 >= a_rev[i - 1] {
            ans += 1;
        } else {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  cout << N * N * N << endl;
}


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

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert 
#define mp make_pair
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define ft front() 
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define deb(x) cout<<#x<<" "<<x<<'\n';
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18; 
const ld pie = acos((ld)-1);

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



int main(){
    
	int n,l;
	scanf("%d%d",&n,&l);
	vector<string> a(n);
	rep(i,0,n){
		cin>>a[i];
	}

	sort(all(a));
	rep(i,0,n){
		cout<<a[i];
	}printf("\n");

	return 0;

	/*STUFF TO LOOK:	
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll k;
    cin >> k;
    ll t = 1, sum = 0;
    for (int i = 1; i <= k + 10; i++) {
        sum += t * 7LL % k;
        sum %= k;
        t *= 10LL;
        t %= k;
        if (sum == 0) {
            cout << i << newl;
            return 0;
        }
    }
    cout << -1 << newl;
}

Measured memory_bytes: 3644
Q,H,S,D=map(int,input().split())
N=int(input())

#Q,H,Sの中ででいちばん得になるサイズのリットル単価をrとする
r=min(Q*4,H*2,S)

#rはDより得か？
if r*2<D:
    print(N*r)
else:
    print((N//2)*D + (N%2)*r)


Measured memory_bytes: 38384
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

# aに後の要素
function comp(a,b)
  if a[1] == b[1] && a[2] > b[2]
        return true　#文字列aが文字列bより短ければtrueを返す。
    end
  return false
end

function main()
  N = readline() |> parseInt
  
  tmp = []
  for i in 1:N
	S,P = readline() |> split
    P = parseInt(P)
    push!(tmp,(S,P,i))
  end
  sort!(tmp, by=x->x[1])
  sort!(tmp, lt=comp)
  
  for result in tmp
  	println(result[3])
  end
  
end
main()

Measured memory_bytes: 171140
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	int ans = 0;
	if(n >= 2)ans += n * (n - 1) / 2;
	if(m >= 2)ans += m * (m - 1) / 2;
	cout << ans << endl;
}

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

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef complex<double> CD;

#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define F first
#define S second

void R(int &x) { scanf("%d", &x); }
void R(LL &x) { scanf("%lld", &x); }
void R(ULL &x) { scanf("%llu", &x); }
void R(double &x) { scanf("%lf", &x); }
void R(LD &x) { scanf("%Lf", &x); }

template <typename T> void R(T &t) { cin >> t; }
template <typename T> void R(vector<T> &ar) {
  for (auto &it : ar)
    R(it);
}

template <typename T, typename... Args> void R(T &t, Args &... args) {
  R(t);
  R(args...);
}

void W(const char &c) { putchar(c); };
void W(const int &x) { printf("%d", x); }
void W(const LL &x) { printf("%lld", x); }
void W(const ULL &x) { printf("%llu", x); }
void W(const double &x) { printf("%lf", x); }
void W(const LD &x) { printf("%Lf", x); }

template <typename T> void W(const T &t) { cout << t; }
template <typename T> void W(const vector<T> &ar) {
  for (size_t i = 0; i < ar.size(); ++i) {
    W(ar[i]);
    putchar(" \n"[i + 1u == ar.size()]);
  }
}
template <typename T, typename... Args>
void W(const T &t, const Args &... args) {
  W(t);
  W(args...);
}

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

int main() {
  int h, w, n;
  R(h, w, n);
  LL t[10] = {};
  t[0] = 1LL * (h - 2) * (w - 2);
  set<PII> checked;
  set<PII> cov;
  REP(t, n) {
    int x, y;
    R(x, y);
    cov.insert({x, y});
    REPE(i, max(1, x - 2), min(h - 2, x))
    REPE(j, max(1, y - 2), min(w - 2, y))
      checked.insert({i, j});
  }
  for (auto p : checked) {
    t[0]--;
    int cnt = 0;
    REP(i, 3) REP(j, 3)
      if (cov.count({p.F + i, p.S + j}))
        cnt++;
    t[cnt]++;
  }
  for (auto x : t)
    cout << x << endl;
  return 0;
}



Measured memory_bytes: 47104
def main():
    n,ma,mb = map(int, input().split())
    a,b,c = [],[],[]
    for i in range(n):
        ia,ib,ic = map(int, input().split())
        a.append(ia)
        b.append(ib)
        c.append(ic)
    sa = sum(a)
    sb = sum(b)
    INF = 10**5
    dp = [[ [INF] * (sb+1) for i in range(sa+1)] for i in range(n+1)]
    dp[0][0][0] = 0

    for i in range(n):
        for ca in range(sa):
            for cb in range(sb):
                if dp[i][ca][cb] == INF:
                    continue
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
                dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb] + c[i])



    res = INF
    for ca in range(1, sa):
        for cb in range(1, sb):
            if ca*mb==cb*ma:
                res = min(res, dp[n][ca][cb])

    if res == INF:
        res = -1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 25172
# 写経
# https://atcoder.jp/contests/agc011/submissions/1157055

class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]

    def find(self, x):
        if self.v[x] < 0:
            return x
        else:
            self.v[x] = self.find(self.v[x])
            return self.v[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:
            x, y = y, x
        self.v[x] += self.v[y]
        self.v[y] = x

    def root(self, x):
        return self.v[x] < 0

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.v[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(2 * N)
for _ in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    uf.unite(u, N + v)
    uf.unite(N + u, v)

alone = 0
bi = 0
unko = 0

for u in range(N):
    if uf.root(u) or uf.root(N + u):
        if uf.size(u) == 1:
            alone += 1
        elif uf.same(u, N + u):
            unko += 1
        else:
            bi += 1

ans = 0
ans += alone * N
ans += N * alone
ans -= alone * alone
ans += bi * bi * 2
ans += bi * unko
ans += unko * bi
ans += unko * unko

print(ans)


Measured memory_bytes: 8796
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans = 0, id;
	cin >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];

	for (i = 0; i < n; i++) {
		ans++;
		id = 0;
		for (j = i + 1; j < n; j++) {
			if (id == 0) {
				if (a[j] == a[j - 1]) continue;
				else if (a[j] > a[j - 1]) id = 1;
				else id = -1;
			}
			else if ((id == 1) && !(a[j] >= a[j - 1])) break;
			else if ((id == -1) && !(a[j] <= a[j - 1])) break;
		}
		i = j - 1;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
// ----- boost -----
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// ----- using directives and manipulations -----
using boost::rational;
using boost::multiprecision::cpp_int;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;
 
int64_t N, K;
vector<ll> A;
vector<ll> F;
 
bool check(int64_t X){
    ll sum = 0;
    for(int i=0; i<N; i++){
        ll ok = X/F[i];
        if(ok < A[i]) sum += A[i] - ok;
    }
    return (sum <= K);
}

ll binary_search(){
  ll ok = LLINF;
  ll ng = -1;
  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(check(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  return ok;
}
 
int main(){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> F[i];
    sort(all(A));
    sort(rall(F));
    ll ans = binary_search();
    print(ans);
}


Measured memory_bytes: 3456
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int R = int.Parse(Console.ReadLine());
        int G = int.Parse(Console.ReadLine());

        int res = G * 2 - R;

        Console.WriteLine(res);
    }
}

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
  int N;
  cin >> N;
  string ans = "No";
  int count =0;
  rep(i,N){
    int a,b;
    cin >> a >> b;
    if(a==b){
      count++;
      if(count==3){
        ans = "Yes";
        printl(ans);
        return 0;
      }
    }else{
      count = 0;
    }
  }
  printl(ans);
}


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

int main(void){
    int N;
    cin>>N;
    vector<ll> a(N);
    for (int i=0;i<N;i++) cin>>a[i];

    
    ll ans1 = 0;
    ll sum = 0;

    for (int i=0;i<N;i++) {
        ll tsum = sum + a[i];
        if (i%2==0) {
            if (tsum <= 0) {
                ll change = 1 - tsum;
                ans1 += change;
                sum = 1;
            }
            else {
                sum = tsum;
            }
        }
        else {
            if (tsum >= 0) {
                ll change = -1 - tsum;
                ans1 += abs(change);
                sum = -1;
            }
            else {
                sum = tsum;
            }
        }
    }

    ll ans2 = 0;
    sum = 0;

    for (int i=0;i<N;i++) {
        ll tsum = sum + a[i];
        if (i%2==1) {
            if (tsum <= 0) {
                ll change = 1 - tsum;
                ans2 += change;
                sum = 1;
            }
            else {
                sum = tsum;
            }
        }
        else {
            if (tsum >= 0) {
                ll change = -1 - tsum;
                ans2 += abs(change);
                sum = -1;
            }
            else {
                sum = tsum;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

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

int bubbleSort(int N, int A[]) {
    int sw = 0;
    bool flag = 1;
    
    //外側forループ
    for (int i = 0; flag; i++) {
        flag = 0;
        //内側forループ
        for (int j = N - 1; j >= i + 1; j--) {
            
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j -1]);
                flag = 1;
                sw++;
            }
        }
    }
    
    return sw;
}

int main(){
    
    int sw, N, A[100];
    
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    sw = bubbleSort(N, A);
    
    for (int i = 0; i < N; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    
    cout << sw << endl;
   
    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    char c;
    cin >> c;
    char ans ;
    if('A' <= c && c <= 'Z') ans = 'A';
    else ans = 'a';
    cout << ans  << endl; 
    return 0;
}

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

namespace ABC167B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCK = ReadLong();

            long A = ABCK[0];
            long B = ABCK[1];
            long C = ABCK[2];
            long K = ABCK[3];


            long a = Math.Min(A, K);
            long c = Math.Max(K - A - B, 0);

            Console.WriteLine(a - c);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 19060
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;



int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << max(C - A + B, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
const int MN = 100100;
ll w[MN],re[MN],pw[MN],pp[MN];
pl qu[MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin >> n >> m;
	memset(re,0,sizeof(re));
	for(int i=0;i<n;i++) {
		cin >> w[i];
	}
	sort(w,w+n);
	pw[0] = 0;
	for(int i=0;i<n;i++) {
		pw[i+1] = pw[i]+w[i];
	}
	for(int i=0;i<m;i++) {
		ll a,b;
		cin >> a >> b;
		qu[i] = {b,a};
	}
	sort(qu,qu+m);
	ll ct = 0;
	for(int i=m-1;i>=0;i--) {
		if(ct == n) break;
		for(int j=0;j<qu[i].second;j++) {
			if(ct == n) break;
			re[ct] = qu[i].first;ct++;
		}
	}
	ll ma = 0;
	pp[0] = 0;
	for(int i=0;i<ct;i++) {
		pp[i+1] = pp[i]+re[i];
	}
	for(int i=0;i<=n;i++) {
		ma = max(ma,pw[n]-pw[i]+pp[i]);
	}
	cout << ma << '\n';
}


Measured memory_bytes: 4992
def resolve():
    r, c = map(int, input().split())

    sum_c = [0 for _ in range(c)]
    for i in range(r):
        row = list(map(int, input().split()))
        for j, x in enumerate(row):
            print("{} ".format(x), end='')
            sum_c[j] += row[j]
        print(sum(row))

    [print("{} ".format(x), end="") for x in sum_c]
    print(sum(sum_c))


resolve()


Measured memory_bytes: 5636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int A = sc.nextInt(), V = sc.nextInt(), B = sc.nextInt(), W = sc.nextInt(), T = sc.nextInt();
        int diff = Math.abs(B - A);
        int reach = V - W;
        if(reach > 0 && (long)diff <= (long)reach * (long)T){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 27004
#include <bits/stdc++.h>
using namespace std;
int n,m,k,sum,ans,inv[900010],Pow[900010],Mod=1e9+7;
int Add(int aa,int bb) {return (aa+=bb)>Mod? aa-Mod:aa;}
int Sub(int aa,int bb) {return (aa-=bb)<0? aa+Mod:aa;}
int Mul(int aa,int bb) {return 1LL*aa*bb%Mod;}
int ksm(int aa,int bb)
{
	int an=1;
	for (;bb;bb>>=1) {
		if (bb&1) an=Mul(an,aa);
		aa=Mul(aa,aa);
    }
    return an;
}
int C(int N,int M)
{
	if (N<M) return 0;
	return Mul(Mul(Pow[N],inv[N-M]),inv[M]);
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	Pow[0]=1;
	for (int i=1;i<=n+m+k;i++)
	  Pow[i]=Mul(Pow[i-1],i);
    inv[n+m+k]=ksm(Pow[n+m+k],Mod-2);
    inv[0]=1;
    for (int i=n+m+k-1;i;i--)
      inv[i]=Mul(inv[i+1],i+1); 
	sum=1;ans=ksm(3,n+m+k-n);
	for (int i=n+1;i<=n+k;i++) {
	  sum=Sub(sum*2%Mod,C(i-1-n,m));
	  ans=Add(ans,Mul(Mul(C(i-1,n-1),sum),ksm(3,n+m+k-i)));
    }
	for (int i=n+k+1;i<=n+m+k;i++) {
		sum=Sub(sum*2%Mod,C(i-1-n,m));
		sum=Sub(sum,C(i-1-n,i-1-n-k));
		ans=Add(ans,Mul(Mul(C(i-1,n-1),sum),ksm(3,n+m+k-i)));
	}
	printf("%d\n",ans);
}
		  

Measured memory_bytes: 7424
// luogu-judger-enable-o2
// =================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// =================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=2000+10;

struct Edge { int v,nxt; } e[N];
int head[N];

inline void addEdge(int u,int v) {
    static int cnt=0;
    e[++cnt]=(Edge){v,head[u]},head[u]=cnt;
}

int n;
int a[N],vis[N],deg[N];
int G[N][N];

inline void dfs(int u) {
    vis[u]=1;
    for (re int i=1;i<=n;++i) {
        if (vis[i]||!G[u][i]) continue;
        ++deg[i],addEdge(u,i);
        dfs(i);
    }
}

inline void topsort() {
    priority_queue<int> Q;
    for (re int i=1;i<=n;++i)
        if (!deg[i]) Q.push(i);
    while (!Q.empty()) {
        int u=Q.top(); Q.pop();
        printf("%d ",a[u]);
        for (re int i=head[u];i;i=e[i].nxt) Q.push(e[i].v);
    }
}

int main() {
    n=read();
    for (re int i=1;i<=n;++i) a[i]=read();
    sort(a+1,a+n+1);
    for (re int i=1;i<=n;++i)
        for (re int j=i+1;j<=n;++j) {
            if (__gcd(a[i],a[j])==1) continue;
            G[i][j]=G[j][i]=1;
        }
    for (re int i=1;i<=n;++i)
        if (!vis[i]) dfs(i);
    topsort();
    return 0;
}


Measured memory_bytes: 16128
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		long l = s.nextLong();
		long r = s.nextLong();
		System.out.println(calc(l, r));
	}

	public static long calc(long l, long r) {
		long next2019 = l - l % 2019 + 2019;
		if (l == 0 || r >= next2019) {
			return 0;
		}
		long min = Long.MAX_VALUE;
		for (long i = l; i < next2019 && i < r; i++) {
			for (long j = i + 1; j < next2019 && j <= r; j++) {
				min = Math.min(min, (i * j) % 2019);
				if ((i * j) % 2019 == 0) {
					return 0;
				}
			}
		}
		return min;
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
const ll INF = 1e9+10;

int h[100007];
vi graph[100007];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	int m; cin >> m;
	FOR(i, n) cin >> h[i];
	FOR(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].PB(b);
		graph[b].PB(a);
	}

	int ans = 0;
	FOR(i, n){
		bool ok = true;
		for(auto& v : graph[i]){
			if(h[v] >= h[i])
				ok = false;
		}
		if(ok) ans++;
	}

	cout << ans << '\n';


	return 0;
}

Measured memory_bytes: 9184
import numpy as np

n = int(input())
a = list(map(int, input().split(" ")))

a_sorted = sorted(a)

result = a_sorted.pop(0)
while a_sorted:
    a = a_sorted.pop(0)
    result = sum([a, result]) / 2
    if not a_sorted:
        print(result)

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

using namespace std;

int main()
{
	int a, b, d = 0, r = 0;
	double f = 0;
	scanf("%d %d", &a, &b);
	
	if(b > 0)
		d = a / b;
	
	r = a % b;
	f = (double) a / b;
	
	printf("%d %d %.5f", d, r, f);
	
	return 0;
}


Measured memory_bytes: 3208
N = int(input())
exist = False
num = None
for K in range(1, N+1):
    if K * (K + 1) // 2 == N:
        exist = True
        num = K
        break

if not exist:
    print("No")
else:
    print("Yes")
    print(num + 1)
    res = [[] for _ in range(num + 1)]
    tot = 1
    for k in range(num, 0, -1):
        for i in range(k):
            res[num - k].append(tot + i)
            res[num - k + i + 1].append(tot + i)
        tot += k

    for i in range(num + 1):
        ans = []
        ans.append(len(res[i]))
        ans += res[i]
        print(" ".join(map(str, ans)))



Measured memory_bytes: 43868
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,i=0,e=0,w=0,an=1e9,a[300003];
	char c[300003];
	cin>>n;
	for(;i<n;)
	{
		cin>>c[i];
		a[i]=w;
		w+=c[i++]==87;
	}
	for(i=n-1;i>-1;i--)
	{
		an=min(an,a[i]+e);
		e+=c[i]==69;
	}
	cout<<an<<endl;
}

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

int main(){
  int N;
  int Alice = 0;
  int Bob = 0;
  int i;
  
  cin >> N;
  vector<int> card(N);
  for(i=0;i<N;++i){
    cin >> card.at(i);
  }

  sort(card.begin(),card.end());
  for(i=0;i<N;++i){
    if(i%2 == 0){
      Alice += card.at(N-1-i);
    }else{
      Bob += card.at(N-1-i);
    }
  }

  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
MOD=10**9+7 
def sumXOR( arr, n): 
	sum = 0
	for i in range(0, 75): 
		zc = 0
		oc = 0
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] >>=1 
		idsum = (oc * zc * pow(2,i,MOD))%MOD
		sum = sum%MOD + idsum; 
		sum%=MOD 
	return sum%MOD 
n=int(input())
arr=[int(i) for i in input().split()]
MOD=10**9+7 
print(sumXOR(arr,n)%MOD)


Measured memory_bytes: 125624
#include <stdio.h>

int main() {

int j1,j2,t;

  for (;;) 
  {
    scanf("%d %d\n", &j1,&j2);
    if (j1==0 && j2==0) break;
    if (j1>j2) {
      t=j2;
      j2=j1;
      j1=t;
    }
    printf("%d %d\n",j1,j2);
  }

  return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


string calc(int n){
	string ret("0000000");
	rep(i,7){
		ret[i]=n%2+'0';
		n/=2;
	}
	reverse(all(ret));
	return ret;
}



int main(){
	int v[11]={63,6,91,79,102,109,125,39,127,111,0};
	int a=10,b,c;
	int n;
	while(cin>>n && n>0){
		a=10;
		rep(i,n){
			cin>>b;
			c=(v[a]^v[b]);
			cout<<calc(c)<<endl;
			a=b;
		}
	}
}

Measured memory_bytes: 1196
Imports System.Console
Module Module1
    Dim n As Int64
    Dim a() As Integer
    Dim ans As Int64
    Sub Main()
        n = ReadLine()
        Dim s() As String = ReadLine.Split
        ReDim a(s.Length - 1)
        For i = 0 To s.Length - 1
            a(i) = s(i)
        Next
        For i = 0 To a.Length - 1
            If ((i + 1) * a(i)) Mod 2 = 1 Then
                ans += 1
            End If
        Next
        WriteLine(ans)
    End Sub
End Module


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

string parse(int &p, string &s){
	string ret;
	while(s[p] != ']' && p < (int)s.length()){
		if(s[p] == '['){
			string tmp = parse(++p, s);
			reverse(tmp.begin(), tmp.end());
			ret += tmp;
		}else{
			int diff = 0;
			while(s[p] == '+' || s[p] == '-'){
				if(s[p] == '+'){
					diff++;
				}else{
					diff--;
				}
				p++;
			}
			if(s[p] == '?'){
				ret += 'A';
			}else{
				ret += 'A' +(s[p]-'A'+diff+2600)%26;
			}
			p++;
		}
	}
	p++;
	return ret;
}

int main(){
	while(1){
		string s;
		cin >> s;
		if(s == ".") break;
		int p = 0;
		cout << parse(p, s) << endl;
	}
	return 0;
}


Measured memory_bytes: 3156
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
  	"sort"
)
func main(){
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
//   	loopNum, _ := strconv.Atoi(sc.Text())
  	
 	sc.Scan()
  nums := strings.Split(sc.Text(), " ")
  intNums := make([]int, 0)
  for _, n := range nums {
    i, _ := strconv.Atoi(n)
    intNums = append(intNums, i)
  }
    
  sort.Sort(sort.Reverse(sort.IntSlice(intNums)))
  
  alice := 0
  bob := 0
  
  for i, card := range intNums {
      if i%2==0 {
          alice+=card
      } else {
          bob+=card
      }
  }
  
  fmt.Println(alice-bob)
}

Measured memory_bytes: 1784
<?php

/**
 * Class DSU
 * ref. AtCoder Library
 * 無向グラフに対して、<br>
 * 1. 辺の追加<br>
 * 2. 2頂点が連結かの判定<br>
 * をならし O(α(n)) 時間で処理することが出来ます。<br>
 * また、内部的に各連結成分ごとに代表となる頂点を 1つ持っています。<br>
 * 辺の追加により連結成分がマージされる時、新たな代表元は元の連結成分の代表元のうちどちらかになります。<br>
 */
class DSU
{
    private int $n;
    private array $parent;

    /**
     * DSU constructor.<br>
     * n 頂点 00 辺の無向グラフを作ります。<br>
     * 制約<br>
     * 0 ≤ n ≤ 10^8 <br>
     * 計算量<br>
     * O(n)<br>
     * @param int $n
     */
    function __construct(int $n)
    {
        $this->n = $n;
        $this->parent = array_fill(0,$n,-1);
    }

    /**
     * 辺 (a, b) を足します。<br>
     * a, bが連結だった場合はその代表元、非連結だった場合は新たな代表元を返します。<br>
     * 制約<br>
     * 0 ≤ a < n<br>
     * 0 ≤ b < n<br>
     * 計算量<br>
     * ならし O(α(n))
     * @param int $a
     * @param int $b
     * @return int
     */
    public function merge(int $a, int $b):int
    {
        assert(0 <= $a && $a < $this->n);
        assert(0 <= $b && $b < $this->n);
        $x = $this->leader($a);
        $y = $this->leader($b);
        if($x === $y){
            return $x;
        }
        if(-$this->parent[$x] < -$this->parent[$y]){
            [$x, $y] = [$y, $x];
        }
        $this->parent[$x] += $this->parent[$y];
        $this->parent[$y] = $x;
        return $x;
    }

    /**
     * 頂点 a, ba,b が連結かどうかを返します。<br>
     * 制約<br>
     * 0 ≤ a < n<br>
     * 0 ≤ b < n<br>
     * 計算量<br>
     * ならし O(α(n))
     * @param int $a
     * @param int $b
     * @return bool
     */
    public function same(int $a, int $b): bool
    {
        assert(0 <= $a && $a < $this->n);
        assert(0 <= $b && $b < $this->n);
        return $this->leader($a) === $this->leader($b);
    }

    /**
     * 頂点aの属する連結成分の代表元を返します。<br>
     * 制約<br>
     * 0 ≤ a < n<br>
     * 計算量<br>
     * ならし O(α(n))<br>
     * @param int $a
     * @return int
     */
    public function leader(int $a): int
    {
        if($this->parent[$a] < 0){
            return $a;
        }
        return $this->parent[$a] = $this->leader($this->parent[$a]);
    }

    /**
     * 頂点aの属する連結成分のサイズを返します。<br>
     * 制約<br>
     * 0 ≤ a < n<br>
     * 計算量<br>
     * ならし O(α(n))<br>
     * @param int $a
     * @return int
     */
    public function size(int $a):int
    {
        assert(0 <= $a && $a < $this->n);
        return -$this->parent[$this->leader($a)];
    }

    /**
     * グラフを連結成分に分け、その情報を返します。<br>
     * 返り値は「「一つの連結成分の頂点番号のリスト」のリスト」です。<br>
     * (内側外側限らず)vector内でどの順番で頂点が格納されているかは未定義です。<br>
     * 計算量<br>
     * O(n)<br>
     * @return array
     */
    public function groups(): array
    {
        $leader_buf = $group_size = array_fill(0,$this->n, 0);
        $result = [];
        for($i=0;$i<$this->n;$i++){
            $result[$this->leader($i)][] = $i;
        }
        return $result;
    }
}

[$N, $Q] = fscanf(STDIN, "%d%d");
$dsu = new DSU($N);
while($Q--){
    [$T, $U, $V] = fscanf(STDIN, "%d%d%d");
    if($T === 0){
        $dsu->merge($U, $V);
    }else{
        if($dsu->same($U, $V)){
            echo 1 .PHP_EOL;
        }else{
            echo 0 .PHP_EOL;
        }
    }
}

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

// 1-origin
struct BIT{
    int n, mod;
    vector<int> v;

    BIT(int _n, int _mod) : n(_n), mod(_mod){
        v.resize(n+1, 0);
    }

    void add(int k, int x){
        while(k <= n){
            (v[k] += x) %= mod;
            k += k&-k;
        }
    }

    int sum(int k){
        int ret = 0;
        while(k > 0){
            (ret += v[k]) %= mod;
            k -= k&-k;
        }
        return ret;
    }
};

typedef long long ll;

int main(){
    int a, b, p;
    while(cin >> a >> b >> p, p){
        int n = b-a+1;
        vector<string> vs;
        for(int i = 0; i < n; i++)  vs.push_back(to_string(a+i));
        sort(vs.begin(), vs.end());
        vector<int> rev(n);
        for(int i = 0; i < n; i++){
            rev[stoi(vs[i])-a] = i;
        }
        ll ans = 0;
        BIT bit(n, p);
        for(int i = 0; i < n; i++){
            ll tmp = bit.sum(rev[i])+1;
            (ans += tmp) %= p;
            bit.add(rev[i]+1, tmp);
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 9312
N,W = map(int,input().split())

L = []
for i in range(N):
    L.append(list(map(int,input().split())))
    
MAX_ANS = 0
for fgo in range(0,8):
    FGO = [pow(-1,fgo%2),pow(-1,(fgo//2)%2),pow(-1,(fgo//4)%2)]
    L = sorted(L,key=lambda x:x[0]*FGO[0]+x[1]*FGO[1]+x[2]*FGO[2],reverse=True)
    ans = 0
    for m in L[:W]:
        ans += m[0]*FGO[0] + m[1]*FGO[1] + m[2]*FGO[2]
    if ans > MAX_ANS: MAX_ANS = ans

print(MAX_ANS)

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>

using std::endl;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std


int N;

int T, X, Y;
int N_T = 0, N_X = 0, N_Y = 0;
int T_buf, move_buf;

int main()
{
	IN >> N;

	LEP(a, N)
	{
		IN >> T >> X >> Y;

		T_buf = T - N_T;
		move_buf = 0;
		move_buf += abs(X - N_X);
		move_buf += abs(Y - N_Y);

		if (T_buf < move_buf)
		{
			puts("No");
			return 0;
		}
		else if ((T_buf - move_buf) % 2 == 1)
		{
			puts("No");
			return 0;
		}

	}

	puts("Yes");

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""abc079_a"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    d = input()
    if d[0] == d[1] and d[1] == d[2] or d[1] == d[2] and d[2] == d[3]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 3828