akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String[] array = input.split(" ");
        int num1 = Integer.parseInt(array[0]);
        int num2 = Integer.parseInt(array[2]);

        if(array[1].equals("+")) {
            System.out.println(num1+num2);
        } else if(array[1].equals("-")) {
            System.out.println(num1-num2);
        }
    }
}


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

int arra[200001];

int rec(int i, int n, int a[]) {
  if(i >= n-1) {
    arra[i] = 0;
  }
  if(arra[i] == -1) {
      arra[i] = min(
        abs(a[i]-a[i+1]) + rec(i+1,n,a),
        abs(a[i]-a[i+2]) + rec(i+2,n,a) );
    }
  return arra[i];
}

int main() {
  for (size_t i = 0; i < 200001; i++) {
    arra[i] = -1;
  }
  int n;
  cin >> n;
  int a[n];
  int count = 0;
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
  }

  count = rec(0,n,a);

  std::cout << count << '\n';
  return 0;
}


Measured memory_bytes: 5376
// Problem: A - Not
// Contest: AtCoder - AtCoder Beginner Contest 178
// URL: https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9;
#define ld long double
#define PI 3.14159265358979323846
#pragma GCC optimize("-O2")
const int INF = 10000000;

int getIInput() {
	cout.flush();
	#ifdef LOCAL
	return generateLocalInputOrAnythingYouWant();
	#else
	int x;
	cin>>x;
	return x;
	#endif
}

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
//3. Ends here
 
//1. Data structures declaration here
//1. Ends here
 
//2. Extra Functions here
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{
	int x;
	cin>>x;
	cout<<1-x;
    return;
}
// how r u bro

Measured memory_bytes: 3648
#2 5 5 4 5 6 3 7 6
#ナップザックのdpかな
#dp[i][v] = dp[i-A[i]][v-M[i]*(10*i)]

import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N,M = na()
A = na()
cost = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

d = {i:cost[i] for i in A}

dp = [-1]*(N+1)
dp[0] = 0
ans = [0]*(N+1)
for i in range(N+1):
    for j in range(10)[::-1]:
        if j not in d:
            continue
        elif d[j] > i:
            continue
        else:
            #print(j)
            if dp[i] < dp[i-d[j]]+1:
                dp[i] = dp[i-d[j]]+1
                ans[i] = j
S = ""
pos = N
#print(dp,ans)
while pos!=0:
    #print(pos)
    S+=str(ans[pos])
    pos-=d[ans[pos]]


print(S)

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

ll hor(ll h, ll w) {
    ll x = h / 3;
    ll mx = x + (h % 3 != 0);
    ll mn = x;
    return w * (mx - mn);
}

pair<ll, ll> divv(ll h, ll w) {
    ll x = h / 2;
    ll mn = x;
    ll mx = x + h % 2;
    return {mn * w, mx * w};
}

