akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<pair<int,int> > a, b;
const int MAX_N=100000;
int par[MAX_N];  //親 **親を探すときはfind
int rank1[MAX_N]; //木の深さ
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        rank1[i] = 0;
    }
}
//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}
//併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(rank1[x]<rank1[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(rank1[x]==rank1[y]) rank1[x]++;
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}
int size(int x) {
        return -par[find(x)];
    }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    init(n);
    for (int i = 0; i < n; i++)
    {
        int tempa, tempb;
        cin >> tempa;
        a.push_back(make_pair(tempa,i));
    }
    for (int i = 0; i < n; i++)
    {
        int tempa;
        cin >> tempa;
        b.push_back(make_pair(tempa,i));
    }
    vector<pair<int,int> > a1, b1;
    a1=a;
    b1=b;
    sort(ALL(a));
    sort(ALL(b));
    ll count=0;
    for(int i=0;i<n;i++){
        unite(a[i].second,b[i].second);
        if(a[i].first>b[i].first){
            no;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(find(i)==i)count++;
    }
    if(count>1) return yes,0;
    for(int i=0;i<n-1;i++){
        if(a[i+1].first<=b[i].first&&a[i].first<=b[i+1].first) return yes,0;
    }
    no;
}


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

int main(){
    int i=0,count=0;
    char s[11]={},string[11]={};
    scanf("%s",s);
    while (s[i]!='\0') {
        if (s[i]=='0') {
            string[count]='0';
            count++;
        }else if(s[i]=='1'){
            string[count]='1';
            count++;
        }else if(s[i]=='B'){
            if (count!=0) {
                string[count-1]='\0';
                count--;
            }
        }
        i++;
    }
    printf("%s",string);
    return 0;
}


Measured memory_bytes: 128
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

int A, B, C;
int L[10];
int n;
int ans = 1e8;

void dfs(int current, int a, int b, int c, int cost) {
	if(a && b && c) ans = min(ans, cost + abs(A-a) + abs(B-b) + abs(C-c));
	if(current < n) {
		dfs(current+1, a+L[current], b, c, cost+10);
		dfs(current+1, a, b+L[current], c, cost+10);
		dfs(current+1, a, b, c+L[current], cost+10);
		dfs(current+1, a, b, c, cost);
	}
}

