akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n, x;
    while(cin>>x>>n){
        ll ans=0;
        int xx;
        for(int i=0; i<n; ++i){
            scanf("%d",&xx);
            a[xx]=1;
        }
        int tmp, mn=1e9;
        for(int i=0; i<=200; ++i){
        	if(a[i])
        		continue;
        	if(abs(i-x)<mn){
        		mn=abs(i-x);
        		tmp=i;
        	}
        }
        printf("%d\n",tmp);
    }
  return 0;
}




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

int main(){
  int N, M;
  vector<int> C(5, -1);

  cin >> N >> M;
  for(int i=0; i<M; i++){
    int s, c; cin >> s >> c;
    if(C[s] != -1 && C[s] != c){
      cout << -1 << endl; return 0;
    } else {
      C[s] = c;
    }
  }

  if(N == 1){
    if(C[1] == -1) C[1] = 0;
    cout << C[1] << endl; return 0;
  }

  if(N == 2){
    if(C[1] == 0) {
      cout << -1 << endl; return 0;
    } else {
      if(C[1] == -1) C[1] = 1;
      if(C[2] == -1) C[2] = 0;
      cout << C[1]*10+C[2] << endl; return 0;
    }
  }

  if(N == 3){
    if(C[1] == 0) {
      cout << -1 << endl; return 0;
    } else {
      if(C[1] == -1) C[1] = 1;
      if(C[2] == -1) C[2] = 0;
      if(C[3] == -1) C[3] = 0;
      cout << C[1]*100+C[2]*10+C[3] << endl; return 0;
    }
  }
}

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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int ans;
  if(K>B){
    ans = A - (K - (A + B));
  }else if(K>A){
    ans = A;
  }else{
    ans = K;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
using namespace std;

int H,W,K,A[309][309],num,cnt[309];
char c[309][309];

void cut(int cl, int cr) {
	vector<int> P;
	erep(i,cl,cr) {
		erep(j,1,W) {
			if (c[i][j] == '#') P.push_back(j);
		}
	}
	sort(P.begin(), P.end());
	rep(i,0,P.size()) {
		int v1 = 1, v2 = W;
		if (i >= 1) v1 = P[i - 1] + 1;
		if (i < (int)P.size() - 1) v2 = P[i];

		num++;
		erep(j,cl,cr) {
			erep(k,v1,v2) A[j][k] = num;
		}
	}
}

int main() {
	cin >> H >> W >> K;
	erep(i,1,H) {
		erep(j,1,W) {
			cin >> c[i][j];
			if (c[i][j] == '#') cnt[i]++;
		}
	}

	vector<int> vec;
	erep(i,1,H) if (cnt[i]) vec.push_back(i);
    rep(i,0,vec.size()) {
		int v1 = 1, v2 = H;
		if (i>0) v1 = vec[i - 1] + 1;
		if (i<(int)vec.size()-1) v2 = vec[i];
		cut(v1, v2);
	}

	erep(i,1,H) {
		erep(j,1,W)cout<<A[i][j]<<" ";
		puts("");
	}
}

Measured memory_bytes: 1280
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n;
    cin >> n;
    vector<ll> f(10001,0);
    for(ll i=1;i<=sqrt(n);i++){
        for(ll j=1;j<=sqrt(n);j++){
            for(ll k=1;k<=sqrt(n);k++){
                ll tmp=i*i+j*j+k*k+i*j+j*k+k*i;
                if(tmp<=n) f[tmp]++;
            }
        }
    }
    for(ll i=1;i<=n;i++){
        cout << f[i] << endl;
    }
}

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

typedef long long ll;

const int N = 1e5 + 1e3;

int n, h[N], A, B;

inline bool check(ll times) {
	ll cur = 0;
	For (i, 1, n) {
		ll tmp = h[i] - B * times;
		if (tmp > 0) cur += tmp / (A - B) + (tmp % (A - B) ? 1 : 0);
	}
	return cur <= times;
}

int main () {

	File();

	n = read(), A = read(), B = read();
	
	ll l = 0, r = 0, res = 0;
	For (i, 1, n) 
		r += (h[i] = read()) / A + 1;

	while (l <= r) {
		ll mid = (l + r) >> 1;
		if (check(mid)) res = mid, r = mid - 1; else l = mid + 1;
	}
	printf ("%lld\n", res);

	return 0;

}