int main() {
#if __APPLE__
    //freopen("A.in", "r", stdin);
    //freopen("A.out", "w", stdout);
#endif

    ll h, w;
    cin >> h >> w;

    ll ans = min(hor(h, w), hor(w, h));
    for (int i = 1; i < h; ++i) {
        ll area = (h - i) * w;
        auto v = divv(w, i);
        ll mn = min({area, v.fi, v.se});
        ll mx = max({area, v.fi, v.se});
        ans = min(ans, mx - mn);
    }
    for (int i = 1; i < w; ++i) {
        ll area = (w - i) * h;
        auto v = divv(h, i);
        ll mn = min({area, v.fi, v.se});
        ll mx = max({area, v.fi, v.se});
        ans = min(ans, mx - mn);
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    map.insert(0, 1);
    for _ in 0..N {
        let entry = map.entry(read()).or_insert(0);
        *entry += 1;
        if *entry >= 3 {
            println!("0");
            return;
        }
    }
    let mut vec: Vec<(usize, usize)> = vec![];
    for v in map {
        vec.push(v);
    }
    let mins = dfs(0, &vec, vec![]);
    println!("{}", mins.iter().max().unwrap());
}

fn dfs(depth: usize, vec: &[(usize, usize)], times: Vec<usize>) -> Vec<usize> {
    if depth == vec.len() {
        let mut now_times = times;
        now_times.sort();
        now_times.push(24);
        let min = now_times
            .windows(2)
            .fold(1000, |acc, v| std::cmp::min(acc, (v[1] - v[0]) % 24));
        return vec![min];
    }
    let v = vec[depth].0;
    let count = vec[depth].1;
    if count == 2 {
        let mut now_times = times;
        now_times.push(v);
        now_times.push(24 - v);
        dfs(depth + 1, vec, now_times)
    } else {
        let mut now_times_mut = times.clone();
        now_times_mut.push(v);
        let mins1 = dfs(depth + 1, vec, now_times_mut);
        let mut now_times_mut = times;
        now_times_mut.push(24 - v);
        let mins2 = dfs(depth + 1, vec, now_times_mut);
        [mins1, mins2].concat()
    }
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val (n, k) = getInts()
    val p = getInts().map { it - 1 }
    val c = getLongs()

    val visit = BooleanArray(n) { false }

    var out = Long.MIN_VALUE
    (0 until n).forEach {
        out = Math.max(out, go(n, k, p, c, it, visit))
    }
    println(out)
}

fun go(n: Int, k:Int, p: List<Int>, c: List<Long>, index: Int, visit: BooleanArray): Long {
    if (visit[index]) return Long.MIN_VALUE

    val ring = ArrayList<Int>()
    val score = ArrayList<Long>()
    var now = index
    while (true) {
        ring.add(now)
        visit[now] = true

        now = p[now]
        score.add(c[now])
        if (now == ring.first()) break
    }

    if (ring.size >= k) {
        return sumScore(score, k)
    } else {
        val sum = score.sum()
        if (sum < 0) {
            return sumScore(score, ring.size)
        } else {
            val turn = k / ring.size
            val remain = k % ring.size
            if (remain == 0) {
                return sumScore(score, ring.size) + (sum * (turn - 1))
            } else {
                return sumScore(score, remain) + (sum * turn)
            }
        }
    }
}

fun sumScore(score: List<Long>, k: Int): Long {
    var mm = Long.MIN_VALUE
    score.indices.forEach { skip ->
        var sum = 0L
        var m = Long.MIN_VALUE
        (0 until k).map { score[(it + skip) % score.size] }.forEach {
            sum += it
            m = Math.max(m, sum)
        }
        mm = Math.max(mm, m)
    }
    return mm
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }
fun getLong() = readLine()!!.toLong()
fun getLongs() = readLine()!!.split(" ").map { it.toLong() }



Measured memory_bytes: 58120
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_H = 12;

int H, W;
string S[MAX_H];

bool synmetry (string s1, string s2) {
  int n = s1.size();
  REP(i, n) {
    if(s1[i] != s2[n - 1 - i]) {
      return false;
    }
  }
  return true;
}

bool check(string s[]) {
  bool used[W];
  REP(j, W) used[j] = false;
  bool center_is_remain = false;
  if(W % 2 == 1) center_is_remain = true;
  REP(j, W) {
    if(used[j]) continue;
    bool flag = false;
    REP(k, W) {
      if(k == j || used[k]) continue;
      if(synmetry(s[j], s[k])) {
        flag = true;
        used[j] = true;
        used[k] = true;
        break;
      }
    }
    if(!flag) {
      if(center_is_remain && synmetry(s[j], s[j])) {
        center_is_remain = false;
        flag = true;
        used[j] = true;
      }
    }
    if(!flag) return false;
  }
  return true;
}

bool dfs(bool used[], vpi swaps, int crt) {
  // cout << "crt " << crt << endl << "used ";
  // REP(i, H) cout << used[i] << ",";
  // cout << endl << "swaps ";
  // REP(i, swaps.size()) cout << swaps[i].first << "-" << swaps[i].second << ", ";
  // cout << endl;

  if(crt == H) {
    string swapped[H];
    REP(i, H) swapped[i] = S[i];
    REP(i, swaps.size()) {
      swap(swapped[swaps[i].first], swapped[swaps[i].second]);
    }
    string s[W];
    REP(i, H) {
      REP(j, W) {
        s[j].push_back(swapped[i][j]);
      }
    }
    // cout << endl << "swaps ";
    // REP(i, swaps.size()) cout << swaps[i].first << "-" << swaps[i].second << ", ";
    // cout << endl;
    // REP(j, W) cout << s[j] << endl;
    // cout << "check " << check(s) << endl;
    return check(s);
  }
  if(used[crt]) {
    return dfs(used, swaps, crt + 1);
  }
  used[crt] = true;
  REP(i, H) {
    if(used[i]) continue;
    vpi tmp_swaps = swaps;
    bool tmp_used[H];
    REP(j, H) tmp_used[j] = used[j];
    tmp_swaps.push_back(pi(crt, i));
    tmp_used[i] = true;
    if(dfs(tmp_used, tmp_swaps, crt + 1)) return true;
  }
  return dfs(used, swaps, crt + 1);
}

int main(){
  cin >> H >> W;
  REP(i, H) cin >> S[i];

  bool used[H];
  REP(i, H) used[i] = false;
  vpi swaps;
  if(dfs(used, swaps, 0)) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 384
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]

def check(mid,k,ar):
    ct=k
    for i in ar:
        if(i<=mid):
            continue
        ct-=(i//mid)
    return ct>=0
def main():
    n,k=map(int,input().split())
    ar=inpt()
    i,j=1,100000000000
    while(i<j):
        mid=(i+j)//2
        if(check(mid,k,ar)):
            j=mid
        else:
            i=mid+1
    print(i)

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


Measured memory_bytes: 35872
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
int main()
{
    int n,s,cnt,c=0;
    cin>>n>>s;
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=n; j++)
        {
            cnt=s-(i+j);
            if(cnt>=0&&cnt<=n)
               c++;
        }

    }
    cout<<c;
    nl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;

string hoge(string S) {
	int cnt[6030]={};
	int vis[6030]={};
	vector<int> As,Bs;
	
	int a=0,b=0,i,j;
	FOR(i,S.size()) {
		if(S[i]=='a') {
			cnt[i]=a++;
			As.push_back(i);
		}
		else {
			cnt[i]=b++;
			Bs.push_back(i);
		}
	}
	
	string R;
	
	if(S[0]=='a') {
		FOR(i,S.size()) {
			if(vis[i]==0) {
				R+=S[i];
				if(S[i]=='a') {
					for(int j=i+1;j<Bs[cnt[i]];j++) vis[j]=vis[Bs[cnt[j]]]=1;
				}
			}
		}
	}
	else {
		FOR(i,S.size()/2) {
			string T;
			FOR(j,S.size()) {
				if(cnt[j]>=i) T+=S[j];
			}
			R=max(R,T);
		}
	}
	return R;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	string T;
	vector<string> V;
	
	x=0;
	FORR(c,S) {
		T+=c;
		if(c=='a') x++;
		else x--;
		if(x==0) {
			string P=hoge(T);
			
			while(V.size() && P > V.back()+P) V.pop_back();
			V.push_back(P);
			T="";
		}
	}
	
	FORR(c,V) cout<<c;
	cout<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 512
// finish date: 2018/04/16

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];
    int ans = 0;
    int i = 0;
    while (i < N) {
        ans++;
        while (i + 1 < N && a[i] == a[i + 1]) i++;
        if (i == N - 1) break;
        if (a[i] < a[i + 1]) {
            while (i + 1 < N && a[i] <= a[i + 1]) i++;
        } else {
            while (i + 1 < N && a[i] >= a[i + 1]) i++;
        }
        i++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
l=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append(a);l.append(b)
l.sort()
for j in range(1,n+1):
    print(l.count(j))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(int i=a; i<b; i++)
#define loopb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n;
	cin>>n;
	vector<vll> s(n, vll(3));
	loop(i, 0, n)	cin>>s[i][0]>>s[i][1]>>s[i][2];
	vector<vll> dp(n, vll(3, 0));
	dp[0] = s[0];
	loop(i, 1, n){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + s[i][0];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + s[i][1];
		dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + s[i][2];
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 11264
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdlib.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

typedef struct{
    int n;
    int p;
    int y;
    int x;
}City;

int compare_struct(const void *a, const void *b){
    City *A = (City *)a;
    City *B = (City *)b;
    return A->y - B->y;
}

int compare_struct2(const void *a, const void *b){
    City *A = (City *)a;
    City *B = (City *)b;
    return A->n - B->n;
}

int main(void){
    int N, M;
    cin >> N >> M;
    int pn[N];
    REP(i,N) pn[i] = 1;
    City city[M];
    REP(i,M) cin >> city[i].p >> city[i].y;
    REP(i,M) city[i].n = i+1;
    qsort(city, M, sizeof(City), compare_struct);
    REP(i,M) city[i].x = pn[city[i].p-1]++;
    qsort(city, M, sizeof(City), compare_struct2);

    REP(i,M){
        cout << setfill('0') << setw(6) << city[i].p;
        cout << setfill('0') << setw(6) << city[i].x << endl;
    }

    return 0;
}

Measured memory_bytes: 5088
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Dec  1 02:24:03 2018
//
package main

import (
	"fmt"
	"math"
)

var n int
var t, a float64
var hs []int

func main() {
	fmt.Scan(&n)
	fmt.Scan(&t, &a)

	hs := make([]int, n)
	for i := range hs {
		fmt.Scan(&hs[i])
	}

	minIndex := 0
	minVal := 1e60
	for i := range hs {
		diff := math.Abs(a - (t - float64(hs[i])*0.006))
		if diff < minVal {
			minIndex = i
			minVal = diff
		}
	}

	fmt.Println(minIndex + 1)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String num = scan.nextLine();
		int diff0 = 0;
		int diff1 = 0;
		for (int i=0; i<num.length(); i++) {
			int sheet = Character.getNumericValue(num.charAt(i));
			if (i % 2 == 0) {
				if (sheet == 0) {
					diff1++;
				} else {
					diff0++;
				}
			} else {
				if (sheet == 0) {
					diff0++;
				} else {
					diff1++;
				}
			}
		}

		if (diff0 > diff1) {
			System.out.println(diff1);
		} else {
			System.out.println(diff0);
		}
	}
}

Measured memory_bytes: 28236
from copy import deepcopy
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

if sum(a) < sum(b):
    print(-1)
    exit()

diffs = sorted([(ai, bi, ai - bi) for ai, bi in zip(a, b)], key = lambda x: x[2])
# print(diffs)
if diffs[0][2] >= 0:
    print(0)
    exit()

remains = [d for _, _, d in diffs]
idx = 1
remains_changed = deepcopy(remains)
for i, d in enumerate(remains_changed):
    if d >= 0:
        break
    else:
        while d < 0:
            if remains_changed[-idx] >= -d:
                remains_changed[-idx] += d
                d = 0
                remains_changed[i] = 0
            else:
                d += remains_changed[-idx]
                remains_changed[-idx] = 0
                idx += 1
# print(remains)
# print(remains_changed)
ans = 0
for r, rc in zip(remains, remains_changed):
    if r != rc:
        ans += 1
print(ans)


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

int main() {
    int N;
    cin >> N;
    int odd = 0;
    long long int A;
    for (int i=0; i<N; ++i) {
        cin >> A;
        if (A % 2 == 1) ++odd;
    }
    if (odd % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 632
#include<stdio.h>
int main(){
  long long a,b,c,d=2;
  scanf("%lld %lld %lld",&a,&b,&c);
  if(c==0)d=1;
  printf("%.10lf\n",((b-1.0)*(a-c)*d)/(a*a));
  return 0;
}


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

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class EStringsOfImpurity {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string s, t;
	    in >> s >> t;
	    unordered_map<char, vector<int>> positions;
	    REP(i,0,s.size()) {
	        positions[s[i]].emplace_back(i);
	    }
	    int count = 0;
	    int currentIndex = -1;
	    REP(i,0,t.size()) {
	        const char c = t[i];
	        if (positions[c].size() == 0) {
	            out << -1 << "\n";
	            return;
	        }
	        const auto itr = upper_bound(all(positions[c]), currentIndex);
	        if (itr == positions[c].end()) {
	            count++;
	            currentIndex = positions[c].front();
	        } else {
	            currentIndex = *itr;
	        }
	    }
	    out << (ll)count * (ll)s.size() + (ll)currentIndex + 1 << "\n";
	}
};


int main() {
	EStringsOfImpurity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1216
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,W = map(int,readline().split())
A1 = []
A2 = []
A3 = []
A4 = []
w1,v1 = map(int,readline().split())
A1.append(v1)

for _ in range(N-1):
    w,v = map(int,readline().split())
    if w == w1:
        A1.append(v)
    elif w == w1+1:
        A2.append(v)
    elif w == w1+2:
        A3.append(v)
    else:
        A4.append(v)

S1 = list(accumulate(sorted(A1,reverse = True)))
S2 = list(accumulate(sorted(A2,reverse = True)))
S3 = list(accumulate(sorted(A3,reverse = True)))
S4 = list(accumulate(sorted(A4,reverse = True)))

S1 = [0] + S1
S2 = [0] + S2
S3 = [0] + S3
S4 = [0] + S4

ans = 0
for a in range(len(S1)):
    for b in range(len(S2)):
        for c in range(len(S3)):
            for d in range(len(S4)):
                tmp = w1*(a+b+c+d)+b+2*c+3*d
                total = S1[a]+S2[b]+S3[c]+S4[d]
                if tmp <= W:
                    ans = max(ans,total)
print(ans)

Measured memory_bytes: 73628
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	for(int i = 0; i < h; ++i){
		cin >> v[i];
	}

	const int M = 610;
	int cnt[M][M] = {};
	for(int i = 0; i < h; ++i)
	for(int j = 0; j < w; ++j)
	if(v[i][j] == '#'){
		cnt[i + j + 2][i - j + 302] = 1;
	}
	int sumh[M][M] = {}, sumv[M][M] = {};
	for(int i = 1; i < M; ++i)
	for(int j = 1; j < M; ++j){
		sumh[i][j] = sumh[i][j - 1] + cnt[i][j];
		sumv[i][j] = sumv[i - 1][j] + cnt[i][j];
	}
	
	LL res1 = 0, res2 = 0;
	for(int y1 = 0; y1 < M; ++y1)
	for(int x1 = y1 & 1; x1 < M; x1 += 2)
	if(cnt[y1][x1]){
		for(int x2 = x1 + 2; x2 < M; x2 += 2)
		if(cnt[y1][x2]){
			int d = x2 - x1;
			for(int s = -1; s <= 1; s += 2){
				int y2 = y1 + d * s;
				if(y2 < 0 || y2 >= M){ continue; }
				res1 += cnt[y2][x1];
				res1 += cnt[y2][x2];
				if(d >= 2){
					res2 += sumh[y2][x2 - 1] - sumh[y2][x1];
				}
			}
		}
		for(int y2 = y1 + 2; y2 < M; y2 += 2)
		if(cnt[y2][x1]){
			int d = y2 - y1;
			for(int s = -1; s <= 1; s += 2){
				int x2 = x1 + d * s;
				if(x2 < 0 || x2 >= M){ continue; }
				res1 += cnt[y1][x2];
				res1 += cnt[y2][x2];
				if(d >= 2){
					res2 += sumv[y2 - 1][x2] - sumv[y1][x2];
				}
			}
		}
	}
	LL ans = res1 / 2 + res2;
	cout << ans << '\n';
}



}
int main() try{
	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 4736
import java.io.*;
  
class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
            int n = Integer.parseInt( kb.readLine() );
             
            int num;
			int cnt = n;
            int i, j;
			int[] nums = new int[n];
            for( i=0; i<n; i++ ) {
				nums[i] = Integer.parseInt( kb.readLine() );
			}
			for( i=0; i<n; i++ ) {
				if( 2 == nums[i] ) { continue; }
				if( 0 == nums[i]%2 ) {
					cnt--;
					continue;
				}
                for( j=3; j*j<=nums[i]; j+=2 ) {
                    if( 0 == nums[i]%j ) {
                        cnt--;
						break;
                    }
                }
            }
             
            System.out.println( cnt  );
              
            kb.close();
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

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

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var ans = Enumerable.Range(A, B - A + 1).Count(i => { var s = i.ToString(); return s == s.Reverse(); });
            WriteLine(ans);
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
    }
}


Measured memory_bytes: 17488
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N,i;
  int *A;

  scanf("%d",&N );
  A = calloc(N, sizeof(int));

  for(i=0; i<N; i++)
    scanf("%d",&A[i]);

  for(i=0; i<N; i++){
    if(A[i]%2 != 0)
      continue;
    else if(A[i]%6 == 0 || A[i]%10 == 0)
      continue;
    else{
      puts("DENIED");
      return 0;
    }
  }
  puts("APPROVED");

  free(A);

  return 0;
}