int main() {
	IOS
	cin >> n;
	cin >> A >> B >> C;
	for(int i=0; i<n; i++) cin >> L[i];
	dfs(0, 0, 0, 0, -30);
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
# abc107_c.py
# https://atcoder.jp/contests/abc107/tasks/arc101_a

# C - Candles /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 数直線上に N本のろうそくが置かれています。 
# 左から i 番目のろうそくは座標 xi に置かれています。 ただし、x1<x2<...<xNが成り立ちます。
# 最初、どのろうそくにも火が付いていません。 すぬけ君は、N本のうち K本のろうそくに火を付けることにしました。
# 今、すぬけ君は座標 0にいます。 すぬけ君は、数直線上を左右に速度 1で移動することができます。 
# また、自分と同じ座標のろうそくに火を付けることができます。 このとき、火を付けるのに掛かる時間は無視できます。
# K本のろうそくに火を付けるのに必要な最小の時間を求めてください。

# 制約
#     1≤N≤105
#     1≤K≤Nxiは整数である。
#     |xi|≤108x1<x2<...<xN

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N K
# x1 x2 ... xN

# 出力
# K本のろうそくに火を付けるのに必要な最小の時間を出力せよ。

# 入力例 1
# 5 3
# -30 -10 10 20 50

# 出力例 1
# 40

# 次のように移動しながらろうそくに火を付ければよいです。

#     座標 0から −10へ移動する。
#     左から 2番目のろうそくに火を付ける。
#     座標 −10から 10へ移動する。
#     左から 3番目のろうそくに火を付ける。
#     座標 10から 20へ移動する。
#     左から 4番目のろうそくに火を付ける。

# 入力例 2
# 3 2
# 10 20 30

# 出力例 2
# 20

# 入力例 3
# 1 1
# 0

# 出力例 3
# 0

# 座標 0にろうそくが置かれていることもあります。

# 入力例 4
# 8 5
# -9 -7 -4 -3 1 2 3 4

# 出力例 4
# 10


def calculation(lines):
    N, K = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # 取りうるパターン数
    P = N-K+1
    difs = list()
    for p in range(P):
        LL = values[p]
        r = values[K-1+p]
        rev = 0
        if LL*r < 0:
            rev = min(abs(LL), abs(r))
            dif = (r-LL) + rev
        else:
            dif = max(abs(r), abs(LL))
        difs.append(dif)
    return [min(difs)]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 3', '-30 -10 10 20 50']
        lines_export = [40]
    if pattern == 2:
        lines_input = ['3 2', '10 20 30']
        lines_export = [20]
    if pattern == 3:
        lines_input = ['1 1', '0']
        lines_export = [0]
    if pattern == 4:
        lines_input = ['8 5', '-9 -7 -4 -3 1 2 3 4']
        lines_export = [10]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 20960
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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


template <class T0, class T1>
class LazySegmentTree{
private:
    void eval(int k, int len){
        node[k] = g(node[k], p(lazy[k], len));

        if(len > 1){
            lazy[2 * k + 1] = f1(lazy[2 * k + 1], lazy[k]);
            lazy[2 * k + 2] = f1(lazy[2 * k + 2], lazy[k]);
        }
        lazy[k] = u1;
    }

    void update(int a, int b, T1 x, int k, int l, int r){
        eval(k, r - l);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] = f1(lazy[k], x);
            eval(k, r - l);
        }
        else{
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = f0(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    T0 query(int a, int b, int k, int l, int r){
        if (r <= a || b <= l){
            return u0;
        }
        eval(k, r - l);
        if (a <= l && r <= b){
            return node[k];
        }
        T0 vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T0 vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return f0(vl, vr);
    }


public:
    int sz;  // 元の配列サイズ
    int n;
    vector<T0> node;
    vector<T1> lazy;
    using F0 = function<T0(T0, T0)>; F0 f0; T0 u0;
    using F1 = function<T1(T1, T1)>; F1 f1; T1 u1;
    using G = function<T0(T0, T1)>;  G g;
    using P = function<T1(T1, int)>; P p;

    LazySegmentTree(vector<ll> v, F0 f0, T0 u0, F1 f1, T1 u1, G g, P p):
            sz(v.size()), f0(f0), u0(u0), f1(f1), u1(u1), g(g), p(p){
        int sz = v.size();
        n = 1;
        while(n < sz) n *= 2;
        node.resize(2*n-1, u0);
        lazy.resize(2*n-1, u1);

        for(int i = 0; i < sz; i++){
            node[i+n-1] = v[i];
        }
        for(int i = n-2; i >= 0; i--){
            node[i] = f0(node[i*2+1], node[i*2+2]);
        }
    }

    void update(int a, int b, T1 x){
        update(a, b, x, 0, 0, n);
    }

    void update(int a, T1 x){
        update(a, a+1, x);
    }

    T0 query(int a, int b){
        return query(a, b, 0, 0, n);
    }

    T0 query(int a){
        return query(a, a+1);
    }
};


int main(){
    int n, q;
    cin >> n >> q;

    LazySegmentTree<ll, ll> seg(
            vector<ll>(n, 0),
            [](ll x, ll y) { return x + y; }, 0,
            [](ll x, ll y) { return x + y; }, 0,
            [](ll x, ll y) { return x + y; },
            [](ll x, int len) { return x * len; }
    );
    for(int i = 0; i < q; i++){
        int ty, s, t, x;
        cin >> ty >> s >> t;
        s--;
        t--;
        if(ty == 0){
            cin >> x;
            seg.update(s, t+1, x);
        }
        else{
            cout << seg.query(s, t+1) << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 7612
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAX(a,b) (a>b?a:b)
using namespace std;

int main(){
  long int N, a[100001], b[100001];
  long long int Aall=0;
  cin >> N;
  rep(i, N){
    cin >> a[i];
    Aall += a[i];
  }
  long int cnt = Aall / (N*(N+1)/2);
  if(Aall%(N*(N+1)/2)){
      cout << "NO" << endl;
      return 0;
    }
  rep(i, N-1) b[i] = -1*(a[i+1] - a[i] - cnt);
  b[N-1] = -1*(a[0] - a[N-1] - cnt);
  bool flag = true;
  int nsum=0;
  rep(i, N){
    if(b[i]<0 || b[i]%N!=0){
      flag=false;
      break;
    } else nsum+=b[i]/N;
  }
  if(flag&&nsum==cnt) cout << "YES" << endl;
  else  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c) {
        cout << b + c << endl;
        return 0;
    } else if (a + b < c) {
        cout << a + b + 1 + b << endl;
        return 0;
    } else {
        cout << b + c << endl;
        return 0;
    }

}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

void append(string &t, char c) {
    if (c == 'S' && !t.empty() && t.back() == 'S') t.resize(t.size() - 1);
    else t += c;
}

int n;
const int maxn = 600000;
int ans[maxn];

void process(int b, int d3, int from, int to, const string &s) {
    if (b == n) {
        ans[from] = to;
        return;
    }
    vector<string> vs(3);
    int go[3];
    forn(i, 3) go[i] = i;
    for (char c: s) {
        if (c == 'S') forn(j, 3) {
            go[j] = (3 - go[j]) % 3;
            append(vs[j], c);
        } else forn(j, 3) {
            go[j] = (go[j] + 1) % 3;
            if (go[j] == 0) append(vs[j], c);
        }
    }
    forn(j, 3) process(b + 1, d3 * 3, from + d3 * j, to + d3 * go[j], vs[j]);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    string s;
    cin >> n >> s;
    process(0, 1, 0, 0, s);
    int d3 = 1;
    forn(i, n) d3 *= 3;
    forn(i, d3) cout << ans[i] << ' ';
    cout << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 6576
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
#define ofk order_of_key
#define fbo find_by_order
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class my>
using indexed_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

template <class my>
inline my aabs (const my &a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b, int m=mod) { return ( a + b ) % m;           }
inline int sub(const int &a, const int &b, int m=mod) { return ( a - b + m ) % m;       }
inline int mul(const int &a, const int &b, int m=mod) { return int ( 1LL * a * b % m ); }
inline int mpow(int a, int b, int m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
        b >>= 1;
    }
    return ans;
}

void tejas_919()
{
    lli n, k, m, q, u=0, v=0, temp=1, a, b, val=0;
    cin>>n; n++;
    lli arr[n+5], brr[n+5]={};
    fol(i,0,n) cin>>arr[i];
    fol(i,0,n-1) cin>>brr[i];
    fol(i,0,n-1)
    {
        val+=min(arr[i],brr[i]);
        u=brr[i]-min(arr[i],brr[i]);
        val+=min(arr[i+1],u);
        arr[i+1]-=min(arr[i+1],u);
    }
    cout<<val<<endl;
}

int main()
{
    fastio
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    while(t--)
        tejas_919();
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class C {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        double L;
        Input(out L);
        double r = L / 3;
        Print(r * r * r);
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void Inputs<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 11220
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    a+=b;
    a%=24;
    cout1(a)
}

Measured memory_bytes: 256
N = int(input())
S = input()
ww=0
ee=0
for i in S:
    if i=='E':
        ee+=1
res=[]
for i in S:
    if i=='E':
        ee-=1
    count=ww+ee
    res.append(count)
    if i=='W':
        ww+=1
print(min(res))

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int cnt[10][10];

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

  std::cin >> N;

  ll x = 0;

  for(int i=1;i<=N;++i){
      std::string s = std::to_string(i);

      cnt[s[0]-'0'][*s.rbegin()-'0'] += 1;
  }

  for(int i=1;i<=9;++i){
      for(int j=1;j<=9;++j){
          x += 1ll * cnt[i][j] * cnt[j][i];
      }
  }

  ll res = x;
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
/**
 * @Author: yujirotakahashi
 * @Date:   2020-05-17T20:21:41+09:00
 * @Last modified by:   yujirotakahashi
 * @Last modified time: 2020-05-25T03:33:07+09:00
 */

#include<bits/stdc++.h>
using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
using ll = long long;
using PAIR = pair<int, int>;
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/

/******** User-defined Function *******/
using Graph = vector<vector<int>>;
int dx[4] = {-1,0,0,1};
int dy[4] = {0,1,-1,0};
/**************************************/

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int q; cin >> q;

  int dp[1010][1010];
  rep(k,q){
      string x,y; cin >> x >> y;
      memset(dp, 0 ,sizeof(dp));

      dp[0][0] = 0;
      rep(i,x.size()){
          rep(j,y.size()){
              if(x[i]==y[j]){
                  chmax(dp[i+1][j+1],dp[i][j]+1);
              }else{
                  chmax(dp[i+1][j+1],dp[i+1][j]);
                  chmax(dp[i+1][j+1],dp[i][j+1]);
              }
          }
      }
      cout << dp[x.size()][y.size()] << endl;
  }

  return 0;
}
/********  Main() Ends Here *************/



Measured memory_bytes: 7220
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

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

	cout << min(A, B) << " " << max(0, A+B-N) << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vi v;
int cnt;

void solve(int lb, int ub, int k)
{
	while (ub-lb>1)
	{
		cnt++;
		int mid = (lb + ub) / 2;
		if (v[mid] == k) return;
		if (v[mid] > k) ub = mid;
		else lb = mid;
	}
}

int main()
{
	int n;
	while (cin >> n, n)
	{
		v.clear();
		cnt = 0;
		REP(i, n)
		{
			int a;
			cin >> a;
			v.push_back(a);
		}
		int k; cin >> k;
		solve(-1, n, k);
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

inline bool comp(string a, string b) {
    if (a.size() > b.size()) return 1;
    else if (b.size() > a.size()) return 0;
    if (a > b) return 1;
    else return 0;
}

int main(void){
    int w, h;
    while (cin>>w>>h && w) {
        vector<string> g(h);
        for (int i = 0; i < h; i++) {
            cin >> g[i];
        }
        
        vector<vector<string> > dp(h, vector<string>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (g[i][j] >= '0' && g[i][j] <= '9') dp[i][j] = g[i][j];
            }
        }
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (g[i][j] < '0' || g[i][j] > '9') continue;
                string a, b, c;
                a = dp[i][j];
                if (a == "0") continue;
                
                if (j+1 < w && g[i][j+1] >= '0' && g[i][j+1] <= '9') {
                    b = a + g[i][j+1];
                    if (comp(b,a) && comp(b, dp[i][j+1])) dp[i][j+1] = b;
                }
                
                if (i+1 < h && g[i+1][j] >= '0' && g[i+1][j] <= '9') {
                    c = a + g[i+1][j];
                    if (comp(c,a) && comp(c, dp[i+1][j])) dp[i+1][j] = c;
                }
            }
        }
        
        string ans;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (comp(dp[i][j], ans)) {
                    ans = dp[i][j];
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    vector<string> u(n);
    rep(i, n) cin >> u[i];

    int status = 0;
    int m; cin >> m;
    rep(i, m) {
        string s; cin >> s;
        if (count(all(u), s)) {
            if (status) cout << "Closed by "+s << endl;
            else cout << "Opened by "+s << endl;
            status ^= 1;
        } else {
            cout << "Unknown " + s << endl;
        }
    }
}


Measured memory_bytes: 3268
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i]) {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }
  prime.erase(remove(prime.begin(),prime.end(),0),prime.end());
  return prime;
}

int main() {
  vector<int> prime = sieve(10000);
  vector<P> v;
  for(int i=0; i<prime.size()-1; i++) {
    if(prime[i+1]-prime[i]==2) v.push_back(P(prime[i],prime[i+1]));
  }
  int n;
  while(cin >> n && n) {
    int l=0,r=v.size(),m;
    while(l+1!=r) {
      m = (l+r)/2;
      if(v[m].second>n) r=m;
      else l=m;
    }
    cout << v[l].first << " " << v[l].second << endl;
  }
  return 0;
}


Measured memory_bytes: 1240
#include <iostream>
#include <vector>
#include <string>
#include <bitset>

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  ll res = 0;
  for(int put_plus = 0; put_plus < ( 1 << (S.size() - 1) ); put_plus++) {

    ll acc = 0;

    for(int i = 0; i < (int)S.size(); i++) {
      acc *= 10;
      acc += (S[i] - '0');
      if( ( put_plus & (1 << i) ) != 0 ) {
        res += acc;
        acc = 0;
      }
    }
    res += acc;
  }

  cout << res;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int w, h, n;
char map[1024][1024];
int d[1024][1024];
const int direction[4][2] = {
	{ -1, 0 },
	{ 1, 0 },
	{ 0, -1 },
	{ 0, 1 },
};

int factory[16][2];
typedef pair<int, int> P;

int bfs(const int& sx, const int& sy, const int& gx, const int& gy)
{
	//memset(d, -1, sizeof(d));
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			d[j][i] = -1;
		}
	}
	queue<P> que;
	que.push(P(sx, sy));
	d[sx][sy] = 0;
	while (que.size())
	{
		const P p = que.front(); que.pop();
		// 如果是?点就?束
		if (p.first == gx && p.second == gy)
		{
			break;
		}

		// 四方向漫游
		for (int i = 0; i < 4; ++i)
		{
			int nx = p.first + direction[i][0];
			int ny = p.second + direction[i][1];
			// 是否可以移?，并且?点没有???
			if (0 <= nx && nx < w && 0 <= ny && ny < h && map[nx][ny] != 'X' && d[nx][ny] == -1)
			{
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}

	return d[gx][gy];
}

///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{

	cin >> h >> w >> n;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin >> map[j][i];
		}
	}

	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (map[j][i] == 'S')
			{
				factory[0][0] = j;
				factory[0][1] = i;
				map[j][i] = '.';
			}
			else if (isdigit(map[j][i]))
			{
				int index = map[j][i] - '0';
				factory[index][0] = j;
				factory[index][1] = i;
			}
		}
	}

	int step = 0;
	for (int i = 0; i < n; ++i)
	{
		
		step += bfs(factory[i][0], factory[i][1], factory[i + 1][0], factory[i + 1][1]);
	}

	cout << step << endl;

	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, h;
  cin >> n >> h;

  vector<ll> a(n);
  vector<ll> b(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());

  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    if (b[i] < a[0]) break;
    if (h <= 0) break;
    h -= b[i];
    ++ans;
  }

  if (h <= 0) {
    cout << ans << endl;
    return 0;
  }

  if (h%a[0] == 0) {
    ans += h / a[0];
  } else {
    ans += h / a[0] + 1;
  }

  cout << ans << endl;
  
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int max1 = 0;
    int max2 = 0;
    for (int i = 0; i < n; i++) {
        if (max1 <= a[i]) {
            max2 = max1;
            max1 = a[i];
        } else if (max2 < a[i]) {
            max2 = a[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == max1) {
            cout << max2 << endl;
        } else {
            cout << max1 << endl;
        }
    }
    return 0;
}

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

