akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int N, Q;
string S;
char t[200010], d[200010];

bool isOK(int index) {
    rep(i, Q) {
        if (t[i] == S[index]) {
            if (d[i] == 'R') index++;
            else if (d[i] == 'L') index--;
            if (index < 0) return true;
            if (index >= N) return false;
        }
    }
    return false;
}

// 汎用的な二分探索のテンプレ
int binary_search() {
    int ng = N; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = -1; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

bool isOK2(int index) {
    rep(i, Q) {
        if (t[i] == S[index]) {
            if (d[i] == 'R') index++;
            else if (d[i] == 'L') index--;
            if (index >= N) return true;
            if (index < 0) return false;
        }
    }
    return false;
}

// 汎用的な二分探索のテンプレ
int binary_search2() {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = N; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK2(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Q;
    cin >> S;
    rep(i, Q) {
        cin >> t[i] >> d[i];
    }
    //cout << binary_search() << " " << binary_search2() << endl;
    cout << (binary_search2() - 1) - binary_search() << endl;

    return 0;
}


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

template <typename T>
using lim = numeric_limits<T>;

const int MOD = 1e9+7;
const int MAXN = 1e5+1;

vector<int> prime;
bool is_composite[MAXN];
int mu[MAXN];
int cnt[MAXN];

void sieve(int n){
	memset(is_composite, 0, sizeof is_composite);
	mu[1] = 1;
	for (int i = 2; i < n; i++){
		if (!is_composite[i]) {
			prime.push_back(i);
			mu[i] = -1;
			cnt[i] = 1;
		}
		for (int j = 0; j < prime.size() and i*prime[j] < n; j++){
			is_composite[i*prime[j]] = true;
			if (i % prime[j] == 0){
				mu[i*prime[j]] = mu[i] / cnt[i] *(cnt[i]+1)&1;
				cnt[i*prime[j]] = cnt[i]+1;
				break;
			}
			mu[i*prime[j]] = mu[i]*mu[prime[j]];
			cnt[i*prime[j]] = 1;
		}
	}
}

ll modpow(ll b, ll e, int mod){
	ll ans = 1;
	while(e){
		if (e&1) ans = ans*b%mod;
		e >>= 1;
		b = b*b%mod;
	}
	return ans;
}

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

	sieve(MAXN);
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for (ll i = 1; i <= k; i++){
		ll innerans = 0;
		for (ll d = 1; d <= k/i; d++){
			innerans = (innerans + mu[d]*modpow(k/(i*d), n, MOD))%MOD;
		}
		ans = (ans+innerans*i%MOD)%MOD;
	}

	cout << ans << "\n";
}

Measured memory_bytes: 4604
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n) {
		vector<int>v(10, 0);
		int c;
		for (int i = 0; i < n; i++) {
			cin >> c;
			v[c]++;
		}
		for (int i = 0; i < 10; i++) {
			if (v[i]) {
				for (int j = 0; j < v[i]; j++) {
					cout << '*';
				}
				cout << endl;
			}
			else {
				cout << '-' << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
using namespace std;

typedef long long ll;
typedef pair<ll, ll> p;

ll f(string &t, int k){
	string s;
	for(int i=0; i<k; i++) s += t;
	ll ret = 0;
	for(int i=1; i<s.size(); i++){
		if(s[i-1] == s[i]){
			ret++; s[i] = '-';
		}
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; ll k;
	cin >> s >> k;
	
	if(k <= 4){
		cout << f(s, k); return 0;
	}
	
	ll a, b, c, d, e;
	a = f(s, 1); b = f(s, 2); c = f(s, 3); d = f(s, 4); e = f(s, 5);
	ll w = b - a;
	ll x = c - b;
	ll y = d - c;
	ll z = e - d;
 	
	if(w == 0 && x == 0){
		//cout << "HAWE";
		ll ans = a * k;
		cout << ans; return 0;
	}
	if(w == x && x == y && y == z){
		ll ans = 0;
		ans += a + w * (k-1);
		cout << ans; return 0;
	}
	if(w == y && x == z){
		ll ans = 0;
		ans += (b) * (k/2);
		if(k & 1) ans += a;
		cout << ans; return 0;
	}
	return 1;
}

Measured memory_bytes: 256
var input= require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");
var str="";
for(var i=0;i<Arr.length;i++){
var arr=Arr[i].split(" ");
var a=arr[0]-0;
var b=arr[1];
var c=arr[2]-0;
if(b==="?")break;
if(b==="+")str+=a+c;
if(b==="-")str+=a-c;
if(b==="*")str+=a*c;
if(b==="/")str+=Math.floor(a/c);
str+="\n";
}
console.log(str.trim());



Measured memory_bytes: 15360
#include <cstdio>

int main() {
  int a, b, c, d, e, f, sum = 0;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
  
  sum = a + (b * 5) + (c * 10) + (d * 50) + (e * 100) + (f * 500);
  
  if (sum >= 1000) {
    printf("1\n");
  }
  else {
    printf("0\n");
  }
  
  return 0;
  
}

Measured memory_bytes: 1012
N , K = list(map(int,input().split()))
li = list(map(int,input().split()))
typ = []
li.sort()
count = 0 
for i in range(N - 1): 
    count += 1
    if li[i] != li[i + 1]: 
        typ.append(count)
        count = 0 
if li[N - 1] != li[N - 2]: 
    typ.append(1)
else:
    typ.append(count + 1)
typ.sort()
count = 0 
if len(typ) > K:
    for i in range(len(typ) - K): 
        count += typ[i]
print(count)


Measured memory_bytes: 24836
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		int h[] = new int[n];
		for(int i=0; i<n; i++) {
			h[i]=sc.nextInt();
		}
		Arrays.sort(h);
		long c=0;
		for(int i=0; i<n-k; i++) {
			c+=h[i];
		}
		System.out.println(c);
		sc.close();
	}
}


Measured memory_bytes: 92852
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

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

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (auto &&i : A) {
        cin >> i;
    }
    for (auto &&i : B) {
        cin >> i;
    }
    priority_queue<int> que;
    vector<int> loss;
    int ans = 0;
    REP(i, N) {
        if (B[i] < A[i]) {
            que.push(A[i] - B[i]);
        } else if (A[i] < B[i]) {
            loss.push_back(B[i] - A[i]);
            ans++;
        }
    }
    int rem = 0;
    REP(i, loss.size()) {
        while (loss[i] != 0) {
            while (rem < loss[i]) {
                if (que.empty()) {
                    std::cout << -1 << '\n';
                    return 0;
                }
                rem += que.top();
                que.pop();
                ans++;
            }
            rem -= loss[i];
            loss[i] = 0;
        }
    }

    std::cout << ans << '\n';

    return 0;
}

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define se second
#define fi first
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef pair<double, double>  iidb;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(nodo*2)+1,mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define offset 3000
#define ptr nodo*
const ll MOD=1e9+7;

#define cmplog 20
#define tam 623400
using namespace std;
const ll inf=1e18;

int main()
{	
	ios::sync_with_stdio(false);cin.tie(0);
	int n;map<int,int> mapa;
	cin>>n;
	forr(i,0,n)
	{
		int valor;
		cin>>valor;
		mapa[valor]++;
	}	
	ll tot=0;
	for(auto par:mapa)
	{
		if (par.fi>par.se)
			tot+=par.se;
		else
			tot+=abs(par.fi-par.se);
	}
	cout<<tot<<endl;
}
// SMASH!!!!!

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

int main(){
        int n;cin>>n;
        int j=0;
        int cnt=1;
        cin >> j;
        int min=j;
        for(int i=1;i<n;i++){
                cin >> j;
                if(min>=j){cnt++;min=j;}
        }
        cout << cnt;
        return 0;
}

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

int main() {
	int X,A,B;
	cin >>X>>A>>B;
	int Y;
	Y = X - A;
	int i;
	i = Y/B;
	cout<<Y-i*B<<endl;



	
	return 0;
}

Measured memory_bytes: 256
// 6/26 解き直し
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

int main() {
    ll A, B;
    cin >> A >> B;

    ll d = gcd(A, B);

    // ll prime = 2;
    vector<int> primes;

    primes.push_back(1);

    for (int i = 2; i <= 1e6; i++) {
        if (d % i == 0) {
            primes.push_back(i);
        }
        while (d % i == 0) {
            d /= i;
        }
    }

    if (d != 1) {
        primes.push_back(d);
    }

    cout << primes.size() << endl;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int n;
    ll sum = 0;
    cin >> n;
    vector<int> a(n+1);
    REP(i,n+1){
        cin >> a[i];
        sum += a[i];
    }
    vector<int> b(n);
    REP(i,n) cin >> b[i];

    REP(i,n){
        if(a[i] < b[i]){
            a[i + 1] -= min(b[i] - a[i],a[i+1]);
        }
        a[i] -= min(a[i], b[i]);

    }

    ll rest = 0;
    REP(i, a.size()){
        rest += a[i];
    }

    cout << sum - rest << endl;

    return 0;
}

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

using namespace std;

int main()
{
    string s,r="";
    cin>>s;
    int ln=s.length();
    for(int i=ln-1;i>=0;i--)
        r+=s[i];

    if(s==r)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b))
    {
        if(a<=b)
            printf("%d\n",a);
        else
        {
            printf("%d\n",a-1);
        }
    }
    return 0;
}


