akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     int ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/





vector<int> adj[100005];
int dist1[100005];
int dist2[100005];
void dfs(int node,int par,int dist1[]){
     for(int child:adj[node]){
          if(child==par)continue;
          dist1[child]=dist1[node]+1;
          dfs(child,node,dist1);
     }
}
int main(){
     int n;
     cin>>n;
     int t,a;
     cin>>t>>a;
     for(int i=1;i<n;i++){
          int a,b;
          cin>>a>>b;
          adj[a].pb(b);adj[b].pb(a);
     }
     dist1[t]=0;
     dfs(t,-1,dist1);
     dist2[a]=0;
     dfs(a,-1,dist2);
     int res=0;
     for(int i=1;i<=n;i++){
          if(dist1[i]<dist2[i]){
              // cout<<i<<"\n";
               res=max(dist2[i]-1,res);
          }
     }
     cout<<res;

}















































Measured memory_bytes: 14756
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int n;
    string s;
    int cnt=0;
    cin>>n>>s;
    rep(i,1000){
        bool a=0,b=0,c=0;
        rep(j,n){
            if(!a&&s[j]-'0'==i/100)a=true;
            else if(a^b&&s[j]-'0'==(i/10)%10)b=true;
            else if(b&&s[j]-'0'==i%10)c=true;
            if(c){
                ++cnt;
                break;
            }
        }
    }
    cout<<cnt<<"\n";
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 384
def main():
    import sys
    input = lambda : sys.stdin.readline().rstrip()
    sys.setrecursionlimit(max(1000, 10**9))
    write = lambda x: sys.stdout.write(x+"\n")


    ### 木の読み込み tree

    # サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
    from collections import defaultdict
    # import numpy as np
    # from numba import njit
    n = int(input())
    ns = defaultdict(set)
    for _ in range(n-1):
        u,v = map(int, input().split())
        u -= 1
        v -= 1
        ns[u].add(v)
        ns[v].add(u)


    # 再帰を用いないver.
    def dfs(start):
        q = [start]
        # 行きがけ順
        seen = [None]*n
        # 帰りがけ順
        done = [None]*n
        parent = [None]*n
        parent[start] = -1
        d0 = 0
        d1 = n
        while q:
            u = q.pop()
            if u>=0:
                if seen[u] is not None:
                    continue
                seen[u] = d0
                d0 += 1
                q.append(~u)
                for v in ns[u]:
                    if seen[v] is None:
                        q.append(v)
                        parent[v] = u
            else:
                d1 -= 1
                done[~u] = d1
        return seen, done, parent
    seen, done, parent = dfs(0)
    done = [(u,d) for u,d in enumerate(done)]
    done.sort(key = lambda x: -x[1])
    bs = {}
    for u,_ in done:
        val = 1
        p = parent[u]
        for v in ns[u]:
            if v!=p:
                val += bs[u,v]
        bs[p,u] = val

    bs[0,-1] = 0
    for u,_ in reversed(done):
        p = parent[u]
        for v in ns[u]:
            if v==p:
                continue
            b1 = bs[p,u]
            b2 = bs[u,v]
            b3 = bs[u,p]
            # 逆向き枝の計算
            bb = b1 - b2 + b3
            bs[v,u] = bb

    M = 10**9 + 7
    p1 = pow(2, n-1, M)
    p2 = pow(2, n, M)
    p3 = pow(p2, M-2, M)
    ans = 0
    for u in range(n):
        s = 0
        for v in ns[u]:
            s += pow(2, bs[u,v], M) - 1
            s %= M
        val = p1 - s - 1
        ans += val
        ans %= M
    ans *= p3
    ans %= M
    print(ans%M)
main()

Measured memory_bytes: 256052
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

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