Measured memory_bytes: 1644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int sum = 0;
			int result = 0;
			if (n == 0) {
				break;
			}
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i != j && i != k && j != k) {
							sum = i + j + k;
							if (sum == x) {
								result++;
							}
						}
					}
				}
			}
			System.out.println(result);
		}

	}
}


Measured memory_bytes: 26652
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<int> vecint;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)

#define MAX_V 200
#define INF 1e+9





int main() {
	int A, B;
	int X;
	cin >> X >> A >> B;
	if (A >= B)
		cout << "delicious";
	else if (X >= B - A)
		cout << "safe";
	else
		cout << "dangerous";

	return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
MOD = 10**9+7

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
for i in range(0, min(K, N)):
    if T[i] == 'r':
        ans += P
    elif T[i] == 's':
        ans += R
    else:
        ans += S
    flg = True
    for j in range(i+K, N, K):
        if T[j-K] == T[j] and flg:
            flg = False
        else:
            if T[j] == 'r':
                ans += P
            elif T[j] == 's':
                ans += R
            else:
                ans += S
            flg = True
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 9;
bool comp(pii a,pii b){
    return a.F+a.S < b.F+b.S;
}
bool comp2(pii a,pii b){
    return a.F-a.S < b.F-b.S;
}
bool comp3(pii a,pii b){
    return -a.F+a.S < -b.F+b.S;
}
bool comp4(pii a,pii b){
    return -a.F-a.S < -b.F-b.S;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    vector<pii> maxxy;
    vector<pii> maxx;
    vector<pii> maxy;
    vector<pii> ma;
    rep(i,0,n){
        ll x,y;
        cin>>x>>y;
        maxxy.push_back({x,y});
        maxx.push_back({x,y});
        maxy.push_back({x,y});
        ma.push_back({x,y});
    }
    sort(all(maxxy),comp);
    sort(all(maxx),comp2);
    sort(all(maxy),comp3);
    sort(all(ma),comp4);
    vector<pii> inter;
    inter.push_back(maxxy[n-1]);
    inter.push_back(maxx[n-1]);
    inter.push_back(maxy[n-1]);
    inter.push_back(ma[n-1]);
    ll ans=-INF;
    rep(i,0,4){
        rep(j,0,4){
            if(i==j){
                continue;
            }
                ans = max(ans,abs(inter[i].F-inter[j].F)+abs(inter[i].S-inter[j].S));
        }
    }
    cout<<ans<<"\n";
    return 0;  
}   

Measured memory_bytes: 15876
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int k;
	cin >> k;

	for(int i = 0;i < n;i++){
		if(s[i] != s[k-1])s[i] = '*';
	}

	cout << s << endl;
}


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