Measured memory_bytes: 128
# https://atcoder.jp/contests/arc097/tasks/arc097_b
# Pについてp_xとp_yでuniteしていくと、スワップできる集合が獲得できる
# 1,2,3...i...Nにできるかだが, iについてp_iとiがスワップできるかはunion-findで探せばよい


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right


N, M = read_ints()
P = [p - 1 for p in read_ints()]
uf = UnionFind(N)
for _ in range(M):
    x, y = read_ints()
    uf.unite(P[x - 1], P[y - 1])

ans = 0
for i in range(N):
    ans += uf.is_in_same(i, P[i])

print(ans)


Measured memory_bytes: 14260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_N 10000000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int p[MAX_N+1], N;

int main(){
  p[0] = p[1] = 1;
  for(int i = 2; i < MAX_N / 2; i++){
    if(p[i]) continue;
    for(int j = i+i; j < MAX_N; j+=i) p[j] = 1;
  }

  while(scanf("%d", &N) && N){
    for(int x = N; x >= 13; x--){
      if(p[x] == 0 && p[x-2] == 0 && p[x-6] == 0 && p[x-8] == 0){
	printf("%d\n", x);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 40248
#include<stdio.h>
 
int main (){
  int x[5];
  int x_length = sizeof x / sizeof x[0];
  for(int i = 0;i < x_length;i++){
    scanf("%d",&x[i]);
  }
 
  for(int i = 0;i < x_length;i++){
    if(x[i] == 0){
      printf("%d",i+1);
    }
  }
  return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    vector<string> map(h);
    cinv(map,0,h);
    VEC2(used,h,w);

    ll res = 0;
    FOR(i,0,h){
      FOR(j,0,w){

        if(map[i][j]=='#' && used[i][j] == 0){
          queue<P> que;
          que.push(P(i,j));
          used[i][j]=1;
          ll black=0;
          ll white=0;
          while(!que.empty()){
            ll raw = que.front().first;
            ll clm = que.front().second;
            char x = map[raw][clm];
            que.pop();

            if(x == '.') white++;
            else if(x == '#') black++;

            if(raw-1>=0 && map[raw-1][clm] != x && used[raw-1][clm] == 0){
              que.push(P(raw-1,clm));
              used[raw-1][clm] = 1;
            }
            if(clm-1<w && map[raw][clm-1] != x && used[raw][clm-1] == 0){
              que.push(P(raw,clm-1));
              used[raw][clm-1] = 1;
            }
            if(raw+1<h && map[raw+1][clm] != x && used[raw+1][clm] == 0){
              que.push(P(raw+1,clm));
              used[raw+1][clm] = 1;
            }
            if(clm+1<w && map[raw][clm+1] != x && used[raw][clm+1] == 0){
              que.push(P(raw,clm+1));
              used[raw][clm+1] = 1;
            }

          }
          res += black*white;
          //cout<<black*white<<" "<<black<<" "<<white<<endl;
        }

      }
    }
    cout<<res<<endl;

}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
char s;
int a,b,c;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>s>>b>>s>>c;
	if (b<=4 && c<=30) cout<<"Heisei";
	else cout<<"TBD";
	return 0;
}

Measured memory_bytes: 256
def has_no2(s, digits):
    for ch in s:
        if ch in digits:
            return False
    return True

def main2():
    N, K = [int(x) for x in input().split()]
    digits = ''.join(input().split())

    for s in [str(i) for i in range(N, 100000)]:
        if has_no2(s, digits):
            print(s)
            break

main2()


Measured memory_bytes: 16012
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    long long x, y;
    cin >> x >> y;
    if (x % y == 0 || y == 1)
    {
        cout << "-1";
        return 0;
    }
    long long z = x;
    while (z % y == 0)
        z += x;
    cout << z;
    return 0;
}


Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main () {
	int n;
	cin >> n;
	vector<ll> p(n);
	ll a,b;
	
	ll sum = 0;
	rep(i, n) {
		cin >> a >> b;
		p[i] = a + b;
		sum -= b;
	}

	sort(all(p));

	int cnt = 0;
	for (int i = n - 1; i >=0; i--) {
		if (cnt % 2 == 0) sum += p[i];
		cnt++;
	}

	cout << sum << endl;
}


 

Measured memory_bytes: 1024
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


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

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){
	int N;
	cin >> N;
	int h[N];
	rep(i, N) cin >> h[i];

	int dp[N+2];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	dp[2] = abs(h[2] - h[0]);
	rep(i, N-2) {
		dp[i+2] = min(dp[i] + abs(h[i] - h[i+2]), dp[i+1] + abs(h[i+1] - h[i+2]));
	}
	cout << dp[N-1] << endl;


	return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

const int maxn=5e3+5;
vector<int> p(maxn+1,0);
vector<int> c(maxn,0);
// map<int,int> mp;
vector<int> vis(maxn,-1);
vector<pair<int,ll>> num;
void solve()
{
    int n,k;
    cin>>n>>k;
    for (int i = 1; i < n+1; i++)
    {
        cin>>p[i];
    }
    for (int i = 1; i < n+1; i++)
    {
        cin>>c[i];
    }
    
    ll ans=LLONG_MIN;

    for (int i = 1; i < n+1; i++)
    {
        for (int i = 1; i < n+1; i++)
        {
            vis[i]=-1;
        }
        
        // mp.clear();
        num.clear();
        ll mx=LLONG_MIN;
        num.eb(mk(i,0));
        int count=0;
        ll mpans=0;
        while(count<k)
        {
            pair<int,ll> last=num.back();
            int go=p[last.first];

            if(vis[go]!=-1)
            {
                int preind=vis[go];
                ll sm=num[preind-1].second; 
                if(last.second-sm<=0) {
                    count=k;
                    break;
                }
                int ind=num.size()-1 -(preind-1);
                int val=(k-count)/ind;
                if(val>0) val--;
                count+=ind*val;
                mpans+=val*(last.second-sm);
                mx=max(mx,mpans);
                break;
            }
            
            mpans+=c[go];
            mx=max(mx,mpans);
            vis[go]=num.size();
            num.eb(mk(go,mpans));
            count++;
        }

        while(count<k){
            pair<int,ll> last=num.back();
            int go=p[last.first];
            mpans+=c[go];
            mx=max(mx,mpans);
            num.eb(mk(go,mpans));
            count++;
        }

        ans=max(ans,mx);
    }
    
    cout<<ans;
}

int main()
{
    IOS;
    ll t=1;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3856
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

int main()
{
    int n;
    
    std::cin >> n; 
    
    std::cout << (int)std::exp2(std::floor(std::log2(n)));
    
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y){
	if(y == 0) return x;
	return gcd(y, x % y);
}

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

	ll a, b;
	cin >> a >> b;

	cout << a / gcd(a, b) * b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

int N, K;
//bool path[5010][5010];
vector<int> path[5010];
int C[5010];
int R[5010];
int cost[5010];
bool visited[5010];
queue<int> updates;

void bfs(int x) {
  //cout << "bfs("<<x<<")\n";
  int r = R[x];
  int v = cost[x] + C[x];
  for (int i=0; i<N; i++) visited[i] = false;
  visited[x] = true;
  queue<int> q;
  q.push(x);
  q.push(0);

  while (!q.empty()) {
    int s    = q.front(); q.pop();
    int dist = q.front(); q.pop();
    if (dist >= r) continue;

    //for (int d=0; d<N; d++) {
    for (auto d : path[s]) {
      //if (!visited[d] && path[s][d] && x != d) {
      if (!visited[d]) {
        q.push(d);
        q.push(dist+1);
        visited[d] = true;
        if (cost[d] == -1 || v < cost[d]) {
          cost[d] = v;
          updates.push(d);
        }
      }
    }
  }
}

int main() {
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    cin >> C[i] >> R[i];
    cost[i] = -1;
  }
  for (int i=0; i<K; i++) {
    int a, b;
    cin >> a >> b;
    //path[a-1][b-1] = true;
    //path[b-1][a-1] = true;
    path[a-1].push_back(b-1);
    path[b-1].push_back(a-1);
  }

  cost[0] = 0;
  updates.push(0);

  while (!updates.empty()) {
    int i = updates.front(); updates.pop();
    bfs(i);
  }
  cout << cost[N-1] << "\n";
  return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll K, ll S) {
  int res = 0;
  REP(i,K+1) REP(j,K+1) {
    int k = S - i - j;
    if (0 <= k && k <= K) ++res;
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll S;
	ll K;
	scanf("%lld", &K);
	scanf("%lld", &S);
	solve(K, S);
	return 0;
}


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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i, N) cin >> x[i];
    int ans = 1e9;
    rep(i, N - K + 1) {
        int l = x[i], r = x[i + K - 1];
        ans = min({ans, abs(l) + r - l, abs(r) + r - l});
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
s=input()
q=int(input())
l=""
r=""
flg=True

for i in range(q):
    p=list(map(str,input().split()))
    if p[0]=="1":
        flg=not flg
    else:
        z,f,c=p
        if f=="1":
            if flg:
                l=c+l
            else:
                r=r+c
        else:
            if not flg:
                l=c+l
            else:
                r=r+c
s=l+s+r

if flg:
    ans=s
else:
    ans=s[::-1]
print(ans)

Measured memory_bytes: 4668
def main():
    N, M, X, Y = map(int, input().split(" "))
    x = max(list(map(int, input().split(" "))))
    y = min(list(map(int, input().split(" "))))
    if X < x < y < Y:
        print("No War")
    else:
        print("War")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

// LazyUpdateSegmentTree
template<typename T>
class LazyUpdateSegTree{
public:
    int n;
    T defaultValue;
    vector<T> dat;
    vector<T> lazy;
    vector<bool> isSetLazy;

    LazyUpdateSegTree(vector<T>& v, T defaultValue){
        n = 1;
        int vSize = (int)v.size();
        while(n < vSize){
            n *= 2;
        }
        dat.assign(2 * n - 1, defaultValue);
        lazy.assign(2 * n - 1, 0);
        isSetLazy.assign(2 * n - 1, false);
        this->defaultValue = defaultValue;

        for(int i = 0; i < vSize; i++){
            dat[i + n - 1] = v[i];
        }
        for(int i = n - 2; i >= 0; i--){
            dat[i] = ope(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    T update(int a, int b, T value, int k = 0, int l = 0, int r = -1){
        if(r < 0){
            r = n;
        }
        propagate(k);

        if(r <= a || b <= l){
            return dat[k];
        }

        if(a <= l && r <= b){
            lazy[k] = lazyUpdate(value, l, r);
            isSetLazy[k] = true;
            propagate(k);
            return dat[k];
        }
        else{
            T vl = update(a, b, value, 2 * k + 1, l, (l + r) / 2);
            T vr = update(a, b, value, 2 * k + 2, (l + r) / 2, r);
            dat[k] = ope(vl, vr);
            return dat[k];
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0){
            r = n;
        }

        if(r <= a || b <= l){
            return defaultValue;
        }
        propagate(k);

        if(a <= l && r <= b){
            return dat[k];
        }
        else{
            T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return ope(vl, vr);
        }
    }

private:

    void propagate(int k){
        if(isSetLazy[k]){
            dat[k] = lazy[k];
            if(k <= n - 2){
                T value = lazyPropUpdate(lazy[k]);
                lazy[2 * k + 1] = value;
                lazy[2 * k + 2] = value;
                isSetLazy[2 * k + 1] = true;
                isSetLazy[2 * k + 2] = true;
            }

            isSetLazy[k] = false;
        }
    }

    T ope(T a, T b){
        return a + b;
    }

    T lazyUpdate(T value, int l, int r){
        return (r - l) * value;
    }

    T lazyPropUpdate(T value){
        return value / 2;
    }
};

int main(){

    int n, q;
    cin >> n >> q;
    vector<long long> v(n, 0);
    LazyUpdateSegTree<long long> segTree(v, 0);
    for(int i = 0; i < q; i++){
        int type;
        cin >> type;
        if(type == 0){
            int s, t, x;
            cin >> s >> t >> x;
            segTree.update(s, t + 1, x);
        }
        else{
            int s, t;
            cin >> s >> t;
            cout << segTree.query(s, t + 1) << endl;
        }
    }

    return 0;
}


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

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

int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	REP(i,n){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	int res=0;
	REP(i,n){
		res+=v[i];
	}
	bool dame = true;
	if(res%10==0){
		REP(i,n){
			if(v[i]%10 != 0){
				res-=v[i];
				dame=false;
				break;
			}
		}
	} else {
		dame = false;
	}
	if(dame){
		cout<<0<<endl;
	} else {
		cout<<res<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define FOR(a, b, c) for (int (a) = (b); (a) < (c); ++(a))
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))

int main() {
    ll t;
    cin >> t;
    ll five, hund; 
    hund = t / 500;
    five = (t % 500) / 5;
    cout << (hund * 1000) + (five * 5) << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long k = scan.nextLong();

		boolean flag = true;
		if ( n > k){
			long w = n / k;
			n = n - (k*w);
		}
		while(flag){
			long min = 0;
			if( n < k){
				min = k - n;
			}else{
				min = n -k;
			}
			if(n <= min){
				flag = false;
			}else{
				n =min;
			}
		}
		System.out.println(n);

	}
}

Measured memory_bytes: 23764
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def egcd(a: int, b: int):
    """
    A solution of ax+by=gcd(a,b). Returns
    (gcd(a,b), (x, y)).
    """
    if a == 0:
        return b, 0, 1
    else:
        g, x, y = egcd(b % a, a)
        return g, y - (b // a) * x, x


def modinv(a: int, mod: int = 10**9 + 7):
    """
    Returns a^{-1} modulo m.
    """
    g, x, y = egcd(a, mod)
    if g > 1:
        raise Exception('{}^(-1) mod {} does not exist.'.format(a, mod))
    else:
        return x % mod


def modpow(a: int, n: int, mod: int = 10**9 + 7):
    """
    Returns a^n mod m. (-inf < n < inf)
    """
    if a in [-1, 0, 1]:
        if a == -1:
            return 1 if n & 1 == 0 else mod - 1
        else:
            return a

    x, k = (a % mod, n) if n >= 0 else (modinv(a, mod), -n)

    ret = 1
    while k > 0:
        if k & 1 == 1:
            ret = ret * x % mod
        x = (x**2) % mod
        k = k >> 1

    return ret


def main():
    N = gete(int)

    d = dict()
    z = 0

    for _ in range(N):
        a, b = geta(int)
        if a == b == 0:
            z += 1
            continue

        if a != 0 and b != 0:
            g, _, _ = egcd(a, b)
            ai, bi = a // g, b // g
            c1 = (ai, bi) if ai > 0 else (-ai, -bi)
            c2 = (bi, -ai) if bi > 0 else (-bi, ai)
        elif a == 0:
            c1 = (0, 1)
            c2 = (1, 0)
        elif b == 0:
            c1 = (1, 0)
            c2 = (0, 1)

        if c1 in d:
            d[c1][0] += 1
        elif c2 in d:
            d[c2][1] += 1
        else:
            d[c1] = [1, 0]

    mod = 1000000007
    ans = 1
    for k in d:
        n = modpow(2, d[k][0], mod)
        m = modpow(2, d[k][1], mod)
        ans = ans * (n + m - 1) % mod

    ans = (ans + z - 1) % mod

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 137604
from itertools import permutations
def main():
    N = int( input())
    P = list( map( int, input().split()))
    Q = list( map( int, input().split()))
    Pem = list( map( lambda x: list(x), permutations( range(1, N+1))))

    M = 1
    for i in range(1, N+1):
        M *= i
    for i in range(M):
        if Pem[i] == P:
            p = i
        if Pem[i] == Q:
            q = i
    print( abs(p-q))
if __name__ == '__main__':
    main()


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  ll ans = 0, as = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') as++;
    else if (s[i] == 'B' && i+1 < s.size() && s[i+1] == 'C')
      ans += as, i++;
    else as = 0;
  }
  cout << ans << endl;
}


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

int main() {
	int h, w;
	cin >> h >> w;
	for(int i = 0; i < h; i++) {
		char c[101];
		scanf("%s", c);
		printf("%s\n", c);
		printf("%s\n", c);
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a + b + c >= 22)
	{
		printf("bust\n");
	}

	else
	{
		printf("win\n");
	}

	return 0;
}

Measured memory_bytes: 128
n,k = gets.chomp.split.map(&:to_i)
hs = gets.chomp.split.map(&:to_i)
dp = Array.new(n,10**18)
dp[0] = 0
(n-1).times do|i|
  1.upto(k) do |j|
    if i+j < n && dp[i+j] > dp[i] + (hs[i] - hs[i+j]).abs
      dp[i+j] = dp[i] + (hs[i] - hs[i+j]).abs
    end
  end
end
puts dp[n-1]

Measured memory_bytes: 9484
N = int(input())
A = list(map(int, input().split()))

trend = 0
groups = 1

for i in range(N-1):
  if trend * (A[i+1] - A[i]) < 0:
    trend = 0
    groups +=1
  elif trend == 0:
    trend = A[i+1] - A[i]
    
print(groups)

Measured memory_bytes: 14252
#include <stdio.h>

int main(void)
{
    int a, b, c, x;
    scanf("%d%d%d%d", &a, &b, &c, &x);

    int count = 0;
    int i, j, k;
    for (i = 0; i <= a; i++) {
        for (j = 0; j <= b; j++) {
            for (k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k == x)
                    count++;
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    int n, m;
    cin >> n >> m;
    VEC( int, n, pa, -1 );
    vector< vector<int> > edge(n);
    
    VEC( int, n, bb, 0 );
    REP( i, n - 1 + m )
    {
        int a, b;
        cin >> a >> b;
        edge[a-1].push_back( b-1 );
        bb[b-1]++;
    }

    stack<int> st;
    REP( i, n )
    {
        if( bb[i] > 0 ) continue;
        st.push( i );
        break;
    }

    vector<int> top;
    while( !st.empty() )
    {
        int i = st.top(); st.pop();
        top.push_back(i);
        for( const auto& v : edge[i] )
        {
            if( --bb[v] == 0 ) st.push( v );
        }
    }

    REP(i,n)
    {
        int t = top[i];
        if( i == 0 ) { pa[t] = -1; }
        for( const auto& v : edge[t] )
        {
            pa[v] = t;
        }
    }
    
    REP( i, n )
    {
        cout << pa[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 7544
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int add(int i, int j) {
    if((i += j) >= mod) i -= mod;
    return i;
}

int mult(int i, int j) {
    return (ll) i * j % mod;
}

int dp[100000][13];
string line;

int f(int i, int j) {
    if(i == line.size()) return j == 5;
    if(dp[i][j] > -1) return dp[i][j];
    if(line[i] != '?') return dp[i][j] = f(i + 1, (j * 10 + line[i] - '0') % 13);
    int mx = 0;
    for(int k = 0; k < 10; ++k)
        mx = add(mx, f(i + 1, (j * 10 + k) % 13));
    return dp[i][j] = mx;
}

int main() {
    cin >> line;
    memset(dp, -1, sizeof dp);
    cout << f(0, 0);
    return 0;
}

Measured memory_bytes: 13312
use std::io;
use std::io::BufRead;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n: usize = sc.next().unwrap();
    let mut a: Vec<i64> = vec![];

    let mut sum = 0;
    for i in 0..n {
        a.push(sc.next().unwrap());
        sum += a[i];
    }
    let mut res = std::i64::MAX;
    let mut t = 0;
    for i in 0..n - 1 {
        t += a[i];
        res = std::cmp::min(res, (sum - 2 * t).abs());
    }

    println!("{}", res);
}

/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next().unwrap());
/// assert_eq!(3.5, sc.next().unwrap());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


Measured memory_bytes: 15608
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    string S,T,a,b;
    string ans = "No";
    cin >> S >> T;
    rep(i,S.length()){
        a = S.substr(0, (unsigned)i);
        b = S.substr(i, S.length()-i);
        if(b+a == T) ans = "Yes";
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
sl s;
int n, a;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> a;
    if(s.find(a) == s.end()){
      s.insert(a);
    }else{
      s.erase(a);
    }
  }
  cout << sz(s) << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll n,m;
int main(){
    cin >> n >> m;
    ll ans;
    if(n == 1 && m == 1) ans = 1;
    else if(n == 1) ans = m - 2;
    else if(m == 1) ans = n - 2;
    else ans = (n-2)*(m-2);
    cout << ans << '\n';
}

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

struct Number
{
    public int x { get; set; }
    public bool f { get; set; }
    public Number(int x, bool f)
    {
        this.x = x;
        this.f = f;
    }
}

class Program
{
    static int n;
    static List<Number> a;
    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        a = new List<Number>();
        for (int i = 0; i < n; i++)
        {
            int ai = int.Parse(Console.ReadLine());
            a.Add(new Number(ai, i % 2 == 0));
        }
        a.Sort((p, q) => p.x - q.x);
        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i].f && i % 2 == 0)
                continue;
            if ((!a[i].f) && (!(i % 2 == 0)))
                continue;
            ans++;
        }
        ans /= 2;
        /*
        foreach (var x in a)
            Console.Write("{0} ",x.x);
        Console.WriteLine();
        */
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 19548
#include <stdio.h>

int main(){
	int a,b,c,tmp;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a > b ){
	  tmp=a;
	  a=b;
	  b=tmp;
	}
	if(b > c ){
	  tmp=b;
	  b=c;
	  c=tmp;
	}
    if(a > b ){ 
	  tmp=a;
	  a=b;
	  b=tmp;
    }
	 
	 printf("%d %d %d\n",a,b,c);
    
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	long long N,M;
	int flag=1;
	cin >>N;
	long long D[N];
	for(long long i=0; i<N; i++){
		cin>>D[i];
	}
	std::sort(D, D+N);
	
	cin>>M;
	long long T[M];
	for(long long i=0;i<M;i++){
		cin>>T[i];
	}
	sort(T, T+M);
	
	long long k=0;
	for(long long i=0; i<M; i++){
		if(D[k]>T[i]){flag=0;break;}
		
		if(D[k]<T[i]){k++; i--;}
		
		if(D[k]==T[i]){k++;}
	}
	
	if(flag==1){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int h,w;
    cin >> h >> w;

    vector<string> s(h);

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

    vector<vector<int>> numMine(h+2,vector<int>(w+2,0));

    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if(s[i][j]=='#'){
                for(int k=i-1; k<i+2; k++){
                    for (int l=j-1; l<j+2; l++){
                        if(numMine[k+1][l+1]!=-1){
                            numMine[k+1][l+1]++;
                        }
                    }
                }
                numMine[i+1][j+1]=-1;
            }
        }
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            if(numMine[i][j]>-1){
                cout << numMine[i][j];
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256