Measured memory_bytes: 640
N = gets.to_i
x_list = gets.split.map(&:to_i)
sorted_x_list = x_list.sort
mid_i = sorted_x_list.size / 2 - 1
mid = sorted_x_list[mid_i]

N.times do |i|
  x = x_list[i]
  ans =
    if x <= mid
      sorted_x_list[mid_i + 1]
    else
      mid
    end
  puts ans
end


Measured memory_bytes: 23396
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(void) {
    int a, b;
    std::scanf("%d %d", &a, &b);
    if ((a + b) % 2 == 0) {
        std::printf("%d\n", (a + b) / 2);
    }
    else {
        std::printf("%d\n", (a + b) / 2 + 1);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int bc[100005];
long long s[5];
long long max(long long a, long long b) {
	return a > b ? a : b;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> bc[i];
	}
	sort(bc, bc + n);
	int an = 0;
	long long sss = 0;
	for (int i = n - 1, j = 0;i >= 0;i--) {
		int ans = 1;
		while (bc[i] == bc[i - 1]) {
			ans++;i--;
		}
		if (an == 2)
			break;
		else if (ans >= 2) {
			s[j] = bc[i];
			if (ans >= 4)
				sss = max(sss, s[j]*s[j]);
			j++;
		}
	}
	long long t = s[0]*s[1];
	cout << max(sss, t) << endl;
}

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

const int N = 200001;
vector< vector<int> > G(N);
vector< vector<int> > dist(2,vector<int>(N,-1));

void bfs(int s){
  int c;
  if(s == 1) c = 0;
  else c = 1;

  queue<int> q;
  q.push(s);
  dist[c][s] = 0;
  while(!q.empty()){
    int p = q.front(); q.pop();
    for(int i = 0; i < G[p].size(); i++){
      int v = G[p][i];
      if(dist[c][v] == -1){
        dist[c][v] = dist[c][p] + 1;
        q.push(v);
      }
    }
  }
}

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

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

  bfs(1);
  bfs(n);

  int fennec = 0,snuke = 0;
  for(int i = 1; i <= n; i++){
    if(dist[0][i] <= dist[1][i]) fennec++;
    else snuke++;
  }
  if(fennec > snuke) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}


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

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

	set<int> values;
	for (int i = 0; i < d.size(); ++i)
	{
		values.insert(d[i]);
	}

	cout << values.size() << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())

if len(str(n)) == 6:
    print(90909)
elif len(str(n)) == 4:
    print(909)
elif len(str(n)) == 2:
    print(9)
elif len(str(n)) == 1:
    print(n)
elif len(str(n)) == 3:
    print(9 + (n - 100) + 1)
elif len(str(n)) == 5:
    print(9 + 900 + (n - 10000) + 1)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(void)
{
    int n,a[5],b[5];
    cin>>n;
    for(int i=0;n>0;n/=10,i++){
        a[i]=n%10;
    }
    for(int i=0;i<3;i++){
        if(a[i]==1)
        b[i]=9;
        else if(a[i]==9)
        b[i]=1;
        else
        b[i]=a[i];
    }
    cout<<b[2]<<b[1]<<b[0]<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    ll A[N][N];
    ll B[N][N];
    FOR(i, 0, N){
        FOR(j, 0, N){
            ll a;
            cin >> a;

            A[i][j] = a;
            B[i][j] = a;
        }
    }

    // ワーシャル
    FOR(i, 0, N){
        FOR(j, 0, N){
            FOR(k, 0, N){
                // j -> i -> k
                B[j][k] = min(B[j][k], B[j][i] + B[i][k]);
            }
        }
    }

    ll sum = 0;

    // 各u, vについてチェック
    FOR(u, 0, N){
        FOR(v, u+1, N){
            if(u==v){
                continue;
            }

            if(B[u][v]!=A[u][v]){
                p(-1);
                return 0;
            }

            bool have_bypass = false;
            // u, v以外の点wを経由して最短で行けるか
            FOR(w, 0, N){
                if(w!=u && w!=v && B[u][v] == B[u][w]+B[w][v]){
                    have_bypass = true;
                }
            }

            if(!have_bypass){
                sum += B[u][v];
            }
        }
    }

    p(sum);


    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  char color;
  string number = "Three";
  for (int i=0; i < N; i++) {
    cin >> color;
    if (color == 'Y') {
      number = "Four";
    }
  }
  cout << number << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc135/tasks/abc135_c

n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))