int main(){
	int a;
	int flag = 0;
	string s;
	cin >> s;
	a = s.find("C", 0);
	if (a != -1){
		a = s.find("F", a);
		if (a != -1) flag = 1;
	}
	if (flag == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int ans = a[0];
  for(int i = 1; i < n; i++){
    ans = gcd(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}


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

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

  int N;
  N=s.size();

  int countA=N-1;
  int countZ=0;
  for (int i = 0; i < N; i++) {
     if (s.at(i)=='A') countA=min(countA,i);
     else if (s.at(i)=='Z') countZ=max(countZ,i); 
  }
  cout << countZ-countA+1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	string S;
	cin >> S;

	string y = S.substr(0,4);
	string m = S.substr(5, 2);
	string d = S.substr(8, 2);
	
	if (stoi(m) <= 4) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from scipy.sparse import*
_,*s=open(0)
M=999
*g,=eval('[0]*M,'*M)
i=0
for t in s:
 i+=1;j=0
 for u in t:k=i*20+j;g[k][k+1]=u>'#'<t[j+1];g[k][k+20]=u>'#'<(s+['#'*M])[i][j];j+=1
a=csgraph.johnson(csr_matrix(g),0)
print(int(max(a[a<M])))

Measured memory_bytes: 31908
import java.util.*
data class Neta(val t: Int, val d: Int)
fun main(args: Array<String>) {
    val (N, K) = listOfInt()
    val A = Array(N) {
        val (t, d) = listOfInt()
        Neta(t, d)
    }.sortedByDescending { it.d }
    val map = mutableMapOf<Int, Int>()
    val use = PriorityQueue<Neta>(N, Comparator { o1, o2 -> o1.d - o2.d }) //asc
    val rem = PriorityQueue<Neta>(N, Comparator { o1, o2 -> o2.d - o1.d }) //desc
    var sum = 0L
    var ans = 0L
    for (k in 0 until K) {
        use.add(A[k])
        map.put(A[k].t, map.getOrElse(A[k].t, { 0 }) + 1)
        sum += A[k].d
        ans = Math.max(ans, sum + map.size.squaredLong())
    }
    for (k in K until N) rem.add(A[k])
outside@
    while (!use.isEmpty()) {
        val u = use.poll()
        if (map.get(u.t)!! >= 2) {  // <-- ★
            while (!rem.isEmpty()) {
                val r = rem.poll()
                if (!map.containsKey(r.t)) {
                    map.put(r.t, 1)
                    sum += r.d - u.d
                    ans = Math.max(ans, sum + map.size.squaredLong())
                    continue@outside
                }
            }
            break@outside
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun Int.squaredLong() = this.toLong() * this.toLong()

Measured memory_bytes: 77264
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;
 
int main(){
  ll n,x;
  cin >> n >> x;
  ll a[n];
  rep(i,n)cin >> a[i];
  ll ans=0;
  ll temp=a[0];
  rep(i,n-1){
    ll res=temp+a[i+1]-x;
    if(res>0){
      ans+=res;
      temp=max((ll)0,x-temp);
    }
    else temp=a[i+1];
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N;
struct DISH{
	int a, b, sum;
}dish[100005];
int cmp(const void* A, const void* B){
	return (*(DISH*)A).sum < (*(DISH*)B).sum ? 1 : -1; 
}
int main(){
	
	scanf("%d",&N);
	for(int i = 0 ; i < N ; ++i){
		scanf("%d%d",&dish[i].a, &dish[i].b);
		dish[i].sum = dish[i].a + dish[i].b;
	}
	qsort(dish, N, sizeof(dish[0]), cmp);	
	
	long long suma = 0, sumb = 0;
	for(int i = 0 ; i < N ; ++i)
		if(i % 2)
			sumb += dish[i].b;
		else
			suma += dish[i].a;
	
	printf("%lld\n", suma - sumb);			
	
} 

Measured memory_bytes: 2556
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int main() {
    int n = 0, k = 0;
    scanf("%d %d\n", &n, &k);
    int raw[n+1];
    char s[n+2];
    fgets(s, n+2, stdin);
    int len_raw = 0;
    char c = 0;
    int i = 0;
    while (i < n) {
        raw[len_raw] = 0;
        while ((i < n) && (s[i] == '1')) {
            raw[len_raw]++;
            i++;
        }
        len_raw++;
        raw[len_raw] = 0;
        while ((i < n) && (s[i] == '0')) {
            raw[len_raw]++;
            i++;
        }
        len_raw++;
    }
    raw[len_raw] = 0;
    k = 2 * k - 1;
    int max = 0;
    for (int i=0; i<=k+1; i++) { 
        if (i >= len_raw) break;
        max += raw[i];
    }
    int buf = max;
    for (int i=k; i<len_raw-2; i += 2) {
        buf += raw[i+2] + raw[i+3] - raw[i-k] - raw[i-k+1];
        if (buf > max) max = buf;
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;

int main()
{
	int u[] = { 1, 2, 1, 2, 1, 4, 1, 4 };
	int p[8];
	while (scanf("%d %d %d %d %d %d %d %d"
		, p, p+1, p+2, p+3, p+4, p+5, p+6, p+7) != EOF)
	{
		int firstUma;
		int maxRide = 0;
		for (int i = 0; i < 8; ++i)
		{
			int canRide = 0;
			for (int j = 0; j < 8; ++j)
				canRide += min(p[j], u[(i+j)%8]);
			if (canRide > maxRide)
			{
				maxRide = canRide;
				firstUma = i;
			}
			else if (canRide == maxRide)
			{
				int a, b;
				a = b = 0;
				for (int k = 0; k < 8; ++k)
				{
					a = a*10 + u[(firstUma+k)%8];
					b = b*10 + u[(i+k)%8];
				}
				if (a > b)
					firstUma = i;
			}
		}
		for (int i = 0; ; ++i)
		{
			printf("%d", u[(firstUma+i)%8]);
			if (i < 7)
				printf(" ");
			else
			{
				printf("\n");
				break;
			}
		}
	}

	return 0;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{
    gearup;
    int n; cin >> n;
    string s; cin >> s;
    auto ss = s;
    sort(all(s));
    ll res = 0;
    rep(i,n) if(s[i] != ss[i])res++;
    out(res/2);
}

Measured memory_bytes: 3876
X, N = map(int,input().split())
p_n = list(map(int,input().split()))

p = list(range(102))

for i in p_n:
    for j in range(len(p)):
        if p[j] == i:
            p.pop(j)
            break
            

p_X = list(map(lambda x: x - X, p))
p_abs = list(map(abs,p_X))

print(p[p_abs.index(min(p_abs))])

Measured memory_bytes: 9100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, ans = 0;
    cin >> n;
    vector<string> s(n);
    int ends_a = 0, starts_b = 0, both = 0;
    for(int i=0;i<n;++i){
        cin >> s[i];
        for(int j=0;j<s[i].length()-1;++j) {
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ++ans;
        }

        if(s[i][0] == 'B') {
            if(s[i].back() == 'A') {
                ++both;
            } else {
                ++starts_b;
            }
        } else if(s[i].back() == 'A') {
            ++ends_a;
        }
    }

    bool flag = false;
    if(ends_a) {
        --ends_a;
        flag = true;
    } else if(both) {
        --both;
        flag = true;
    }
    if(flag) {
        if(both) {
            ans += both;
            both = 0;
        }
    }
    if(flag) {
        if(starts_b) {
            ++ans;
            --starts_b;
            flag = false;
        }
    }
    ans += min(ends_a, starts_b);

    cout << ans << endl;

}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c; cin>>a>>b>>c; cout<<a+b+c-max({a,b,c})<<"\n";
	return 0;
}

Measured memory_bytes: 256