typedef long long arr[110000];

arr v, d, rev, pred, sufd, sufv, maxsuf, maxpre;
long long n, c;

int main() {
	cin >> n >> c;
	for (int i = 1; i <= n; i++)
		scanf("%lld%lld", &pred[i], &v[i]);
	for (int i = 1; i <= n; i++)
		rev[i] = rev[i - 1] + v[i];
	sufd[n] = c - pred[n];
	sufv[n] = v[n];
	for (int i = n - 1; i >= 1; i--) {
		sufd[i] = c - pred[i];
		sufv[i] = sufv[i + 1] + v[i]; 
	}
	for (int i = 1; i <= n; i++)
		if (rev[i] - pred[i] > maxpre[i - 1])
			maxpre[i] = rev[i] - pred[i];
		else maxpre[i] = maxpre[i - 1];
	maxsuf[n + 1] = 0;
	for (int i = n; i >= 1; i--)
		if (sufv[i] - sufd[i] > maxsuf[i + 1])
			maxsuf[i] = sufv[i] - sufd[i];
		else maxsuf[i] = maxsuf[i + 1];
//	for (int i = 1; i <= n; i++) {
//		cout << rev[i] << " " << pred[i] << " " << maxpre[i] << endl;
//	}
	long long ans = 0;
	ans = max(ans, max(maxsuf[1], maxpre[n]));
	for (int i = 1; i <= n; i++)
		ans = max(ans, max(rev[i] - pred[i] - pred[i] + maxsuf[i + 1], maxpre[i] + sufv[i + 1] - sufd[i + 1] - sufd[i + 1]));
	cout << ans;
	return 0;
}