f1 = min(a[0], b[0])
f2 = min(a[1], b[0] - f1)
res = f1 + f2
for i in range(1, n):
    f1 = min(a[i] - f2, b[i])
    f2 = min(a[i+1], b[i] - f1)
    res += f1 + f2

print(res)


Measured memory_bytes: 24172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using P = pair<int,int>;

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

    int tot = 0;
    for(char c : s) tot += (int)c - 48;
    if(tot%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    for (int i = 0; i < A; i++)cin >> a[i];
    for (int i = 0; i < B; i++)cin >> b[i];
    int minA = *min_element(a.begin(), a.end());
    int minB = *min_element(b.begin(), b.end());
    int ans = minA+minB;
    for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c; x--; y--;
    ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int a, b, c; cin >> a >> b >> c;
  if (a == b && b == c) cout << 1 << endl;
  else if (a != b && b != c && a != c) cout << 3 << endl;
  else cout << 2 << endl;
  
  return 0;
}


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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 4764
#include<iostream>

using namespace std;

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

Measured memory_bytes: 3652
H,W = list(map(int,input().split()))
S = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            if not (i == 0 or S[i-1][j] == '.'):
                continue
            if not (i == H-1 or S[i+1][j] == '.'):
                continue
            if not (j == 0 or S[i][j-1] == '.'):
                continue
            if not (j == W-1 or S[i][j+1] == '.'):
                continue
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
module Main where

import Control.Applicative
import Numeric

main :: IO()
main = do
  {[n] <- getInts
  ; call n
  }

call :: Int -> IO ()
call n = check_num n 1 1

check_num :: Int -> Int -> Int -> IO ()
check_num n i x = if x `mod` 3 == 0
  then putStr " " >> putStr (show i) >> end_check_num n i x
  else include3 n i x

include3 :: Int -> Int -> Int -> IO ()
include3 n i x = if x `mod` 10 == 3
  then putStr " " >> putStr (show i) >> end_check_num n i x
  else let x' = x `div` 10
           in if x' /= 0 then include3 n i x'
              else end_check_num n i x'

end_check_num :: Int -> Int -> Int-> IO ()
end_check_num n i x = let i' = i +1
                      in if i' <= n then check_num n i' i'
                         else putStrLn ""

--


getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO()
putInts = putStrLn . unwords . map show

getDoubles :: IO[Double]
getDoubles = map read . words  <$> getLine

putDoubles :: [Double] -> IO()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4284
using System;

namespace aziz
{
    class Program
    {
        static void Main(string[] args)
        {
          String[] AB = Console.ReadLine().Split(' ');
          int A = int.Parse(AB[0]);
          int B = int.Parse(AB[1]);
          
          var result = A * B;
          
          Console.WriteLine(result);  
        }
    }
}

Measured memory_bytes: 27532
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define fi first
#define se second
map<int,int> mp;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int i=0;i<n;i++){
    int a;
    cin>>a;
    mp[a]++;
    mp[a+1]++;
    mp[a-1]++;
}
int ans=0;
for(auto p:mp){
    int res=p.se;
    ans=max(ans,res);
}
cout<<ans<<endl;
}


Measured memory_bytes: 4736
n,m=map(int,input().split())
a=0
cnt=1
p,q,r=1,0,0
#print(cnt,p)
for i in range(m):
  a=int(input())
  while cnt<n and cnt<a:
      s,r,q=r,q,p
      p=(q+r)%(10**9+7)
      cnt+=1
      #print(cnt,p)
  if a==cnt:
    s,r,q=r,q,p
    p=0
    cnt+=1
    #print(cnt,p)
    
while cnt<=n:
    s,r,q=r,q,p
    p=(q+r)%(10**9+7)
    cnt+=1
    #print(cnt,p)
print(p%(10**9+7))

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

