akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) lower_bound(vc.begin(), vc.end(), x) - vc.begin()

const int N = 5e5 + 7;

int n, k;
int p[N], q[N];
int seg[N * 50];
bool mrk[N];
int cpk;
set <int> s;
void upd(int p, int val) {
	p += (1 << 20);
	seg[p] = val;
	p /= 2;
	while (p) {
		seg[p] = max(seg[p * 2], seg[p * 2 + 1]);
		p /= 2;
	}
}
int get(int l, int r) {
	l += (1 << 20);
	r += (1 << 20);
	int res = max(seg[l], seg[r]);
	while (l / 2 != r / 2) {
		if (l % 2 == 0)
			res = max(res, seg[l + 1]);
		if (r % 2 == 1)
			res = max(res, seg[r - 1]);
		l /= 2;
		r /= 2;
	}
	return res;
}

void get(int pk) {
	int l = pk * k;
	int r = min(n, pk * k + k - 1);
	int mx = get(l, r);
	if (mx < 0 || mrk[q[mx]])
		return;
	if (get(q[mx] - k + 1, q[mx] + k - 1) == mx) {
		s.insert(q[mx]);
		mrk[q[mx]] = 1;	
	}

}
int res[N];
int main() {
	makefast;
	cin >> n >> k;
	cpk = (n + k - 1) / k;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
		q[p[i]] = i;
		upd(i, p[i]);
	}
	for (int i = 0; i < cpk; i++)
		get(i);
	for (int i = 1; i <= n; i++) {
		int p = *s.rbegin();
		s.erase(p);
		res[p + 1] = n - i + 1;
		upd(p, -1);
		for (int i = (p / k) - 1; i <= (p / k) + 1; i++)
			if (0 <= i && i < cpk)
				get(i);
	}
	for (int i = 1; i <= n; i++)
		cout << res[i] << '\n';


	return 0;
}


Measured memory_bytes: 43008
#include <iostream>

using namespace std;

int Euclid(int a, int b){
    int temp;
    if (a<b){
        temp=a;
        a=b;
        b=temp;
    }

    int r=a%b;
    while (r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
        

int main(){
    int n,x;
    cin >> n >> x;
    int a[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
        a[i]=abs(x-a[i]);
    }
    if (n==1){
      cout << abs(a[0]);
      exit(0);
    }
    int gcd=Euclid(a[0],a[1]);
    for (int i=1; i<n; i++){
        gcd=Euclid(gcd,a[i]);
    }
    cout << gcd << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, c = 0, x = 0;
  cin >> N >> A;
  while(A / 2 * 2 == A) {
    A /= 2;
      x++;
  }
  c = x;
  for(int i = 0; i < N - 1; i++) {
    x = 0;
    cin >> A;
    while(A / 2 * 2 == A) {
      A /= 2;
      x++;
    }
    if(x < c) {
      c = x;
    }
  }
  cout << c << endl;
}

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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 3; j++) cin >> a[i][j];
  }
  for (int i = 0; i < 8; i++) {
    vector<long long>vec;
    for (int j = 1; j <= N; j++) {
      long long S = 0;
      for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
      vec.push_back(S);
    }
    sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
    long long ans = 0;
    for (int j = 0; j < M; j++) ans += vec[j];
    maxn = max(maxn, ans);
  }
  cout << maxn << endl;
  return 0;
}

Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vector<int>> arr(15, vector<int>(15, -1));

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >>a >>b;
    cout <<6 - a - b;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

int main() {
    string s;
    int a[2];
    a[0] = 0;
    a[1] = 0;
    for (int i = 0; i < 3; i++) {
        int n;
        cin >> n;
        if (n == 5)a[0]++;
        if (n == 7)a[1]++;
    }
    if (a[0] == 2 && a[1] == 1)cout << "YES";
    else cout << "NO";
    return 0;
}

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

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

    vector<bool> v(3, false);
    v[--a] = true;
    v[--b] = true;

    for (int i = 0; i < 3; i++)
    {
        if (v[i] == false) {
            cout << i + 1 << endl;
            break;
        }
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n = 0;
	cin >> n;
	long long t= 0;
	long long ans = 1;
	long long temp=1000000000000000000;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		if (t == 0)
		{
			ans = 0;
			temp = 1;
			break;
		}
		temp /= t;
		ans *= t;
	}
	if (temp == 0)
	cout << -1 << endl;
	else
	cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int s;
  cin >> s;
  int ans;
  vector<int> v(1000001);
  v.at(s) ++;
  for(int i = 2;i <= 1000000;i++){
    int next;
    if(s % 2 == 0){
      next = s/2;
    }
    else{
      next = s*3 + 1;
    }
    if(v.at(next) == 1){
      cout << i << endl;
      return 0;
    }
    else{
      v.at(next) ++;
      s = next;
    }
  }
  cout << 1000000 << endl;
}