Measured memory_bytes: 6912
import java.util.*;

public class Main {

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

    char[] c = new char[123];

    for (int i = 0; i < s.length(); i++) {
      int k = (int)s.charAt(i);
      c[k]++;
    }

    for (int i = 97; i < 123; i++) {
      if (c[i]%2 != 0) {
        System.out.println("No");
        return;
      }
    }

    System.out.println("Yes");

  }

}


Measured memory_bytes: 23252
/*input
4
20 11 9 24
*/

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int A = 0;
  rep(i, n) {
    cin >> a[i];
    A ^= a[i];
  }
  rep(i, n) cout << (A^a[i]) << " ";
  cout << endl;
}

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

int main()
{
    int L, R, d;
    cin >> L >> R >> d;

    int ans = 0;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

// BIT
// ※節点の番号は1-indで[1, n]とする
const int MAX_N = 500000;
int N;
vvi bit(26, vi(MAX_N + 1)); // 文字ごとのBIT26本

int sum(int c, int i) { // c番目のBITの番号の範囲[1, i]の節点の値の和
	int res = 0;
	while (i > 0) {
		res += bit.at(c).at(i);
		i -= i & -i;
	}
	return res;
}

void add(int c, int i, int x) { // c番目のBITの番号iの節点の値にxを加える
	while (i <= N) {
		bit.at(c).at(i) += x;
		i += i & -i;
	}
}
int main () {
	cin >> N;
	string S; cin >> S; // 0-ind
	rep(i, N) { // 0-ind
		int c = S.at(i) - 'a';
		// db(c); dbl(i);
		add(c, i + 1, 1); // 1-ind
		/*
		rep(c, 26) {
			cout << char('a' + c);
			rep(i, N) cout << bit.at(c).at(i) << " ";
			cout << endl;
		}
		*/
	}
	/*
	rep(c, 26) {
		cout << char('a' + c);
		rep(i, N) cout << bit.at(c).at(i) << " ";
		cout << endl;
	}
	*/
	int Q; cin >> Q;
	rep(i, Q) {
		int type; cin >> type;
		if (type == 2) { // 2の場合
			int l, r; cin >> l >> r;
			int ans = 0;			
			rep(c, 26) {
				if (sum(c, r) - sum(c, l - 1) > 0) {
					ans++;
				}
			}
			cout << ans << endl;
		} else if (type == 1) { // 1の場合
			int i; char cq; cin >> i >> cq;
			
			char ci = S.at(i - 1);
			S.at(i - 1) = cq; // 文字列更新
			add(ci - 'a', i, -1);
			add(cq - 'a', i, 1);

			//  db(S);
			/*
			rep(c, 26) {
				cout << char('a' + c);
				rep(i, N) cout << bit.at(c).at(i) << " ";
				cout << endl;
			}
			*/
		}
	}	
}

Measured memory_bytes: 54236
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
if a[0] - a[1] == b[0] - b[1] == c[0] - c[1] and a[2] - a[1] == b[2] - b[1] == c[2] - c[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val X, Y = sc.nextInt()
  val price = (i: Int) => i match {
    case 1 => 300000
    case 2 => 200000
    case 3 => 100000
    case _ => 0
  }
  val championPrice = if (X == 1 && Y == 1) 400000 else 0
  println(championPrice + price(X) + price(Y))
}


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

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const long long int INF=0x3f3f3f3f3f;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

int main()
{
	vivek_ghosh;
	
	cin>>n;
	
	ll a[n];

	mn=-1;
	mx=-1;
	cnt=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		mx=max(mx,a[i]);
	}
	
	for(ll i=0;i<n;i++)
	{
		if(a[i]<mx)
		{
			mn=max(a[i],mn);
		}
		else if(a[i] == mx)
		{
			cnt++;
			if(cnt==2)
				mn=max(mx,mn);
		}
	}
	
	if(mn == -1)
		mn=mx;
		
	for(i=0;i<n;i++)
	{
		if(a[i] == mx)
			cout<<mn<<endl;
		else
			cout<<mx<<endl;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}








Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
#include <set>

int main(void){
    Cin(int, n);
    Cins(int, n, p);
    
    vc<int> llb(n+1, -1), lb(n+1, -1), ub(n+1, n), uub(n+1, n), ind(n+1, -1);
    {
        For(i, n) ind[p[i]] = i;
        set<int> s;
        for(int e = n; e > 0; e --){
            int i = ind[e];
            auto itr = s.upper_bound(i);
            if(itr != s.end()){
                ub[e] = *itr;
                auto jtr = itr;
                jtr ++;
                if(jtr != s.end()) uub[e] = *jtr;
            }
            if(itr != s.begin()){
                itr --;
                lb[e] = *itr;
                if(itr != s.begin()){
                    itr --;
                    llb[e] = *itr;
                }
            }
            s.insert(i);
        }
    }
    /*Couts(p);
    Couts(llb);
    Couts(lb);
    Couts(ub);
    Couts(uub);*/
    
    ll ans = 0;
    for(int e = 1; e <= n; e ++){
        // Cout(e, " : ", llb[e], " ", lb[e], " ", ub[e], " ", uub[e]);
        ans += (ll)e * ((ll)(uub[e]-ub[e])*(ind[e]-lb[e]) + (ll)(ub[e]-ind[e])*(lb[e]-llb[e]));
        // Cout((uub[e]-ub[e])*(ind[e]-lb[e]), " ", (ub[e]-ind[e])*(lb[e]-llb[e]));
    }
    Cout(ans);
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
void read (int &x) {
	char ch = getchar(); int f = 0; x = 0;
	while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2e5 + 10;
int a[N], b[N];
signed main() {
	int n; scanf ("%d", &n);
	for (int i = 1; i <= n; ++i) 
		scanf ("%d %d", a + i, b + i);
	sort (a + 1, a + n + 1); sort (b + 1, b + n + 1);
	if (n & 1) {
		int t = (n + 1) / 2;
		printf ("%d\n", b[t] - a[t] + 1);
	} else {
		int t = n / 2;
		printf ("%d\n", b[t] + b[t + 1] - a[t] - a[t + 1] + 1);
	} return 0;
}

Measured memory_bytes: 5352
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  string bw;
  cin>>bw;
  ll cntb=0,res=0;
  for(char c:bw)
  {
    if(c=='B')
    {
      cntb++;
    }
    else if(c=='W')
    {
      res+=cntb;
    }
  }
  cout<<res<<endl;
  return 0;

}


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

int main() {
  long long x,y;
  cin >> x >> y;
  
  int ans = 0;
  
  long long z = y/x;
  while(z>0){
    ++ans;
    z /= 2;
  }
  
  cout << ans << endl;
}

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

const int N = 2e5;
const int INF = 1e9;
typedef pair<int, int> P;

struct edge{ int to,cost; };
vector< edge > G[N];

void dikstra(int s,int V){
  priority_queue<P,vector<P>,greater<P>> que;
  int d[N]; //sからの最短距離
  fill(d,d+N,INF);
  d[s] = 0;
  que.push({0,s});

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }

  for(int i = 0; i < V; i++){
    if(d[i] >= INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }
}

signed main(){

  int V,E,r; cin >> V >> E >> r;
  for(int i = 0; i < E; i++){
    int s,t,c; cin >> s >> t >> c;
    G[s].push_back({t,c});
  }

  dikstra(r,V);

  return 0;
}



Measured memory_bytes: 22640
import java.util.Scanner;


public class Main{    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i=1;
                
        while(true){
            int a=sc.nextInt();
            if(a==0){
                break;
            }
            System.out.println("Case "+ i+": " +a);
            i++;
        }
    }
}


Measured memory_bytes: 42768
fun main(args: Array<String>) {
    val mod = 1000000007
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(" ").map(String::toInt).toList()
    val m : MutableMap<Int, Int> = mutableMapOf()
    for ( i in l ) {
        m[i] = if (m[i] != null) m[i]!!+1 else 1
    }
    var cur = if (n % 2 == 0) 1 else 0
    var ok = true
    while(cur < n) {
        val x = if (cur == 0) 1 else 2
        if (m[cur] == null || m[cur] != x) {
            ok = false
            break
        }
        cur += 2
    }
    var ans = 0
    if (ok) {
        ans = 1
        for (i in 1..n/2) ans = ans * 2 % mod
    }
    println(ans)
}

Measured memory_bytes: 58836
n, m = gets.split.map(&:to_i)

k = [0]
s = [0]

1.upto(m) do |i|
  tmp = gets.strip.split.map(&:to_i)
  k << tmp[0]
  s << tmp[1..-1]
end

p = [nil] + gets.strip.split.map(&:to_i)

ans = 0

[0, 1].repeated_permutation(n) do |swich|
  swich.unshift nil
  ok = true
  1.upto(m) do |i|
    sum = 0
    1.upto(swich.size) do |j|
      sum += swich[j] if s[i].include?(j)
    end
    unless sum % 2 == p[i]
      break ok = false
    end
  end
  ans +=1 if ok ==true
end
puts ans


Measured memory_bytes: 14500
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
void dprintf(const char *format, ...) {
  va_list arg;
  va_start (arg, format);
  vfprintf(stderr, format, arg);
  va_end(arg);
}
#define debug(arg) cerr << #arg << " = " << arg << endl;
#else
#define dprintf(...)
#define debug(x)
#endif
using ll = long long;



const int MOD = 1e9 + 7;
const int MAX_N = 10000;
const int MAX_D = 100;

int Count[2][MAX_N + 1][1 + MAX_D];

void addSelf(int &a, int b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int main() {
  string K;
  cin >> K;
  reverse(K.begin(), K.end());
  for (char &c : K) {
    c -= '0';
  }
  int D;
  cin >> D;
  Count[true][0][0] = 1;
  for (int i = 0; i < (int)K.size(); i++) {
    for (int d = 0; d <= D; d++) {
      for (int digit = 0; digit <= 9; digit++) {
        for (bool leq : {true, false}) {
          bool LEQ = (digit < K[i] || (digit == K[i] && leq));
          addSelf(Count[LEQ][i + 1][(d + digit) % D], Count[leq][i][d]);
        }
      }
    }
    //printf("%d %d\n", Count[true][i][0], Count[false][i][0]);
  }
  int answer = (Count[true][(int)K.size()][0] - 1 + MOD) % MOD;
  printf("%d\n", answer);
  return 0;
}


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

using namespace std;

int h, w, k, ans;
string c[6];

int main()
{
    cin >> h >> w >> k;
    for(int i = 0; i<h; i++)
        cin >> c[i];
    for(int i = 0; i<(1<<h); i++)
        for(int j = 0; j<(1<<w); j++)
        {
            int cnt = 0;
            for(int k = 0; k<h; k++)
                for(int l = 0; l<w; l++)
                    if((c[k][l]=='#')&&(!(i&(1<<k)))&&(!(j&(1<<l))))
                        cnt++;
            if(cnt==k)
                ans++;
        }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b;
  cin >> a >> b;
  vector<int> e;
  e.push_back(a+b);
  e.push_back(a-b);
  e.push_back(a*b);
  sort(all(e));
  cout << e[2] << endl;
}


Measured memory_bytes: 256