signed main() {
	IOS();
	ll k, t;
	cin >> k >> t;
	ll M = 0;
	for (int i = 0; i < t; i++) {
		ll a;
		cin >> a;
		M = max(M, a);
	}
	ll ans = max(M - (k - M) - 1, 0ll);
	dump(ans);
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using vi = vector<Int>;
const Int INF = 1e18;
Int f(vi X0, vi Y0, vi X1, vi Y1) { // 0:U, 1:R
    map<Int, set<Int>> M;
    Int ans = INF;
    for (int i = 0; i < X0.size(); i++) {
        M[X0[i] + Y0[i]].insert(X0[i]);
    }
    for (int i = 0; i < X1.size(); i++) {
        auto& s = M[X1[i] + Y1[i]];
        auto it = s.lower_bound(X1[i]);
        if (it == end(s)) continue;
        ans = min(ans, (*it - X1[i]) * 10);
    }
    return ans;
}
Int g(vi X0, vi Y0, vi X1, vi Y1) { // 0:U, 1:D
    map<Int, set<Int>> M;
    Int ans = INF;
    for (int i = 0; i < X1.size(); i++) {
        M[X1[i]].insert(Y1[i]);
    }
    for (int i = 0; i < X0.size(); i++) {
        auto& s = M[X0[i]];
        auto it = s.lower_bound(Y0[i]);
        if (it == end(s)) continue;
        ans = min(ans, (*it - Y0[i]) * 5);
    }
    return ans;
}
vector<Int> X[4], Y[4];
int d2i(char u) {
    static const char A[] = "URDL";
    return find(begin(A), end(A), u) - begin(A);
}
void rot(int cnt) {
    if (cnt < 0) cnt = 4 + cnt;
    if (cnt == 0) return;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < X[i].size(); j++) {
            auto x = X[i][j];
            auto y = Y[i][j];
            X[i][j] = -y;
            Y[i][j] = x;
        }
    }
    rot(cnt - 1);
}
int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        Int x, y; char u;
        cin >> x >> y >> u;
        X[d2i(u)].push_back(x);
        Y[d2i(u)].push_back(y);
    }
    Int ans = INF;
    for (int i = 0; i < 4; i++) {
        rot(i);
        Int t = f(X[i], Y[i], X[(i+1)%4], Y[(i+1)%4]);
        ans = min(ans, t);
        rot(-i);
    }
    for (int i = 0; i < 2; i++) {
        rot(i);
        Int t = g(X[i], Y[i], X[i+2], Y[i+2]);
        ans = min(ans, t);
        rot(-i);
    }
    cout << (ans == INF ? "SAFE" : to_string(ans)) << endl;
    return 0;
}


Measured memory_bytes: 37216
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#include <cstdint>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n;
typedef std::pair<long, long> P;

P kth_range(long k, std::vector<P> vec){
    P ret(LINF, 0);
    long l = 0, r = 0;
    for(int i = 0; i < vec.size()-1; i++){
        long flag = vec[i].second;
        if(flag == 0){
            l++;
        }else{
            r++;
        }
        if(l >= k && r < k){
            ret.first = std::min(ret.first, vec[i].first);
            ret.second = std::max(ret.second, vec[i+1].first);
        }
    }
    //printf("  %ld %ld\n", ret.first, ret.second);
    return ret;
}

long divCeil(long a, long b){
    return (a-1)/b+1;
}

int main(){
    scanf("%ld", &n);
    std::vector<P> point(n*2);
    for(int i = 0; i < n; i++){
        long a, b;
        scanf("%ld%ld", &a, &b);
        point[i*2] = P(a, 0);
        point[i*2+1] = P(b+1, 1);
    }
    std::sort(point.begin(), point.end());
    /*
    for(int i = 0; i < point.size(); i++){
        printf("%ld %ld\n", point[i].first, point[i].second);
    }
    //*/
    if(n % 2 == 1){
        P ans = kth_range(n/2+1, point);
        //printf("%ld %ld\n", ans.first, ans.second);
        printf("%ld\n", ans.second - ans.first);
    }else{
        P l = kth_range(n/2, point);
        P r = kth_range(n/2+1, point);
        long med_r = l.second + r.second-1;
        long med_l = l.first + r.first;
        printf("%ld\n", med_r - med_l);
    }
}


Measured memory_bytes: 15744
#![allow(non_snake_case, unused_variables, unused_mut, dead_code)]
//use permutohedron::LexicalPermutation as _;
//use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    proconio::input! {
        N:i32
    }
    let ans = (N + 1) / 2;
    println!("{}", ans);
}


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