long long count(vector<long long> &A, long long d)
{
    long long N = A.size();
    vector<long long> remain(N);
    for (long long i = 0; i < N; i++)
    {
        remain[i] = A[i] % d;
    }
    sort(remain.begin(), remain.end());

    vector<long long> plus(N, 0);
    for (long long i = N - 1; i >= 0; i--)
    {
        plus[i] += (d - remain[i]) % d;
        if (i + 1 < N)
        {
            plus[i] += plus[i + 1];
        }
    }

    vector<long long> minus(N, 0);
    for (long long i = 0; i < N; i++)
    {
        minus[i] += remain[i];
        if (i > 0)
        {
            minus[i] += minus[i - 1];
        }
    }

    long long ret = INT_MAX;
    for (long long i = 0; i < N - 1; i++)
    {
        ret = min(ret, max(minus[i], plus[i + 1]));
    }
    return ret;
}

int main()
{
    long long N, K;
    cin >> N >> K;

    vector<long long> A(N);
    long long sum = 0;
    for (long long &a : A)
    {
        cin >> a;
        sum += a;
    }

    long long ans = 1;
    for (long long i = 1; i * i <= sum; i++)
    {
        if (sum % i == 0)
        {
            if (count(A, i) <= K)
            {
                ans = max(ans, i);
            }
            if (count(A, sum / i) <= K)
            {
                ans = max(ans, sum / i);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector <int> v(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i%2 == 0 && v[i]&1) ans++;
    }
    cout << ans;
    return 0;
}




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

void solve() {

	int N; cin >> N;
	map<int, int> even, odd;
	vector<int> vec(N);
	int tmp;
	rep(i, N) {
		scanf("%d", &tmp);
		vec[i] = tmp;
		if (i % 2 == 0) odd[tmp]++;
		else even[tmp]++;
	}

	int even_1 = 0, even_2 = 0, odd_1 = 0, odd_2 = 0;
	int e1 = 0, e2 = 0, o1 = 0, o2 = 0;
	int count = 0;
	for (auto itr = even.begin(); itr != even.end(); itr++) {
		if (itr->second > count) {
			count = itr->second;
			even_1 = itr->first;
		}
	}

	e1 = count;
	count = 0;
	for (auto itr = even.begin(); itr != even.end(); itr++) {
		if (itr->second > count && itr->first != even_1) {
			count = itr->second;
			even_2 = itr->first;
		}
	}
	e2 = count;

	count = 0;
	for (auto itr = odd.begin(); itr != odd.end(); itr++) {
		if (itr->second > count) {
			count = itr->second;
			odd_1 = itr->first;
		}
	}

	o1 = count;
	count = 0;
	for (auto itr = odd.begin(); itr != odd.end(); itr++) {
		if (itr->second > count && itr->first != odd_1) {
			count = itr->second;
			odd_2 = itr->first;
		}
	}
	o2 = count;

	cout << (even_1 == odd_1 ? min(N - e1 - o2, N - e2 - o1) : N - e1 - o1) << endl;
}

int main(void) {
	solve();

	return 0;
}

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

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

const int lim = 1000000007;

int main(){
    ll S;
    cin >> S;

    const int val = pow(10, 9);

    int y = (S + val - 1) / val;
    int x = val * y - S;

    cout << 0 << " " << 0 << " " << val << " " << 1 << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        char[] s = scanner.next().toCharArray();
        boolean mmyy = false, yymm = false;
        if (check(s[2], s[3]))
            yymm = true;
        if (check(s[0], s[1]))
            mmyy = true;
        if (mmyy && yymm)
            writer.println("AMBIGUOUS");
        else if (mmyy)
            writer.println("MMYY");
        else if (yymm)
            writer.println("YYMM");
        else
            writer.println("NA");
        writer.close();
    }

    private static boolean check(char a, char b) {
        return (a == '0' && b >= '1' && b <= '9') || (a == '1' && (b == '0' || b == '1' || b == '2'));
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22484
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=0

for a in range(2**h):
    sa="0"+str(h)+"b"
    la=list(format(a,sa))
    for b in range(2**w):
        sb = "0" + str(w) + "b"
        lb = list(format(b, sb))
        cnt=0
        for i in range(h):
            for j in range(w):
                if la[i]!="1" and lb[j]!="1" and c[i][j]=="#":
                    cnt+=1
        if cnt==k:
            ans+=1
print(ans)

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

ll init();
void solve();

signed main()
{
	cout << init() << endl;
	solve();
}

ll init()
{
	int N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> k1(N);
	vector<ll> k2(N);
	rep(i, N) cin >> a[i];
	sort(all(a));
	if (N == 2) return abs(a[0] - a[1]);
	if (N % 2) {
		k1[0] = k1[1] = 1;
		k2[0] = k2[1] = -1;
	} else {
		k1[0] = k2[1] = 1;
		k1[1] = k2[0] = -1;
	}
	int f = -1;
	reps(i, 2, N) {
		k1[i] = f * 2;
		k2[i] = -f * 2;
		f = -f;
	}
	sort(all(k1));
	sort(all(k2));
	ll res1 = 0;
	ll res2 = 0;
	rep(i, N) {
		res1 += k1[i] * a[i];
		res2 += k2[i] * a[i];
	}
	return max(res1, res2);
}

void solve()
{
}




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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	vl a(n);
	FOR(i,0,n) cin >> a[i];

	vl res;
	while (sz(a)) {
		ll i = sz(a)-1;
		while (i >= 0 && a[i] != i+1) i--;

		if (i < 0) {
			cout << -1 << endl;
			return 0;
		}

		res.pb(a[i]);
		a.erase(begin(a)+i);
	}
	
	reverse(all(res));
	for (ll x: res) cout << x << endl;

}



Measured memory_bytes: 256
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (x, y) = readIntegerList()
    for (i in 0..x) {
        val j = x - i
        if (i * 2 + j * 4 == y) {
            println("Yes")
            return
        }
    }
    println("No")
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

int LDY[4] = {-1, 0, 1, 0};
int LDX[4] = {0, 1, 0, -1};
int RDY[4] = {-1, 0, 1, 0};
int RDX[4] = {0, -1, 0, 1};

int W, H;
char used[52][52][52][52]; // ly, lx, ry, rx
char L[52][52], R[52][52];

class State {
public:
    int ly, lx, ry, rx;
    State() {}
    State(int ly, int lx, int ry, int rx) : ly(ly), lx(lx), ry(ry), rx(rx) {}
    bool operator==(const State& a) { return ly == a.ly && lx == a.lx && ry == a.ry && rx == a.rx; }
};

void init() {
    memset(used, 0, 52*52*52*52);
    for (int i=0; i<52; ++i) {
        for (int j=0; j<52; ++j) {
            L[i][j] = R[i][j] = '#';
        }
    }
}

int main() {
    while (cin >> W >> H, W) {
        init();
        State S, G;
        for (int i=1; i<=H; ++i) {
            string rl, rr;
            cin >> rl >> rr;
            for (int j=1; j<=W; ++j) {
                L[i][j] = rl[j-1];
                R[i][j] = rr[j-1];
                if (L[i][j] == 'L') {
                    S.ly = i;
                    S.lx = j;
                } else if (L[i][j] == '%') {
                    G.ly = i;
                    G.lx = j;
                }
                if (R[i][j] == 'R') {
                    S.ry = i;
                    S.rx = j;
                } else if (R[i][j] == '%') {
                    G.ry = i;
                    G.rx = j;
                }
            }
        }
        
        bool ok = false;
        queue<State> q;
        q.push(S);
        while ( ! ok && ! q.empty()) {
            State t = q.front(); q.pop();
            if (used[t.ly][t.lx][t.ry][t.rx]) continue;
            used[t.ly][t.lx][t.ry][t.rx] = 1;
            for (int i=0; i<4; ++i) {
                State t2 = t;
                if (L[t.ly + LDY[i]][t.lx + LDX[i]] != '#') {
                    t2.ly += LDY[i];
                    t2.lx += LDX[i];
                }
                if (R[t.ry + RDY[i]][t.rx + RDX[i]] != '#') {
                    t2.ry += RDY[i];
                    t2.rx += RDX[i];
                }
                if (t2 == G) {
                    ok = true;
                    break;
                }
                if ((L[t2.ly][t2.lx] == '%' && R[t2.ry][t2.rx] != '%')
                || (L[t2.ly][t2.lx] != '%' && R[t2.ry][t2.rx] == '%')) {
                    continue;
                }
                if ( ! used[t2.ly][t2.lx][t2.ry][t2.rx]) q.push(t2);
            }
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 11768
import math
H, W = map(int, input().split())
# 今いる列の到達可能店
if H == 1 or W == 1:
    print(1)
    exit()
if H % 2 == 0:
    can = H // 2
    ans = can * W
    print(ans)
elif H % 2 == 1:
    can = H
    ans = math.ceil(can * (W / 2))
    print(ans)


Measured memory_bytes: 3060
#include <iostream>

#include <deque>

#include <stdio.h>

#include <cstdio>

#include <algorithm>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "
#define nw <<"\n"
#define ca "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define ull unsigned LL
#define check cout<<"* ";
#define show_vector for(int q=0;q<v.size();q++){cout<<v[q]<<" ";}
#define REP(i,n) for (int i=0;i<(n);++i)
#define N_MAX 26


const int inf=1<<30;
const long long int INF=1e10;
const int MOD=1e9+7;
const int maxn = 1e5+10;
int a[200005],b[1000005];

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
/*
int ck_prime(int n)
{
    int coun;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
           return 1; // n is prime
        }
    return 0;
}
*/
int main()
{
    int n,z,sum=0;
    cin>>n;
    vector<int>order;
    vector<int>extra;
    for(int i=1;i<=n;i++){
        cin>>z;
        order.pub(z);
    }
    order.pub(0);
    for(int i=1;i<=n;i++){
       cin>>z;
       sum+=z;
    }
    for(int i=1;i<n;i++){
        cin>>z;
        extra.pub(z);
    }

    for(int i=0;i<n;i++){
        int x=order[i];
        int y=x+1;

        if(order[i+1]==y){
            sum+=extra[x-1];
        }
    }
    cout<<sum nw;
}



Measured memory_bytes: 3592
#include <stdio.h>

int main()
{
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=S/60;
	while(!(60>m)){
		m-=60;
	}
	s=S%60;
	
	printf("%d:%d:%d\n",h,m,s);
    return(0);
}

Measured memory_bytes: 592
from collections import defaultdict
import string
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

N = int(input())
alph = string.ascii_lowercase

ans = defaultdict(int)

@lru_cache(maxsize=None)
def search(S, nums):
    if nums in ans:
        return
    if len(nums) == N:
        ans[nums] = S
        return

    for i in range(len(nums)):
        for s, n in zip(S, nums):
            if n == i:
                search(S + s, nums + (n, ))
                break
    C = set(list(S))
    for s in alph:
        if not s in C:
            search(S + s, nums + (len(nums), ))
            break

search('a', (0, ))
ans = list(ans.values())
ans.sort()
print(*ans, sep='\n')


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

signed main() {
  int x; cin>>x;
  if(400<=x && x<=599)
    cout<<8<<endl;
  else if(600<=x && x<=799)
    cout<<7<<endl;
  else if(800<=x && x<=999)
    cout<<6<<endl;
  else if(1000<=x && x<=1199)
    cout<<5<<endl;
  else if(1200<=x && x<=1399)
    cout<<4<<endl;
  else if(1400<=x && x<=1599)
    cout<<3<<endl;
  else if(1600<=x && x<=1799)
    cout<<2<<endl;
  else if(1800<=x && x<=1999)
    cout<<1<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

int ans, n, m, to[N], qnt, passei[N];
vector<int> g[N];
void bfs(int no){

    queue<int> q;
    q.push(no);
    passei[no] = 1;
    qnt++;
    while(!q.empty()){
        no = q.front();
        q.pop();
        for(int x:g[no]){
            if(passei[x])continue;
            passei[x] = 1;
            to[x] = no;
            qnt++;
            q.push(x);
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    scanf("%d %d", &n, &m);
    for(int a,b,i=1;i<=m;++i){
        scanf("%d %d", &a, &b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    bfs(1);
    if(qnt != n) printf("No\n");
    else{
        printf("Yes\n");
        for(int i=2;i<=n;i++){
            printf("%d\n", to[i]);
        }
    }
}

Measured memory_bytes: 13356
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string s;cin >> s;
    deque<char> ans;

    rep(i,s.size()){
        if(ans.size() == 0 && s[i] == 'B')continue;
        else if(s[i] == 'B'){
            ans.pop_back();
        }
        else if(s[i] == '0'){
            ans.push_back('0');
        }
        else if(s[i] == '1'){
            ans.push_back('1');
        }
    }


    for(auto t : ans){
        cout << t;
    }

    cout <<  endl;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.length();

  auto is_kaibun = [](const string& str) {
    string comp = str;
    reverse(comp.begin(), comp.end());
    return str == comp;
  };

  if (!is_kaibun(s)) {
    cout << "No" << endl;
    return 0;
  }

  string sub1 = s.substr(0, (n - 1) / 2);
  if (!is_kaibun(sub1)) {
    cout << "No" << endl;
    return 0;
  }

  string sub2 = s.substr((n + 3) / 2 - 1);
  if (!is_kaibun(sub2)) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

bool Check( int N , int pos )  { return (bool)( N & ( 1 << pos ) );}

vector < pair <int,int> > V[20];
int n;

bool ok( vector <int> &h ) {
        set <int> S;
        for( auto x : h ) S.insert( x );
        for( auto x : h ) {
                for( int i = 0; i < V[x].size(); i++ ) {
                        int xx = V[x][i].first , yy = V[x][i].second;
                        if( yy == 1 ) {
                                if( S.find( xx ) == S.end() ) return false;
                        }
                        else {
                                if( S.find( xx ) != S.end() ) return false;
                        }
                }
        }
        return true;
}
int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n;
        for( int i = 0; i < n; i++ ) {
                int k;
                cin >> k;
                for( int j = 1; j <= k; j++ ) {
                        int x , y;
                        cin >> x >> y;
                        V[i].push_back( {x - 1,y} );
                }
        }
        int ans = 0;
        for( int i = 0; i < ( 1 << n ); i++ ) {
                vector <int> h;
                for( int j = 0; j < n; j++ ) {
                        if( Check( i , j ) ) {
                                h.push_back( j );
                        }
                }
                if( ok( h ) ) {
                        ans = max( ans , (int)h.size() );
                        //for( auto x : h ) cout << x << " "; cout << endl;
                }
        }
        cout << ans << endl;
        return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 100001
#define ll long long
using namespace std;

ll ab(ll x, ll y){
    if (x<0) x*=-1;
    if (y<0) y*=-1;
    return max(x,y);
}

ll mn(ll x, ll y){
    if (x<0) x*=-1;
    if (y<0) y*=-1;
    return min(x,y);
}

int main(){
    ll n,k;
    cin>>n>>k;
    ll data[n];
    for (ll i=0; i<n; i++){
        cin>>data[i];
    }
    
    vector<ll> num;
    for (ll i=0; i<n-k+1; i++){
        if (data[i]*data[i+k-1]>=0) num.push_back(ab(data[i],data[i+k-1]));
        else{
            ll p=mn(data[i],data[i+k-1])*2+ab(data[i],data[i+k-1]);
            num.push_back(p);
        }
    }
    
    sort(num.begin(),num.end());
    
    cout<<num[0]<<endl;
}

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int digits(int n, int k) {
  int cnt = 0;
  while(n > 0) {
    n /= k;
    cnt++;
  }
  return cnt;
}

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

  int N, K;
  cin >> N >> K;
  cout << digits(N, K) << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws IOException {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			String W = in.readLine();

			double R= Integer.parseInt(W.split(" ")[0]);


         System.out.println(R*2*3.14159);
	}

}


Measured memory_bytes: 33256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	string s,t;cin >> s >>t ;
	int n = s.size();
	int m = t.size();
	int ret = 1e18;
	for(int i = 0;i+m <= n;i++){
		int tmp = 0;
		for(int j = i;j < i+m ;j++){
			tmp += s[j] != t[j-i];
		}
		ret = min(ret,tmp);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  vector<int> a(n),b(n),c(n-1);
  for(int i = 0; i < n; i++) cin >> a[i],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 = 0;
  for(int i = 0; i < n; i++){
    ans += b[a[i]];
    if(i > 0 && a[i]-a[i-1] == 1) ans += c[a[i-1]];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define ABS(Value) ((Value < 0) ? (Value * -1) : (Value))


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int N;
	int *A;
	int max_diff;
	int current;
	int i;
	int j;

	scanf("%d", &N);
	A = (int *)malloc(sizeof(int) + N);
	if (!A){
		printf("malloc error\n");
		return (0);
	}
	i = 0;
	while (i < N){
		scanf("%d", &A[i]);
		i++;
	}
	max_diff = 0;
	i = 0;
	while (i < N - 1){
		j = i + 1;
		while (j < N){
			current = A[i] - A[j];
			if (ABS(current) > max_diff){
				max_diff = ABS(current);
			}
			j++;
		}
		i++;
	}
	printf("%d\n", max_diff);
	free(A);
	return (0);
}


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

int main() {
  int H, W;
  string C;
  cin >> H >> W;
  
  for (int i = 0; i < W + 2; i++) {
    C += '#';
  }
  cout << C << endl;
  
  for (int i = 0; i < H; i++) {
    string B;
    cin >> B;
    B = '#' + B + '#';
    cout << B << endl;
  }
  cout << C << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


int main() {
    int N; cin>>N;
    vector<int> a(N);

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

    ll ans=0ll,cnt=0ll;

    for (int i = 0; i < N; ++i) {
        if(a[i]>0ll){
            cnt+=(ll)a[i];
        }else{
            ans+=(ll)cnt/2;
            cnt=0ll;
        }
    }

    ans+=(ll)cnt/2;

    cout<<ans<<endl;

    return 0;
}

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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int res = 0; //求める答え

    for(int a=0; a<=A; ++a){
        for(int b=0; b<=B; ++b){
            for(int c=0; c<=C; ++c){
                int x = 500*a + 100*b + 50*c;
                if (x == X) ++res;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
    print(0)
else:
    a.sort(reverse=True)
    ans = 1
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print("-1")
            break
    else:
        print(ans)


Measured memory_bytes: 21788
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
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 IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int X, Y, N;
	cin >> X >> Y >> N;
	int X0 = 0;
	int Y0 = 0;
	int X1 = X;
	int Y1 = Y;
	for (int i = 0; i < N; ++i) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			X0 = max(X0,x);
		}
		if (a == 2) {
			X1 = min(X1,x);
		}
		if (a == 3) {
			Y0 = max(Y0,y);
		}
		if (a == 4) {
			Y1 = min(Y1,y);
		}
	}
	if (X0 > X1 || Y0 > Y1) {
		cout << 0 << endl;
		return;
	}
	else {
		int res = (X1 - X0) * (Y1 - Y0);
		cout << res << endl;
	}

}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1<<30
#define LINF 1LL<<60
ll dp[105][105][505];
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll n;
	while (cin >> n, n) {
		vector<ll> p(n);
		for (int i = 0; i < n;i++) cin >> p[i];
		/* dp[N][500yen cnt][1000yen cnt] := cost */
		for (int i = 0; i < 105;i++)for (int j = 0; j < 105;j++)for (int k = 0; k < 505;k++)dp[i][j][k] = INF;
		dp[0][0][0] = 0;

		for (int i = 0; i < n;i++) {
			for (int j = 0; j < 105;j++) {
				for (int k = 0; k < 505;k++) {
					if (dp[i][j][k] == INF)continue;

					int coin = 1000 * k - dp[i][j][k] - 500 * j;
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);

					/*cout << i << " " << j << " " << k << endl;
					cout << dp[i][j][k] << " " << p[i] << endl;
					cout << coin << endl;
					cout << "---------------------------------" << endl;*/

					int x = p[i] + 500;
					int th = x / 1000;
					int c = x % 1000;
					if (coin >= c) {
						dp[i + 1][j + 1][k + th] = min(dp[i + 1][j + 1][k + th], dp[i][j][k] + p[i]);
					}

					th = p[i] / 1000;
					if (p[i] % 1000 != 0)th++;
					c = 1000 * th - p[i];
					if (c >= 500) {
						dp[i + 1][j + 1][k +th] = min(dp[i + 1][j + 1][k + th], dp[i][j][k] + p[i]);
					}
					else {
						dp[i + 1][j][k + th] = min(dp[i + 1][j][k + th], dp[i][j][k] + p[i]);
					}
				}
			}
		}
		ll ans1, ans2 = INF;
		for (int i = 104; i >= 0;i--) {
			bool f = false;
			for (int j = 504; j >= 0; j--) {
				if (dp[n][i][j] == INF)continue;
				if (!f) { ans1 = i; f = true; }
				ans2 = min(ans2, dp[n][i][j]);
			}
			if (f)break;
		}
		cout << ans1 << " " << ans2 << endl;
	}
	return 0;
}

Measured memory_bytes: 46612