Measured memory_bytes: 7188
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int dist[25][25];
char board[25][25];
int main() {
    int H, W; cin >> H >> W;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> board[i][j];
        }
    }

    int ans = 0;    
    for(int sx=0; sx<H; sx++) {
        for(int sy=0; sy<W; sy++) {
            if(board[sx][sy] == '#') continue;
            fill(dist[0], dist[H+1], INF);
            dist[sx][sy] = 0;
            queue< pair<int, int> > que;
            que.emplace(sx, sy);

            while(que.size()) {
                int x, y; tie(x, y) = que.front(); que.pop();
                for(int k=0; k<4; k++) {
                    int nx = x + dx[k];
                    int ny = y + dy[k];
                    if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
                    if(board[nx][ny] == '#') continue;
                    if(dist[nx][ny] > dist[x][y] + 1) {
                        dist[nx][ny] = dist[x][y] + 1;
                        que.emplace(nx, ny);
                    }
                }
            }

            int max_dist = 0;
            for(int i=0; i<H; i++) {
                for(int j=0; j<W; j++) {
                    if(board[i][j] == '#') continue;
                    max_dist = max(max_dist, dist[i][j]);
                }
            }
            chmax(ans, max_dist);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long A,B,M,x,maxim=-1;
int main(){
	cin>>A>>B>>M;
	if(M<B){
		x=M;
		cout<<A*x/B<<'\n';
	}else{
		x=B-1;
		maxim=max(A*x/B-A*(x/B),maxim);
		long long coe=((M+1)/B)-1;
		x=coe*B-1;
		maxim=max(A*x/B-A*(x/B),maxim);
		x=M;
		maxim=max(A*x/B-A*(x/B),maxim);
		cout<<maxim<<'\n';
	}
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long int ll;
//きれいに書き直し
int main(){

    ll N , K;
    cin >> N >> K;

    if(K == 0){
        cout << N * N << endl;
        return 0;
    }

    ll ans = 0;

    for(ll i = 1; i <= N; i++){
        // iの倍数間の塊でどれくらいK以上のあまりが発生するか
        ans += max((ll)0, i - K) * (N / i);
        //残りの中にどれくらいK以上が残されているか
        //+1＝以上だょ
        ans += max((ll)0, N % i - K + 1);
    }

    cout << ans << endl;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ", "
#define de(x) cout << #x << "=" << x << endl
#define ds() puts("---stop here---")
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

int main()
{
    int op[5];
    char str[5];
    int a,b,c,d;
    scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
    bool ok = false;
    rep(i,0,8){
        op[1] = (1<<2)&i;
        if(op[1]) str[1] = '+';
        else str[1]='-';
        op[2] = (1<<1)&i;
        if(op[2]) str[2] = '+';
        else str[2]='-';
        op[3] = 1&i;
        if(op[3]) str[3] = '+';
        else str[3] = '-';
        int tmp = a;
        if(op[1]){
            tmp+=b;
        }
        else tmp-=b;
        if(op[2]){
            tmp+=c;
        }
        else tmp-=c;
        if(op[3]){
            tmp+=d;
        }
        else tmp-=d;
        if(tmp==7){
            printf("%d%c%d%c%d%c%d%c%c",a,str[1],b,str[2],c,str[3],d,'=','7');
            break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool ans[101][101];
int main(){
  int n,u,k,v;
  cin>>n;
  for(int j=0;j<n;j++){
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v;
      ans[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++){
      cout<<ans[i][j];
      if(j==n)cout<<endl;
      else cout<<" ";
    }
  return 0;
}



Measured memory_bytes: 3084
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AizuKnapsackNoRepetitions {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int w = in.nextInt();
            int[] vs = new int[n];
            int[] ws = new int[n];

            for (int i = 0; i < n; i++) {
                vs[i] = in.nextInt();
                ws[i] = in.nextInt();
            }

            out.printf("%d\n", knapsack(w, vs, ws, n));
        }

        private int knapsack(int w, int[] vs, int[] ws, int n) {
            int[][] dp = new int[w + 1][n + 1];

            for (int i = 1; i < w + 1; i++) {
                for (int j = 1; j < n + 1; j++) {
                    dp[i][j] = dp[i][j - 1];
                    if (i >= ws[j - 1]) {
                        dp[i][j] = Math.max(dp[i][j], vs[j - 1] + dp[i - ws[j - 1]][j - 1]);
                    }
                }
            }

            return dp[w][n];
        }

    }
}




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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P.at(i);
  }
  vector<int> m(N);
  m.at(0) = P.at(0);
  for (int i = 1; i < N; i++){
    m.at(i) = min(m.at(i-1), P.at(i));
  }
  int judge = 0;
  for (int i = 0; i < N; i++){
    if (P.at(i) == m.at(i)){
      judge++;
    }
  }
  cout << judge << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include  <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int,int>;
#define f first
#define s second
#define mp make_pair
#define pb push_back

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	int n,d;
	cin >> n >> d;
	double  dist = 0;
	int count = 0;
	for(int i = 0; i<n; i++){
		int x, y;
		cin >> x >> y;
		dist = sqrt(pow(x, 2) + pow(y, 2));
		if(dist <= d)
			count++;
		}
		cout << count << endl;
	return 0;    
}


Measured memory_bytes: 3636
/*---------------------------------------------*/
/*
    ABC177 D
 */
/*---------------------------------------------*/

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

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;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }
const int64_t INF = 0x3fffffffffffffff;

int main() {
    ll n, m, a, b;
    cin >> n >> m;
    Graph g(n);
    std::vector<int> vis(n,0);
    rep(i, m) {
        cin >> a >> b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans=0, cnt;
    queue<int> q;
    for(int i=0;i<n;i++){
        if(vis[i]) continue;
        vis[i]=1, cnt=0;
        q.push(i);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            cnt++;
            for (auto&(v) : (g[u])) {
                if(!vis[v]){
                    q.push(v);
                    vis[v]=1;
                }
            }
        }
        chmax(ans,cnt);
    }

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


Measured memory_bytes: 17356
#include<iostream>
int n;
void CountingSort(int*, int*, int);
int main(){
  int i, k=10000;
  std::cin >> n;
  int A[n], B[n];
  for(i=0; i<n; i++) std::cin >> A[i];
  CountingSort(A, B, k);
  for(i=0; i<n; i++) std::cout << B[i] << (i!=n-1 ? " " : "\n");
  return 0;
}
void CountingSort(int* A, int* B, int k){
  int i, j, C[k+1];
  for(i=0; i<=k; i++) C[i] = 0;
  for(j=0; j<n; j++) C[A[j]]++;
  for(i=1; i<=k; i++) C[i]= C[i] + C[i-1];
  for(j=n-1; j>=0; j--) B[C[A[j]]-1] = A[j], C[A[j]]--;
}

Measured memory_bytes: 18676
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: 
 */

#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<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  for (int i = 0; i < 12; i++) {
    if (i == 4) putchar(' ');
    putchar(s[i]);
  }
  putchar('\n');
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define OUT(x) std::cout << x << std::endl
#define DEBUG(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;あ
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    ll l,r,d;
    cin >> l >> r >> d ;
    ll tmp = 0;
    if (l%d == 0) tmp++;
    tmp += r/d - l/d;
    OUT(tmp);
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main(){
    bool card[4][14]={{}};
    char suit;
    int n,rank,i,j;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> suit >> rank;
        if(suit=='S') card[0][rank]=1;
        if(suit=='H') card[1][rank]=1;
        if(suit=='C') card[2][rank]=1;
        if(suit=='D') card[3][rank]=1;
    }
    
    for(i=0;i<4;i++){
        for(j=1;j<=13;j++){
            if(card[i][j]) continue;
            if(i==0) suit='S';
            if(i==1) suit='H';
            if(i==2) suit='C';
            if(i==3) suit='D';
            cout << suit << " " << j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
//TODO add string to vector of integers macro or function
vector<int> str_to_vect(string s)
{
	vector<int> v;
	for(int i=0;i<s.size();++i)
	{
		v.push_back((int)s[i]-48);
	}
	return v;
}
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<'\n';
	return 0;
}

Measured memory_bytes: 256
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C = il()
    print(min(C, B//A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4088
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i];
    }
    int ans = b[a[0] - 1];
    //cout << a[0] << b[a[0] - 1] << endl;
    //cout << ans << endl;
    for (int i = 1; i < n; i++) {
        ans += b[a[i] - 1];
        if (a[i - 1] + 1 == a[i]) {
            ans += c[a[i - 1] - 1];
        }        
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AtCoder Grand Contest 017
// D - Game on Tree

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;


const int MAX_N = 100000;

int N;
vector<int> G[MAX_N];
bool visited[MAX_N];

int calc_grundy(int v) {
    int grundy = 0;

    visited[v] = true;
    for (int to : G[v]) {
        if (visited[to]) {
            continue;
        }
        grundy ^= (calc_grundy(to) + 1);
    }

    return grundy;
}

int main() {

    int x, y;

    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> x >> y; x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    fill(visited, visited + N, false);

    cout << (calc_grundy(0) != 0 ? "Alice" : "Bob") << endl;

    return 0;

}





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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    cin>>s;
    if(s[0]==s[1] && s[1]==s[2]){
        cout << "No\n";
    }
    else cout << "Yes\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using i64 = long long;

constexpr i64 mod = 998244353;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

std::vector<i64> roots, rootsinv;

void calc_roots(const int n) {
    int sz = 0;
    while ((1 << sz) <= n) sz++;
    roots.resize(sz);
    rootsinv.resize(sz);

    for (int i = 1; i < sz; i++) roots[i] = pow(3, (mod - 1) / (1 << i), mod);
    for (int i = 1; i < sz; i++) rootsinv[i] = inverse(roots[i], mod);
}

void ntt(std::vector<i64> &a, bool rev = false) {
    const i64 n = a.size();
    if (roots.empty()) calc_roots(n);

    for (int i = 0, j = 1; j < n - 1; j++) {
        for (int k = n >> 1; k > (i ^= k); k >>= 1);
        if (j < i) std::swap(a[i], a[j]);
    }

    for (int mi = 1; (1 << mi) <= n; mi++) {
        const int m = 1 << mi;
        const i64 cc = rev ? rootsinv[mi] : roots[mi];

        for (int i = 0; i < n; i += m) {
            i64 w = 1;
            for (int j = i, k = i + m / 2; k < i + m; j++, k++) {
                i64 t1 = a[j], t2 = w * a[k] % mod;
                a[j] = (t1 + t2) % mod;
                a[k] = (t1 + mod - t2) % mod;
                w = w * cc % mod;
            }
        }
    }

    if (rev) {
        const i64 rv = inverse(n, mod);
        for (int i = 0; i < n; i++) a[i] = a[i] * rv % mod;
    }
}

std::vector<i64> multiply(std::vector<i64> f, std::vector<i64> g) {
    int maxindex = f.size() + g.size() + 1;
    int s = 1;
    while (s < maxindex) s *= 2;
    f.resize(s);
    g.resize(s);

    ntt(f);
    ntt(g);

    for (int i = 0; i < f.size(); i++) f[i] = f[i] * g[i] % mod;
    ntt(f, true);
    while (f.size() > 1 && f.back() == 0) f.pop_back();
    return f;
}

int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<i64> a(n), b(m);
    for (auto &e : a) std::cin >> e;
    for (auto &e : b) std::cin >> e;

    auto ret = multiply(a, b);
    ret.resize(n + m - 1);
    for (const i64 e : ret) std::cout << e << ' ';
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 48424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int A, B; cin >> A >> B;
    int sum = 1;
    int cnt = 0;
    while(true){
        if(sum >= B){
            cout<< cnt << endl;
            return 0;
        }
        sum = sum + A - 1;
        cnt++;
        if(sum >= B){
            cout<< cnt << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	LL n;
	cin >> n;
	auto sn = to_string(n);
	LL D = SI(sn);
	LL A = sn.front() - '0';
	LL B = sn.back()  - '0';
	
	LL E = 0;
	if(D >= 2) {
		auto m = sn;
		m.pop_back();
		reverse(ALL(m));
		m.pop_back();
		reverse(ALL(m));
		E = (D == 2 ? 0 : stoll(m));
	}
	
	LL ans = 0;
	inc1(x, n) {
		auto sx = to_string(x);
		LL a = sx.front() - '0';
		LL b = sx.back()  - '0';
		if(b == 0) { continue; }
		
		LL c = 0;
		inc(i, D - (b < A ? 1 : 2)) { c = 10 * c + 1; }
		if(a == b) { c++; }
		
		if(b == A && D > 1) { c += E + (a <= B ? 1 : 0); }
		
		// cout << x << ": " << c << endl;
		ans += c;
	}
	
	cout << ans << endl;
	
	return 0;
}


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


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var s = Console.ReadLine();
        long count = 0;
        for(int i = 0; i < s.Length; i++)
        {
            if (s[i] == '0')
                count++;
        }
        if (count > s.Length / 2)
            Console.WriteLine(2*(s.Length - count));
        else
            Console.WriteLine(2*count);



        Console.Out.Flush();
    }
}

Measured memory_bytes: 13116
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>

using namespace std;

int f(int k,
      const vector<int>& h,
      vector<int>& res) {
  if (k == 0) return 0;

  if (res[k] == -1) {
    res[k] = f(k - 1, h, res) + abs(h[k] - h[k - 1]);
    if (k >= 2) {
      res[k] = min(res[k], f(k - 2, h, res) + abs(h[k] - h[k - 2]));
    }
  }
  
  return res[k];
}

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

  // lets start from 0, to n-1
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  
  vector<int> res(n, -1);
  
  cout << f(n - 1, h, res);

  return 0;
}

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

const int M=998244353;
int fexp(int x,int t){
	if(!t)return 1;
	int tmp=fexp(x,t>>1);
	tmp=1ll*tmp*tmp%M;
	return (t&1)?1ll*x*tmp%M:tmp;
}
int fc[1000005],fi[1000005],n,k;
int C(int n,int m){
	if(m<0||m>n)return 0;
	return 1ll*fc[n]*fi[m]%M*fi[n-m]%M;
}
int main(){
	scanf("%d%d",&n,&k);
	fc[0]=1;
	for(int i=1;i<=k;i++)fc[i]=1ll*i*fc[i-1]%M;
	fi[k]=fexp(fc[k],M-2);
	for(int i=k-1;i>=0;i--)fi[i]=1ll*fi[i+1]*(i+1)%M;
	int ans=0;
	for(int a=max(n,(k+1)/2);a<=k;a++){
		ans=(ans+C(k,a))%M;
		ans=(ans-C(k,2*a-n+1)+M)%M;
		if(a*2==k){
			ans=(ans-C(k-1,a)+M)%M;
			ans=(ans+C(k-1,n-1))%M;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6272
#include <stdio.h>

#define MOD 1000000007

int main() {
  int N = 0;
  long long int A[200001] = {0};
  long long int sum = 0,sum2 = 0;

  scanf("%d",&N);
  for(int i=0;i<N;i++) {
    scanf("%I64d",&A[i]);
    sum2 += A[i];
    sum2 %= MOD;
  }

  for(int i=0;i<N;i++){
      sum2 -= A[i];
      if(sum2 < 0) sum2 += MOD;
      sum += (A[i] * sum2);
      sum = sum % MOD;
  }
  printf("%I64d\n",sum);

  return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <tuple>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
int S[2000][2000];//x,y

int C[2000][2000];
int I[2001][2001];
int R[2000][2000];
int L[2000][2000];
int U[2000][2000];
int D[2000][2000];
int N,M,Q;

void dfs(int x, int y){
    // cout<<x<<' '<<y<<' '<<S[x][y]<<endl;
    S[x][y]=0;
    if(x>0&&S[x-1][y]){
        U[x-1][y]=1;
        dfs(x-1,y);
    }
    if(x+1<N&&S[x+1][y]){
        D[x+1][y]=1;
        dfs(x+1,y);
    }
    if(y>0&&S[x][y-1]){
        L[x][y-1]=1;
        dfs(x,y-1);
    }
    if(y+1<M&&S[x][y+1]){
        R[x][y+1]=1;
        dfs(x,y+1);
    }
    return;
}

void imos(){
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            I[i+1][j+1]=C[i][j];
        }
    }
    for(int i=0;i<=N;i++){
        for(int j=0;j<M;j++){
            I[i][j+1]+=I[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=M;j++){
            I[i+1][j]+=I[i][j];
        }
    }
}

int sum(int i,int j,int h,int w){
    return I[i + h][j + w] - I[i][j + w] + I[i][j] - I[i + h][j];
}

int main(){
    cin>>N>>M>>Q;
    for(int i=0;i<N;i++){
        string str;
        cin>>str;
        for(int j=0;j<M;j++){
            S[i][j]=str[j]-'0';//x,y
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(S[i][j]){
                C[i][j]=1;
                dfs(i,j);
            }
        }
    }
    /*
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout<<C[i][j];
        }
        cout<<endl;
    }
    cout<<endl;

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout<<R[i][j];
        }
        cout<<endl;
    }
    cout<<endl;

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout<<L[i][j];
        }
        cout<<endl;
    }
    cout<<endl;

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout<<U[i][j];
        }
        cout<<endl;
    }
    cout<<endl;

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cout<<D[i][j];
        }
        cout<<endl;
    }
    cout<<endl;*/
    
    for(int i=0;i<N;i++){
        for(int j=1;j<M;j++){
            U[i][j]+=U[i][j-1];
            D[i][j]+=D[i][j-1];
        }
    }
    for(int j=0;j<M;j++){
        for(int i=1;i<N;i++){
            R[i][j]+=R[i-1][j];
            L[i][j]+=L[i-1][j];
        }
    }
    imos();
    for(int q=0;q<Q;q++){
        int x,X,y,Y;
        cin>>x>>y>>X>>Y;
        x--;y--;X--;Y--;
        int ans = sum(x,y,X-x+1,Y-y+1);
        // cout<<ans<<' ';
        ans+=D[x][Y]-(y?D[x][y-1]:0);
        ans+=U[X][Y]-(y?U[X][y-1]:0);
        ans+=R[X][y]-(x?R[x-1][y]:0);
        ans+=L[X][Y]-(x?L[x-1][Y]:0);
        cout<<ans<<endl;
    }


    return 0;
}

Measured memory_bytes: 112384
def main():
    N = int(input())
    A = []
    for i in range(N):
        a = int(input())
        xy = []
        for _ in range(a):
            x, y = list(map(int, input().split()))
            xy.append([x, y])
        A.append(xy)

    # print(A)
    P = []
    for i in range(2 ** N):
        b = format(i, 'b').zfill(N)
        P.append(b)

    ans = 0  # 矛盾がなかった場合の正直者の数
    for p in P:
        bits = list(p)  # 例: ['1', '0', '1']
        t = list(p)
        mujun = False
        for i, b in enumerate(bits):
            if b == '1':
                ss = A[i]  # 正直者の証言のリスト
                for x, y in ss:  # xはyである
                    if t[x-1] == str(y):
                        pass
                    else:
                        mujun = True
        if not mujun:
            syojiki = bits.count('1')
            ans = max(ans, syojiki)

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 5424
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
    struct newdata
    {
        int label,cnt;
    };
    int n,m;
    int a[301][301];
    newdata rankm[301];
    bool used[301];
bool cmp(newdata i,newdata j)
{
    return (i.cnt>j.cnt);
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
            if (j==1) rankm[a[i][j]].cnt++;
        }
    int now=0;
    for (int i=1;i<=m;i++)
        rankm[i].label=i;
    int ans=2147483647;
    while (now<m)
    {
        sort(rankm+1,rankm+m+1,cmp);
        ans=min(ans,rankm[1].cnt);
        used[rankm[1].label]=true;
        memset(rankm,0,sizeof(rankm));
        for (int i=1;i<=m;i++)
            rankm[i].label=i;
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
            	if (!used[a[i][j]])
            	{
					rankm[a[i][j]].cnt++;
					break;
				}
        now++;
    }
    printf("%d",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long double ans[3001][3001];
long double p[3001];
int main(void)
{
	int n;
	cin >> n;
	p[0]=1;
	for (int i = 1; i <=n; ++i)
	{
		cin>> p[i];
	}
	ans[0][0]=1;
	for (int i = 1; i <=n; ++i)
	{
		for (int j = 0; j <=i; ++j)
		{
			if(j==0)
			{
				ans[i][j]=ans[i-1][j]*(1-p[i]);
			}
			else if(j==i)
			{
				ans[i][j]=ans[i-1][j-1]*(p[i]);				
			}
			else
			{
				ans[i][j]=ans[i-1][j-1]*(p[i])+ans[i-1][j]*(1-p[i]);
			}
		}
	}
	long double final=0;

	for (int i = 0; i <=n; ++i)
	{
		if(i>n-i)
		{
			final=final+ans[n][i];
		}
	}
	printf("%.10Lf\n",final );
}

Measured memory_bytes: 139136
N,K=map(int,input().split())
x=list(map(int,input().split()))
T=10**9
for i in range(N-K+1):
    xr=x[i]
    xl=x[i+K-1]
    d1=abs(xr)+xl-xr
    d2=abs(xl)+xl-xr
    if T>d1:
        T=d1
    if T>d2:
        T=d2   
print(T)


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

def main():
    N = int(input())
    if N % 10 in [2, 4, 5, 7, 9]:
        print('hon')
    elif N % 10 in [0, 1, 6, 8]:
        print('pon')
    else:
        print('bon')
if __name__ == "__main__":
    main()


Measured memory_bytes: 9140
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 998244353;

ll ans = 0, n, q;
int a, b;
int ver[1<<20], hor[1<<20];

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cin>>n>>q;
 ans = (n-2)*(n-2);
 int x = n, y = n;
 while (q--) {
   cin>>a>>b;
   if(a == 1) {
     if(b > y) {
       ans -= hor[b]-2;
     } else {
       ans -= (x-2);
       for(int j = b;j <= y;j++) hor[j]=x;
       y = b;
     }
   } else {
     if(b > x) {
       ans -= ver[b]-2;
     } else {
       ans -= (y-2);
       for(int j = b;j <= x;j++) ver[j]=y;
       x = b;
     }
   }
 }
 cout << ans << endl;

 return 0;
}


Measured memory_bytes: 5236
// ABC088_C
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    vector< vector<ll> > vec((size_t)3, vector<ll>((size_t)3));
    REP(i, 3) {
        // N 行
        REP(j, 3) {
            // M 列：入力が逆になることもあるので注意
            cin >> vec[i][j];
        }
    }
    
    // calculation
    vector<ll> A(3), B(3);
    B[0] = 0;
    REP(i, 3) A[i] = vec[0][i] - B[0];
    REP(i, 3) B[i] = vec[i][0] - A[0];
    
    REP(i, 3) {
        REP(j, 3) {
            if ((A[j] + B[i]) != vec[i][j]) {
                cout << "No" << "\n";
                return 0;
            }
        }
    }
    
    cout << "Yes" << "\n";
    
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

const int maxN = 150010;
const int MAXM = 310;
const int MAXK = 17;
const int MOD = 1000000007;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int n,m,q;

ll a[maxN],b[maxN],c[maxN];
ll pa[maxN],pb[maxN],pc[maxN];

ll check(ll x,ll a,ll b)
{
	ll ans = 0;
	if((a<x && b>x) || (a>x && b<x))
	{
		ans = min(2*abs(x-a)+abs(x-b),2*abs(x-b)+abs(x-a));
	}
	else if(a>x && b>x || a<x && b<x)
	{
		ans = max(abs(x-a),abs(x-b));
	}
	return ans;
}

int main()
{
    scanf("%d%d%d", &n,&m,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	//	v.push_back(a[i]);
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&b[i]);
	//	v.push_back(b[i]);
	}
	for(int i=1;i<=q;i++)
	{
		scanf("%lld",&c[i]);
	//	v.push_back(c[i]);
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	for(int i=1;i<=q;i++)
	{
		ll la,ra,lb,rb;
		int p = lower_bound(a+1,a+1+n,c[i]) - a;
		int q = lower_bound(b+1,b+1+m,c[i]) - b;
		ra = a[p],la = a[p-1];
		rb = b[q],lb = b[q-1];
		if(p>n)
			ra = inf;
		if(p<2)
			la = -inf;
		if(q>m)
			rb = inf;
		if(q<2)
			lb = -inf;
		ll t1 = check(c[i],ra,rb);
		ll t2 = check(c[i],ra,lb);
		ll t3 = check(c[i],la,rb);
		ll t4 = check(c[i],la,lb);
		
		ll ans = min(min(t1,t2),min(t3,t4));
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

int n, m;
vector<vector<int>> e;
vector<char> v;
int c, b;

void dfs(int i, int d) {
    v[i] = d;
    c++;
    d ^= 3;
    for (int j : e[i]) {
        if (v[j]) b |= v[j] ^ d; else dfs(j, d);
    }
}

int main() {
    cin >> n >> m;
    v = vector<char>(n);
    e = vector<vector<int>>(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--; v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    int64_t k[3] = {};
    for (int i = 0; i < n; i++) {
        if (v[i]) continue;
        c = b = 0;
        dfs(i, 1);
        k[(c > 1) + (b != 0)]++;
    }

    k[2] += k[1];
    int64_t r = k[0] * (n * 2 - k[0]) + k[2] * k[2] + k[1] * k[1];

    cout << r << endl;

    return 0;
}


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

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

	int n;
	int sum=0;

	cin >> n;
	vector<int> x(n, 0);

	
	
	for (int i = 0; i < n; i++){
		cin >> x[i];
		if (i % 2 == 0)	sum += x[i];
		else sum -= x[i];
	}

	for (int i = 0; i < n; i++){
		if (i != 0)  sum= 2 * x[i-1] - sum;
		else sum = sum;
		cout << sum << " ";
	}


	

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define mod 1000000007
#define maxn 200005
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb(x) push_back((char)(x))
#define pf(x) push_front((ll)(x))
#define nl cout << "\n";
 
// struct Data{
// 	ll val,pos;
// };

void ini(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

// bool comp(Data &a,Data &b){
// 	return (a.val<b.val);
// }



int main(){
	ini();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	char c;
	cin >> c;
	if((int)c>=97){
		cout << 'a';
	}else{
		cout << 'A';
	}

}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private class Node<T> {
		T key;
		Node<T> left;
		Node<T> right;
		Node<T> parent;
		public Node(T key) {
			this.key = key;
			left = right = parent = null;
		}
		public String toString() {
			return key.toString();
		}
	}
	
	private class BST {
		
		private Node<Integer> rootNode;
		public BST() {
			rootNode = null;
		}
		
		public void insert(Node<Integer> node) {			
			Node<Integer> parent = null;
			Node<Integer> cur = rootNode;
			while (cur != null) {
				parent = cur;
				if (node.key < cur.key) {
					cur = cur.left;
				} else {
					cur = cur.right;
				}
			}
			node.parent = parent;
			if (parent == null) {
				rootNode = node;
			} else if (node.key < parent.key) {
				parent.left = node;
			} else {
				parent.right = node;
			}
		}
		
		public void print() {
			printInOrder(rootNode);
			System.out.println("");
			printPreOrder(rootNode);
			System.out.println("");
		}
		
		private void printInOrder(Node<Integer> node) {
			if (node != null) {
				printInOrder(node.left);
				System.out.print(" " + node);
				printInOrder(node.right);
			}			
		}
		
		private void printPreOrder(Node<Integer> node) {
			if (node != null) {
				System.out.print(" " + node);
				printPreOrder(node.left);
				printPreOrder(node.right);
			}			
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		BST bst = new BST();
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			String cmd = st.nextToken();
			if (cmd.equals("insert")) {
				bst.insert(new Node<Integer>(Integer.parseInt(st.nextToken())));
			} else {
				bst.print();
			}
		}
		reader.close();
	}
}



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

int main()
{
	ll X,Y;
	scanf("%lld%lld",&X,&Y);

	ll ans = 0;
	if(abs(X) <= abs(Y)){
		ans += abs(Y) - abs(X);
		ans += X < 0;
		ans += Y < 0;
	}
	else{
		ans += abs(X) - abs(Y);
		ans += X > 0;
		ans += Y > 0;
	}

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

	return 0;
}


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

int n,a[100010],ans;
bool b[100010];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	
	for(int t=0;t<2;t++)
		for(int i=1;i<=n;i++)
		{
			int cur=0;bool f=0;
			while(i<=n&&a[i]==i) swap(a[i],a[i+1]),i++,cur++,f=1;
			if(f) i--,ans=ans+(cur==1?1:cur-1);
		}
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>       
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    string str;
    set<string>s;
    while(n--)
    {
         cin>>str;
         s.insert(str);
    }
    cout<<s.size();
}


Measured memory_bytes: 19192
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<P> v;
	rep(i,n){
		int a, b;
		cin >> a >> b;
		v.emplace_back(b,a);
	}
	sort(v.begin(), v.end());
	int t = 0;
	rep(i,n){
		if(t+v[i].second > v[i].first){
			cout << "No" << endl;
			return 0;
		}
		t += v[i].second;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;

int main (void) {
  int N;
  ll ans[86];
  cin >> N;
  ans[0]=2;
  ans[1]=1;
  for(int i=2;i<=N;i++){
    ans[i]=ans[i-1]+ans[i-2];
  }
  cout << ans[N];
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;


using edge = struct { int to; ll cost; };
ll len[100005];
vector<edge> tree[100005];
int n;
void dfs(int v,int p,ll d) {
    len[v] = d;
    for (int i = 0; i < tree[v].size(); i++) {
        if (tree[v][i].to == p)continue;
        dfs(tree[v][i].to, v, d + tree[v][i].cost);
    }
}


int main() {
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        tree[a].push_back({ b,c });
        tree[b].push_back({ a,c });
    }
    int q, k;
    cin >> q >> k;
    dfs(k, -1, 0);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << len[x] + len[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 15872