int main() {
    int N;
    int d[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    int num[110] = {0};  // バケット
    for (int i = 0; i < N; ++i) {
        num[d[i]]++;  // d[i] が 1 個増える
    }

    int res = 0;  // 答えを格納
    for (int i = 1; i <= 100; ++i) {  // 1 <= d[i] <= 100 なので 1 から 100 まで探索
        if (num[i]) {  // 0 より大きかったら
            ++res;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int n;
    cin >>n;
    vl a(n);
    rep(i,n) cin >> a[i];

    ll ans = 0;
    int tmp = a[0];
    rep(i,n-1){
        if(tmp > a[i+1]){
            ans += (tmp-a[i+1]);
        }else{
            tmp = a[i+1];
        }
    }

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

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

#define int long long

#define MOD 1000000007

int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}

signed main(){
	int n, m;
	cin >> n >> m;
	cout << pow_mod(n, m) << endl;
	return 0;
}



Measured memory_bytes: 3112
#include <stdio.h>
int main(){
  int h,w,i;
  scanf("%d%d",&h,&w);
  char c[101][101];
  for(i=0;i<h;i++)scanf("%s",c[i]);
  for(i=0;i<h*2;i++)printf("%s\n",c[i/2]);
  return 0;
}

Measured memory_bytes: 128
N, M= map(int, input().split())

C = map(int, input().split())

A = list(C)

#if N < M:
#    print('No')
#if M == 0:
#    print('No')

B = []
for i in range(len(A)):
    if A[i] >= sum(A)/4/M:
        B.append(1)
    else:
        B.append(0)

if sum(B) >= M:
    print('Yes')
else:
    print('No')


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

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::{input, marker::{Isize1, Usize1, Bytes, Chars}};

//#[proconio::fastout]
fn main() {
    input!(
        n: usize,
        s: Chars,
    );
    let s: Vec<_> = s.into_iter().map(|d| if d == 'E' { 0 } else { 1 }).collect();
    let mut scan = Vec::with_capacity(n);
    scan.push(s.iter().copied().skip(1).filter(|&d| d == 0).count() as i64);
    let mut pres = scan[0];
    for w in s.windows(2) {
        let (curr, next) = (w[0], w[1]);
        pres += curr + next - 1;
        scan.push(pres);
    }
    println!("{}", scan.iter().min().unwrap());
}


Measured memory_bytes: 6928
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ETozanAndGezan solver = new ETozanAndGezan();
        solver.solve(1, in, out);
        out.close();
    }

    static class ETozanAndGezan {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            long[] b = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                b[i] = in.nextLong();
            }

            long answer = solve(a, b);

            out.println(answer);
        }

        long solve(long[] a, long[] b) {
            int n = a.length;
            long answer = 0;

            long minB = Long.MAX_VALUE;
            boolean equal = true;

            for (int i = 0; i < n; i++) {
                answer += a[i]; // either one just want total sum

                if (a[i] > b[i]) {
                    minB = Math.min(minB, b[i]);
                    equal = false;
                }
            }

            return equal ? 0 : answer - minB;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



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

#define FOR(i,N) for(int i=0;i<N;i++)

int main(){
    long long N,H,W,Q,M=0,cnt=0,max=0,sum=0;
    cin >> N;
    vector<long>A(N,0),cnta(N,0);
    FOR(i,N){
        cin >> A[i];
        cnta[A[i]-1]++;
    }
    FOR(i,N){
        if(cnta[i]>1)max += cnta[i]*(cnta[i]-1)/2;
    }
    FOR(i,N){
        cnt = max;
        if(cnta[A[i]-1]>1){
            cnt += ((cnta[A[i]-1]-1)*(cnta[A[i]-1]-2)/2) - (cnta[A[i]-1]*(cnta[A[i]-1]-1)/2);
        }
        cout << cnt << endl;
    }
}

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

class Max_and_Min_and_Sum
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        List<long> list = new List<long>(n);

        string[] s = Console.ReadLine().Split();

        List<string> stringList = new List<string>();
        stringList.AddRange(s);

        list = stringList.ConvertAll(x => long.Parse(x));

        Console.WriteLine("{0} {1} {2}", list.Min(),list.Max(),list.Sum());
    }
}



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

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

int main() {
    char a;
    cin >> a;

    if (isupper(a)) {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
// ABC095 - C
function main(input) {
  var inputs = input.split('\n');
  var line1 = inputs[0].split(' ').map(x => parseInt(x, 10));
  var a = line1[0];
  var b = line1[1];
  var ab = line1[2];
  var x = line1[3];
  var y = line1[4];

  var cost = 0;
  if (a + b > ab * 2) {
    cost += ab * 2 * Math.min(x, y);
    if (x > y) {
      cost += (x - y) * (a > ab * 2 ? ab * 2 : a);
    }
    if (y > x) {
      cost += (y - x) * (b > ab * 2 ? ab * 2 : b);
    }
  } else {
    cost += a * x + b * y;
  }
  console.log(cost);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

static const int INFTY = (1 << 21);
char s[30][30];

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        continue;
      }
      int d[h][w];
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          d[k][l] = INFTY;
        }
      }
      queue<pair<int, int> > q;
      q.push(make_pair(i, j));
      d[i][j] = 0;
      while (!q.empty()) {
        pair<int, int> u = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          if (s[u.first + dx[k]][u.second + dy[k]] == '#') continue;
          if (d[u.first + dx[k]][u.second + dy[k]] != INFTY) continue;
          if (u.first + dx[k] < 0 || u.first + dx[k] >= h) continue;
          if (u.second + dy[k] < 0 || u.second + dy[k] >= w) continue;
          d[u.first + dx[k]][u.second + dy[k]] = d[u.first][u.second] + 1;
          q.push(make_pair(u.first + dx[k], u.second + dy[k]));
        }
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (s[k][l] == '.' && d[k][l] > ans) {
            ans = d[k][l];
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();

		//int digits = String.valueOf(n).length();

		int sum = 0;

		int m = n;
		while (m > 0) {
		    sum += m % 10;
		    m /= 10;
		}

		if(n % sum == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int n;
char s[MAXN];
bool h[30];
bool vis[30];
int ans;
int main() {
    scanf("%d %s", &n, s + 1);
    int cnt = 0;
    for(int i = 1; i < n; i++)
    {
        memset(h, false, sizeof(h));
        memset(vis, false, sizeof(vis));
        cnt = 0;
        for(int j = 1; j <= n; j++)
        {
            if(j <= i)
            {
                h[s[j] - 'a'] = true;
            }
            else if(j > i)
            {
                if(h[s[j] - 'a'] == true && !vis[s[j] - 'a'])
                {
                    cnt++;
                    vis[s[j] - 'a'] = true;
                }
            }
        }
        ans = max(ans, cnt);
    }
    printf("%d\n", ans);
}




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

using namespace std;

int main() {
#ifdef FLOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	int n = s.size();
	vector<int> a;
	for (int i = 0; i < n; i++)
		if (s[i] != 'x')
			a.push_back(i);
	int m = a.size();
	for (int i = 0; i < m; i++) 
		if (s[a[i]] != s[a[m - 1 - i]]) {
			cout << -1;
			return 0;
		}
	if (a.empty()) {
		cout << 0;
		return 0;
	}
	int ans = abs(a[0] - (n - 1 - a[m - 1]));
	for (int i = 0; i < m / 2; i++)
		ans += abs((a[i + 1] - a[i]) - (a[m - 1 - i] - a[m - 2 - i]));
	cout << ans;	
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,k,fact[100010],ans,mod=7+1e9;

ll expBin(ll x,ll y){
    if(!y) return 1LL;
    ll myAns = expBin(x,y/2);
    myAns = (myAns*myAns)%mod;
    if( y&1 ) myAns=(myAns*x)%mod;
    return myAns%mod;
}

ll coeff(ll N,ll K){
    if( K>N || K<0) return 0;
    ll myAns = fact[N]*expBin(fact[K],mod-2);
    myAns%=mod;
    myAns*=expBin(fact[N-K],mod-2);
    return myAns%mod;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    fact[0]=1;
    for(ll i=1; i<=100000; i++) fact[i]=(fact[i-1]*i)%mod;

    for(ll i=1; i<=k; i++){
        ll s1 = coeff(k-1,i-1);
        ll s2 = coeff(n-k+1,i);
        //cout << s1 << " " << s2 << " ";
        s1*=s2;
        s1%=mod;
        cout << s1 << "\n";
    }


    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#define mod 1000000007
using namespace std;

int frc[1000];

int main()
{
    string s;
    int ans = 1, n;
    cin >> n >> s;

    for (auto i : s)
        frc[i]++;

    for (int i = 'a'; i <= 'z'; i++)
        ans = 1LL * ans * (frc[i] + 1) % mod;
    ans = (ans - 1 + mod) % mod;

    cout << ans << '\n';

    return 0;
}


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

using ll = long long;
using pll = pair<ll, ll>;

ll dp[101][305];

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> wv(N), vv(N);
    int ws = 0, sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> wv[i] >> vv[i];
        if(i == 0) ws = wv[i];
        wv[i] -= ws;
        sum += wv[i];
    }

    for(int i = 0; i < N; i++) {
        for(int j = i; j >= 0; j--) {
            for(int k = sum; k >= 0; k--) {
                dp[j+1][k+wv[i]] = max(dp[j+1][k+wv[i]], dp[j][k] + vv[i]);
            }
        }
    }

    ll ans = -(1<<30);
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= sum; j++) {
            ll x = (ll)ws * i + j;
            if(x <= W) {
                ans = max(ans, dp[i][j]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include <cmath>
using namespace std;
string a, b, c;
int main() {
    cin >> a >> b >> c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc114b()
}

fun abc114b() {
    val s = readLine()!!

    val absTo753 = (0..(s.length - 3))
        .map { Math.abs(s.substring(it..it + 2).toInt() - 753) }

    println(absTo753.min())
}


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

using namespace std;

using ll = long long;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    if(s.size()==2){
        if(s.at(0)==s.at(1)){
            cout << "1" << " "  << "2" << endl;
            return 0;
        }else{
            cout << "-1" << " " << "-1" << endl;
            return 0;
        }
    }

    for(int i=0;i<s.size()-2;i++){
        if(s.at(i)==s.at(i+1)){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if(s.at(i)==s.at(i+2)){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << "-1" << " " << "-1"  << endl;

    return 0;
}


Measured memory_bytes: 512
N = int(input())
W = [ input() for _ in range(N) ]

if len(W) != len(set(W)):
  print("No")
  exit()

res = True
for i in range(1, N):
  if W[i][0] != W[i-1][-1]:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;

int a, b, c;

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

  scan(a);
  scan(b);
  scan(c);
//  vint s(n);
//  REP(i, n) scan(s[i]);

  cout << a+b+c-max({a, b, c}) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
   int n; cin>>n;
   vector<double> x(n);
   vector<string> u(n);
   rep(i,0,n) cin>>x[i]>>u[i];
   double ans=0;
   rep(i,0,n){
      if(u[i]=="JPY"){
         ans+=x[i];
      }else{
         ans+=x[i]*380000;
      }
   }
   cout<<ans<<endl;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(int N, vi& a) {
    map<int,int> m;
    for(int ai:a) m[ai]++;

    int u=0, v=0;
    for(ii p:m){
        ++u;
        v += p.second-1;
    }
    return (v % 2 == 0)? u : u-1;
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 5888
#include "bits/stdc++.h"
using namespace std;
#define r(i,a,n) for(int i=a;i<n;i++)
int main(){
  double t,a;
  int n;
  cin>>n>>t>>a;
  double h[n];
  int ans;
  r(i,0,n)cin>>h[i];
  double d=1e+9;
  r(i,0,n){
    if(d>abs(a-t+h[i]*0.006))d=abs(a-t+h[i]*0.006),ans=i+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

ll N, W;
ll w[101], v[101];
ll dp[101][100001];

void init()
{
}

void solve()
{
    FOR(i, 1, N+1){
        REP(j, W+1){
            dp[i][j] = dp[i-1][j];
            if(j-w[i] >= 0){
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> W;
    FOR(i, 1, N+1) cin >> w[i] >> v[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 78336
import sys
from collections import deque
sys.setrecursionlimit(10**9)

n,q = map(int, input().split())
l = [deque() for _ in range(n)]

for _ in range(q):
	query = input().split()
	if query[0] == "0": # insert
		idx = int(query[1])
		l[idx].append(query[2])
	elif query[0] == "1": # dump
		idx = int(query[1])
		print(" ".join(l[idx]))
	elif query[0] == "2": # splice
		idx1 = int(query[1])
		idx2 = int(query[2])
		if len(l[idx1]) > 1:
			if len(l[idx2]) == 0:
				l[idx2] = l[idx1]
			elif len(l[idx2]) == 1:
				l[idx1].appendleft(l[idx2][0])
				l[idx2] = l[idx1]
			else:
				l[idx2].extend(l[idx1])
		elif len(l[idx1]) == 1:
			l[idx2].append(l[idx1][0])
		l[idx1] = deque()



Measured memory_bytes: 45700
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  cin>>H>>W;
  rep(i,H)cin>>s[i];
  if(H==1&&W==1){
    cout<<"Yes"<<endl;
  }
  else{
    int mi=2500;
    for(int i=0;i<W;i++){
      for(int j=0;j<H; j++){
        if(s[i][j]=='#'){
          cnt=1;
          mi= min(dfs(i,j),mi);
        }
      }
    }
    if(mi==1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}	





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

int main()
{
    int N;
    string S;
    int count = 0;
    cin >> N >> S;
    for (int i = 0;i < N-2;i++) {
        if (S.substr(i, 3)=="ABC") {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

char str[20000];

int main() {
	int sx, sy, tx, ty;
	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	int idx = 0;
	REP(i, tx - sx) {
		str[idx++] = 'R';
	}
	REP(i, ty - sy) {
		str[idx++] = 'U';
	}
	REP(i, tx - sx) {
		str[idx++] = 'L';
	}
	REP(i, ty - sy) {
		str[idx++] = 'D';
	}
	str[idx++] = 'D';
	REP(i, tx - sx+1) {
		str[idx++] = 'R';
	}
	REP(i, ty - sy+1) {
		str[idx++] = 'U';
	}
	str[idx++] = 'L';
	str[idx++] = 'U';
	REP(i, tx - sx + 1) {
		str[idx++] = 'L';
	}
	REP(i, ty - sy + 1) {
		str[idx++] = 'D';
	}
	str[idx++] = 'R';
	printf("%s\n", str);
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;
use std::str::FromStr;
use std::cmp::Reverse;

#[allow(dead_code)]
type Error = Box<dyn std::error::Error>;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct Scanner {
    buff: Vec<String>,
    pos: usize,
}

#[allow(dead_code)]
impl Scanner {
    pub fn new() -> Self {
        Scanner {
            buff: Vec::new(),
            pos: 0,
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        while self.buff.len() <= self.pos {
            self.pos = 0;
            self.buff = read_line().split_whitespace().map(|s| s.to_owned()).collect();
        }

        let result = self.buff[self.pos].parse::<T>();
        self.pos += 1;
        result.ok().unwrap()
    }

    pub fn next_line(&mut self) -> String {
        let result  = read_line().trim().to_owned();
        self.buff.clear();
        self.pos = 0;

        result
    }

    pub fn next_vec<T: FromStr>(&mut self) -> Vec<T> {
        self.buff.clear();
        self.pos = 0;
        read_line().trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect()
    }
    
    pub fn next_line_chars(&mut self) -> Vec<char> {
        let result  = read_line().trim().chars().collect();
        self.buff.clear();
        self.pos = 0;

        result
    }
}


fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.next();
    let k: usize = sc.next();
    let c: usize = sc.next();

    let s = sc.next_line_chars();

    let mut l = Vec::new();
    let mut r = Vec::new();

    let mut pos = 0;
    while pos < n && l.len() < k {
        if s[pos] == 'o' {
            l.push(pos);
            pos += c+1;
        } else {
            pos += 1;
        }
    }
    let mut pos = (n-1) as i32;
    while pos >= 0 && r.len() < k {
        let p = pos as usize;
        if s[p] == 'o' {
            r.push(p);
            pos -= (c+1) as i32;
        } else {
            pos -= 1;
        }
    }
    r.reverse();
    for i in 0..k {
        if l[i]==r[i] {
            println!("{}", l[i]+1);
        }
    }
}


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

int main(){
  int a,b,c,n;
  cin >>a>>b>>c>>n;
  if(n<=a) cout << n<<endl;
  if(n>a&&n<=a+b) cout <<a<<endl;
  if(n>a+b) cout << a-(n-a-b)<<endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <queue>

int main()
{
    int K;
    std::cin >> K;

    std::queue<long long int> q;

    for (long long int i = 1; i < 10; ++i)
    {
        q.push(i);
    }

    int k = 0;
    while (k < K)
    {
        auto x = q.front();
        q.pop();
        k++;
        if(k==K){
          std::cout << x << std::endl;
          break;
        }

        auto last_digit = x % 10;
        auto m = 10 * x + last_digit;
        if (last_digit > 0)
        {
            q.push(m - 1);
        }
        q.push(m);
        if (last_digit <9)
        {
            q.push(m + 1);
        }
    }
}


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

ll A[101010],B[101010],C[101010];
ll sumBC[101010],sumAC[101010];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int X,Y,Z; cin>>X>>Y>>Z;
  int N=X+Y+Z;
  vector<pair<int,int>> V(N);
  rep(i,N){
    cin>>A[i]>>B[i]>>C[i];
    V[i]={A[i]-B[i],i};
  }
  sort(V.begin(),V.end());
  priority_queue<pair<int,int> > pq;
  ll sumB=0,sumC=0;
  rep(i,Y){
    int ind=V[i].second;
    sumB+=B[ind];
    pq.push({C[ind]-B[ind],ind});
  }
  sumBC[Y-1]=sumB;
  for(int i=Y;i<Y+Z;i++){
    int ind=V[i].second;
    pair<int,int> p=pq.top();
    if((C[ind]-B[ind])<p.first){
      sumB-=B[p.second];
      sumB+=B[ind];
      sumC+=C[p.second];
      pq.pop();
      pq.push({C[ind]-B[ind],ind});
    }else{
      sumC+=C[ind];
    }
    sumBC[i]=sumB+sumC;
  }
  while(pq.size()) pq.pop();
  ll sumA=0;
  for(int i=Y+Z;i<N;i++){
    int ind=V[i].second;
    sumA+=A[ind];
    pq.push({C[ind]-A[ind],ind});
  }
  sumAC[Y+Z]=sumA;
  sumC=0;
  for(int i=Y+Z-1;i>=Y;i--){
    int ind=V[i].second;
    pair<int,int> p=pq.top();
    if((C[ind]-A[ind])<p.first){
      sumA-=A[p.second];
      sumA+=A[ind];
      sumC+=C[p.second];
      pq.pop();
      pq.push({C[ind]-A[ind],ind});
    }else{
      sumC+=C[ind];
    }
    sumAC[i]=sumA+sumC;
  }
  ll ans=0;
  for(int i=Y-1;i<=Y+Z;i++){
    ans=max(ans,sumBC[i]+sumAC[i+1]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4732
<?php

$N = fgets(STDIN);
$array = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s", $v);
    array_push($array, $v);
}

$ua = array_unique($array);
$ra = array_values($ua);

echo count($ra) . PHP_EOL;


Measured memory_bytes: 45396
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k, s;
  cin >> n >> k >> s;
  rep(i, 0, n) {
    if (i > 0)
      cout << " ";
    if (i < k)
      cout << s;
    else {
      if (s == 1000000000)
        cout << s - 1;
      else
        cout << s + 1;
    }
  }
  cout << endl;
}


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

int main() {
  char a,b,n;
  int x;
  cin >>n>> a>>b;
  x=0;
  if (a=='1') {
    x++;
  }
  if (b=='1') {
    x++;
  }
  if (n=='1') {
    x++;
  }
 
  cout << x<< endl;

}

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

using namespace std;

int main(){
    int n, m;
    cin>>n>>m;
    int r, l;
    int a, b;

    cin>>l>>r;
    a=l;
    b=r;
    for(int i=1; i<m; ++i){
        cin>>l>>r;
        if(b<l || r<a){
            cout<<0<<endl;
            return 0;
        }
        a=max(a, l);
        b=min(b, r);
    }
    cout<<b-a+1<<endl;

    return 0;
}


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

int main(void) {
	// in
	std::string s;
	std::cin >> s;

	// 2 char ?
	std::vector<int> n_char(26);
	for(int i = 0; i < 4; ++i) {
		n_char[s[i] - 'A'] += 1;
	}
	
	int n_2char = 0;
	for(int i = 0; i < 26; ++i) {
		if(n_char[i] == 2) ++n_2char;
	}

	std::cout << (n_2char == 2 ? "Yes" : "No") << std::endl;

	return 0;
}


Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def main(args: Array[String]) = {
    val list = stdin.getLines().buffered.map { _.toInt }
    val n = list.next()
    val r0 = list.next()
    val r1 = list.next()
    var max = r1 - r0
    var min = if(r0 > r1) r1 else r0
    for( m <- list ) {
      if( max < m - min) {
        max = m - min
        if( min -m > 0 )
          min = m
      }
      else if( min - m > 0 ) {
        min = m
      }
    }
    println(max)
  }
}

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

int main(){
  string S;
  cin>>S;
  // SUN,MON,TUE,WED,THU,FRI,SAT 
  if(S=="SAT") cout<<"1"<<endl;
  if(S=="FRI") cout<<"2"<<endl;
  if(S=="THU") cout<<"3"<<endl;
  if(S=="WED") cout<<"4"<<endl;
  if(S=="TUE") cout<<"5"<<endl;
  if(S=="MON") cout<<"6"<<endl;
  if(S=="SUN") cout<<"7"<<endl;
}

Measured memory_bytes: 2968
<?php
/**
 * ABC130
 * C - Rectangle Cutting
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d %d %d %d", $W, $H, $x, $y);

echo $W * $H / 2, ' ', ($x * 2 == $W and $y * 2 == $H) ? '1' : '0', PHP_EOL;


Measured memory_bytes: 4604
H,W,K = map(int,input().split())
if W == 1:
    print(1)
    exit()
def serch(yokobou=[[None]*(W-1)],depth=0):
    queue = []
    for arrange in yokobou:
        for b in [0,1]:
            if b == 0:
                copy = arrange[:]
                copy[depth] = 0
                queue.append(copy)
            elif b == 1:
                copy = arrange[:]
                if depth == 0:
                    copy[depth] = 1
                elif arrange[depth-1] != 1:
                    copy[depth] = 1
                else:
                    continue
                queue.append(copy)
    yokobou = queue[:]
    if depth == W-2:
        return yokobou
    return serch(yokobou,depth+1)

def possibility(j):
    X,Y,Z = 0,0,0
    for e in serch():
        if j == 0:
            if e[j] == 1:
                Z += 1
            elif e[j] == 0:
                Y += 1
            continue
        elif j == W-1:
            if e[j-1] == 1:
                X += 1
            elif e[j-1] == 0:
                Y += 1 
            continue
        if e[j-1] == 1:
            X += 1
        if e[j] == 1:
            Z += 1
        if e[j-1] == 0 and e[j] == 0:
            Y += 1
    return (X,Y,Z)

dp = [[0]*(W) for i in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        (X,Y,Z) = possibility(j)
        if j != 0:
            dp[i+1][j] += X*dp[i][j-1]
        if j != W-1:
            dp[i+1][j] += Z*dp[i][j+1]
        dp[i+1][j] += Y*dp[i][j]

ans = dp[H][K-1]
ans %= 10**9 + 7
print(ans)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int a,b;
#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) For(i,0,n)

#define F first
#define S second
#define psb push_back
#define mkp make_pair
#define All(x) x.begin(),x.end()

typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e17;


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


int main(){
  int n;
  cin>>n;
  vector<int> v1(n);
  vector<int> v2(n);
  vector<int> v3(n);
  rep(i,n)cin>>v1[i];
  rep(i,n)cin>>v2[i];
  rep(i,n)v3[i]=i+1;
  int a,b,j=1;
  int cnt=0;
  while(1){
    
    if(v3==v1){a=j;cnt++;}
    if(v3==v2){b=j;cnt++;}
    j++;
    if(cnt==2)break;
  next_permutation(All(v3));
  }
cout<<abs(a-b)<<endl;;  
return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
#define vec vector<int>
using namespace std;
int main()
{

    int N, sum = 0;
    cin >> N;
    for (long long i = 100000000; i >= 1; i /= 10)
    {
        if (i == 1)
        {
            sum += N % 10;
        }
        else
        {
            sum += N / i % 10;
        }
    }
    if (N % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256