akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin>>N;
  
  int count=0;
  for(int i=1;i<=N;i++){
    if(((int)log10((double)i))%2==0){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
i = gets.chop
#keyence
flg = false
if i[0] == "k" then
    if i[-6..-1] == "eyence"
    flg = true
    end
end
if i[0..1] == "ke" then
    if i[-5..-1] == "yence"
    flg = true
    end
end
if i[0..2] == "key" then
    if i[-4..-1] == "ence"
    flg = true
    end
end
if i[0..3] == "keye" then
    if i[-3..-1] == "nce"
    flg = true
    end
end
if i[0..4] == "keyen" then
    if i[-2..-1] == "ce"
    flg = true
    end
end
if i[0..5] == "keyenc" then
    if i[-1] == "e"
    flg = true
    end
end
if i == "keyence" then
    flg = true
end

if flg then
    puts "YES"
else
    puts "NO"
end


Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<numeric>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	lli n, x; cin >> n >> x;
	vector<int> a(n*2), m(n, IINF);
	rep(i, n){
		cin >> a[i];
		a[i+n] = a[i];
	}
	lli ans = LINF;
	
	rep(i, n){
		rep(j, n) m[j] = min(m[j], a[j+n-i]);
		ans = min(ans, accumulate(m.begin(), m.end(), 0LL) + x*i);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define fi first
#define se second
using namespace std;
const int N=2e5+10;
int n,a[N];map<int,int> mp;
bool check(int x){
    mp.clear();
    rep(i,1,n) if(a[i]<=a[i-1]){
        while(!mp.empty()){
            int x=mp.rbegin()->fi;
            if(x<=a[i]) break;mp.erase(x);
        }int p=a[i];
        while(mp[p]+1==x) mp.erase(p--);
        if(!p) return 0;mp[p]++;
    }
    return 1;
}
int main(){
    scanf("%d",&n);bool t=1;
    rep(i,1,n) scanf("%d",a+i),t&=a[i-1]<a[i];
    if(t) return puts("1"),0;
    int l=2,r=n-1,ans=n;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",ans);
    return 0;
}

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

class UnionFind
{
  public:
    vector<long long> root;

    UnionFind(long long N)
    {
        root = vector<long long>(N + 1, -1);
    }

    long long find_root(long long A)
    {
        if (root[A] < 0)
        {
            return A;
        }
        else
        {
            root[A] = find_root(root[A]);
        }
        return root[A];
    }

    long long size(long long A)
    {
        return -root[find_root(A)];
    }

    bool unite(long long A, long long B)
    {
        A = find_root(A);
        B = find_root(B);
        if (A == B)
        {
            return false;
        }

        if (size(A) < size(B))
        {
            swap(A, B);
        }

        root[A] += root[B];
        root[B] = A;

        return true;
    }

    bool has_same_root(long long A, long long B)
    {
        return find_root(A) == find_root(B);
    }
};

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

    UnionFind road(N);
    int p, q;
    for (int i = 0; i < K; i++)
    {
        cin >> p >> q;
        road.unite(p, q);
    }

    UnionFind rail(N);
    int r, s;
    for (int i = 0; i < L; i++)
    {
        cin >> r >> s;
        rail.unite(r, s);
    }

    map<pair<long long, long long>, long long> count;
    for (long long i = 1; i <= N; i++)
    {
        count[{road.find_root(i), rail.find_root(i)}]++;
    }

    for (long long i = 1; i <= N; i++)
    {
        cout << count[{road.find_root(i), rail.find_root(i)}] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 15104
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1+M)]

es = [[] for _ in range(N)]
indeg = [0] * N
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    indeg[b] += 1

from collections import deque
q = deque()
for i in range(N):
    if indeg[i] == 0:
        q.append(i)

ans = [0] * N
while q:
    v = q.popleft()
    for to in es[v]:
        indeg[to] -= 1
        if indeg[to] == 0:
            q.append(to)
            ans[to] = v+1
print(*ans, sep='\n')

Measured memory_bytes: 42412
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

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

class A {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
        for (int i = 1; i < 6; i++) {
            int n;
            cin>>n;
            if (n!=i) cout<<i;
        }
	}
};

#undef int
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    A solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3600
import java.util.*;


public class Main {
	
	
	
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for(int i=0;i<n;i++)h[i] = sc.nextInt();
		sc.close();
		int t[] = new int[n];
		
		int max = 0;
		for(int i=0;i<n;i++) max = Math.max(h[i], max);
		
		int cnt = 0;
		for(int i=0;i<max;i++) {

			boolean minus = false;
			for(int j=0;j<n;j++) {
				if(t[j]<h[j]) {
					if(!minus) {
						cnt++;
					}
					minus = true;
					t[j]++;
				}
				else {
					minus = false;
				}
			}
			
		}
		System.out.println(cnt);
		
	}
	

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <math.h>
 
int main()
{
    int n;
    double x1, x2, x3, y1, y2, y3, r, Px, Py;
    
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
        Px = ((y2-y3)*(x1*x1+y1*y1) + (y3-y1)*(x2*x2+y2*y2) + (y1-y2)*(x3*x3+y3*y3))/(2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)));
        Py = ((x2-x3)*(x1*x1+y1*y1) + (x3-x1)*(x2*x2+y2*y2) + (x1-x2)*(x3*x3+y3*y3))/(2*(y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2)));
        r = sqrt((x1-Px)*(x1-Px)+(y1-Py)*(y1-Py));
        printf("%.3lf %.3lf %.3lf\n",Px, Py, r);
    }
    return 0;
}



Measured memory_bytes: 2572
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
preS = sum(A[:-1])
num = 0
for i in range(N - 1, 0, -1):
    if 2 * preS < A[i]:
        num = i
    else:
        preS -= A[i - 1]
print(N - num)

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

int main()
{
  int a,b;

  for(;cin>>a>>b,a||b;)
    {
      int x[3]={0,0,0};
      int num=b-a;
      for(;num>=1000;)
	{
	  num-=1000;
	  x[2]++;
	}
      for(;num>=500;)
	{
	  num-=500;
	  x[1]++;
	}
      for(;num>=100;)
	{
	  num-=100;
	  x[0]++;
	}
      cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;
    }
}

Measured memory_bytes: 1160
S_dash = list(input())
M = len(S_dash)

T = list(input())
N = len(T)

match = [False for _ in range(M)]

last_match = -100
for i in range(M - N + 1):
    for j in range(N):
        if S_dash[i+j] == "?":
            continue
        elif S_dash[i+j] == T[j]:
            continue
        elif S_dash[i+j] != T[j]:
            break
    else:
        match[i] = True
        last_match = i
S = S_dash.copy()

if last_match == -100:
    print("UNRESTORABLE")
else:
    for i in range(N):
        S[last_match+i] = T[i]
    for i in range(M):
        if S[i] == "?":
            S[i] = "a"
    print("".join(str(x) for x in (S)))

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a,b;
  cin >> a >> b;
  a--;
  b--;
  REP(i, 3){
    if(a != i && b != i)
      cout << i+1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b;
    char c,g;
    cin >> a >> c >> b;
    cout << (c == '+' ? a + b :a - b) << endl;
}



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

using namespace std;

int main()
{
	int n, y;
	cin >> n >> y;
	int i, j, k = 0;
	i = j = k = -1;
	for (int a = 0; a <= 2000; a++)
	{
		int b = y/1000 - 9*a - n;
		if (b < 0 || b % 4 != 0) continue;
		b /= 4;
		int c = n - a - b;
		if (c >= 0)
		{
			i = a;
			j = b;
			k = c;
			break;
		}
	}
	cout << i << " " << j << " " << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,l;
string a[105];
int main()
{
    cin>>n>>l;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    cout<<a[i];
    cout<<endl;
    return 0;
}

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


int main(){
    ll n,a,b,c,d,e;
    cin >> n >> a>>b >>c >> d>>e;
    vector<ll>box(6);
    rep(i,6)box[i]=0;
    box[0]=n;
    ll cnt=0;
    
    cout<< (ll)ceil((double)n/min({a,b,c,d,e}))+4 << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        int H = ScanInt(), W = ScanInt();
        var a = new List<string>();
        for (int i = 0; i < H; i++) {
            var isAllWhite = true;
            var line = Scan();
            for (int j = 0; j < W; j++) {
                if (line[j] == '.') continue;
                isAllWhite = false;
                break;
            }
            if (!isAllWhite) a.Add(line);
        }
        var span = a.AsSpan();
        for (int i = 0; i < W; i++) {
            var isAllWhite = true;
            foreach (var s in span) {
                if (s[i] == '.') continue;
                isAllWhite = false;
                break;
            }
            if (!isAllWhite) continue;
            for (int j = 0; j < span.Length; j++) {
                span[j] = new StringBuilder(span[j][..i]).Append(span[j][(i + 1)..]).ToString();
            }
            i--;
            W--;
        }
        foreach (var line in span) {
            Console.WriteLine(line);
        }
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = ArrayPool<byte>.Shared.Rent(1024);
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) ConsoleIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}

class DList<T>
{
    public T[] Items;
}

static class ListExtensions
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Span<T> AsSpan<T>(this List<T> list) {
        return Unsafe.As<DList<T>>(list).Items.AsSpan(0, list.Count);
    }
}

Measured memory_bytes: 25880
#include <iostream>
#include <algorithm>
#include <stdlib.h> 
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, s;
int A[MAX], B[MAX], T[VMAX + 1]; //"+ 1" is important.

int solve()
{
	int ans = 0;
	
	bool V[MAX];
	for(int i = 0; i < n; i++)
	{
		B[i] = A[i];
		V[i] = false;
	}
	
	sort(B, B+n);
	
	//Build a map from value to ideal order. 
	for(int i = 0; i < n; i++) T[B[i]] = i;
	//Tranverse.
	for(int i = 0; i < n; i++)
	{
		if(V[i]) continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while(1)
		{
			V[cur] = true;
			an++; 
			int v = A[cur];
			m = min(v, m);
			S += v;
			cur = T[v];
			if(V[cur]) break;
		}
		ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
	}
	
	return ans;
}
int main() {
	
	cin >> n;
	s = VMAX;
	for( int i = 0; i < n; i++)
	{
		cin >> A[i];
		s = min(s, A[i]);
	}
	
	int ans = solve();
	cout << ans << endl;
	
//	system("pause");
	return 0;
}


Measured memory_bytes: 3164
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] k = new int[n];
        for (int i=1;i<n;i++){
            for (int j=i+1;j<=n;j++){
                k[Math.min(Math.abs(j-i),Math.min(Math.abs(x-i)+1+Math.abs(j-y),Math.abs(y-i)+1+Math.abs(j-x)))]++;
            }
        }
        for (int i=1;i<n;i++)System.out.println(k[i]);
    }
}


Measured memory_bytes: 36640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<ll, ll> P;
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    ll ans = 1e18;
    for (ll i = 0; i < n; i++)
    {
        multiset<ll> b;
        ll s = m * i;
        for (ll j = 1; j <= i; j++)
        {
            b.insert(v[n - j]);
        }
        rep(j, n)
        {
            b.insert(v[j]);
            s += *b.begin();
            b.erase(b.find(v[(j - i + n) % n]));
        }
        ans = min(ans, s);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    int max;
    int min;
    if(a>b) max=b;
    else max=a;
    if(a+b>=n) min=a+b-n;
    else min=0;
    printf("%d %d\n",max,min);
}

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

int D;

int main(){

	int D;
	cin >> D;

	if (D == 25)
		cout << "Christmas" << endl;
	else if (D == 24)
		cout << "Christmas Eve" << endl;
	else if (D == 23)
		cout << "Christmas Eve Eve" << endl;
	else if (D == 22)
		cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

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

using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;

int main() {
	int n,m;
	cin>>n>>m;
	int a[35]={0};
	for(int i=0;i<n;i++){
	    int k;
	    cin>>k;
	    for(int j=0;j<k;j++){
	        int x;
	        cin>>x;
	        a[x]++;
	    }
	}
	int count=0;
	for(int i=1;i<=30;i++){
	    if(a[i]==n)
	    count++;
	}
	cout<<count;
	return 0;
}

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

typedef long long LL;

using namespace std;

int main() {
	LL N, A, B;
	cin >> N >> A >> B;
	LL minimum = A*(N - 1) + B;
	LL maximum = B * (N - 1) + A;
	LL answer = maximum - minimum + 1;
	if (A > B || N == 1 && A != B) {
		answer = 0;
	}
	cout << answer << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}


int main() {
  
  long long n, k; cin >> n >> k;
  long long ans = 0;

  for (long long i = k; i <= n+1; i++) {
    ans += (-1)*i*i + n*i + i + 1;
    ans %= MOD;
  }
  cout << ans << endl;

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[25],b[25],c[25];

int main()
{
	boost
	ll n,i,sum=0;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>arr[i];
	for(i=1;i<=n;i++)
		cin>>b[i];
	for(i=1;i<n;i++)
		cin>>c[i];
	sum=b[arr[0]];
	//debug(sum);
	for(i=1;i<n;i++)
	{
		sum+=b[arr[i]];
		//cout<<sum<<"\n";
		if(arr[i-1]+1==arr[i])
			sum+=c[arr[i]-1];
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 998244353;

long long pow_mod(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = (res * a) % mod;
		n >>= 1;
		a = (a * a) % mod;
	}
	return res;
}

long long inverse_mod(long long a, long long mod) {
	long long b = mod, x = 1, u = 0;
	while (b != 0) {
		long long r = a % b, q = a / b;
		a = b; b = r;
		int nu = x - q*u;
		x = u; u = nu;
	}
	x %= mod;
	if (x < 0) x += mod;
	return x;
}

int primitive_root(int m) {
	if (m == 167772161) return 3;
	if (m == 469762049) return 3;
	if (m == 754974721) return 11;
	if (m == 924844033) return 5;
	if (m == 998244353) return 3;
	if (m == 1012924417) return 3;
	if (m == 1224736769) return 3;
	return 1;
}

template<int MOD> int ntt_aux(vector<long long> &v, bool inverse) {
	static bool first = true;
	static vector<long long> principal_root(32);
	static vector<long long> principal_root_inv(32);
	if (first) {
		first = false;
		const int p = primitive_root(MOD);
		const int cycle = MOD - 1;
		int x = 0;
		while (cycle % (1<<x) == 0) x++;
		long long a = pow_mod(p, cycle / (1<<(x-1)), MOD);
		long long a_inv = inverse_mod(a, MOD);
		for (int i = x-1; i >= 0; i--) {
			principal_root[i] = a;
			a = a * a % MOD;
			principal_root_inv[i] = a_inv;
			a_inv = a_inv * a_inv % MOD;
		}
	}

	const int n = v.size(), half = n >> 1;
	if (n == 1) return 0;
	vector<long long> v0(half), v1(half);
	for (int i = 0; i < half; i++) {
		v0[i] = v[2*i];
		v1[i] = v[2*i + 1];
	}
	const int size = ntt_aux<MOD>(v0, inverse) + 1;
	ntt_aux<MOD>(v1, inverse);
	const long long alpha = inverse ? principal_root_inv[size] : principal_root[size];
	long long alpha_i = 1;
	for (int i = 0; i < n; i++) {
		v[i] = (v0[i % half] + v1[i % half] * alpha_i % MOD) % MOD;
		alpha_i = alpha_i * alpha % MOD;
	}
	return size;
}

template<int MOD> vector<long long> convolution(const vector<long long> &a, const vector<long long> &b) {
	if (a.size() == 0 || b.size() == 0) return {};
	const int size = a.size() + b.size() - 1;
	int n = 1;
	while (size > n) n <<= 1;
	vector<long long> ta(a), tb(b);
	for (long long &e : ta) e %= MOD;
	for (long long &e : tb) e %= MOD;
	ta.resize(n, 0);
	tb.resize(n, 0);
	ntt_aux<MOD>(ta, false);
	ntt_aux<MOD>(tb, false);
	for (int i = 0; i < n; i++) {
		ta[i] = ta[i] * tb[i] % MOD;
	}
	ntt_aux<MOD>(ta, true);
	ta.resize(size);
	const long long n_inv = inverse_mod(n, MOD);
	for (long long &e : ta) e = e * n_inv % MOD;
	return ta;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<long long> a(n), b(m);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < m; i++) {
		scanf("%lld", &b[i]);
	}
	auto c = convolution<MOD>(a, b);
	for (int i = 0; i < c.size(); i++) {
		printf("%lld", c[i]);
		if (i < c.size()-1) printf(" ");
		else cout << endl;
	}
	return 0;
}

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

using namespace std;


int frog(int* a,int i,int n,int* dp){
    if(n<=i){
        return 0;
    }
    if(dp[i]!=-1) return dp[i];    
    int o1,o2;
    o1=o2=INT_MAX;
    
    o1=frog(a,i+1,n,dp)+(i+1<n?abs(a[i+1]-a[i]):0);

    o2=frog(a,i+2,n,dp)+(i+2<n?abs(a[i+2]-a[i]):abs(a[n]-a[i]));

    dp[i]=min(o1,o2);
    return min(o1,o2);

}

int main() {

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int dp[n];
    memset(dp,-1,sizeof(dp));
    
   cout<<frog(a,0,n,dp);

}



Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define mo 1000000007
#define maxn 200005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int h,w,a,b,ans;
int jc[maxn],inv[maxn];
inline int C(int x,int y)
{
    if(x<y)return 0;
    return 1ll*jc[x]*inv[y]%mo*inv[x-y]%mo;
}
int main()
{
    h=read(),w=read();a=read(),b=read();
    reg int i;jc[0]=inv[0]=inv[1]=1;
    for(i=1;i<=200000;++i)jc[i]=1ll*jc[i-1]*i%mo;
    for(i=2;i<=200000;++i)inv[i]=1ll*inv[mo%i]*(mo-mo/i)%mo;
    for(i=2;i<=200000;++i)inv[i]=1ll*inv[i]*inv[i-1]%mo;
    ans=C(h+w-2,h-1);
    for(i=h-a+1;i<=h;++i)
        ans=(ans-1ll*C(i+b-2,i-1)*C(h-i+w-b-1,h-i)%mo+mo)%mo;
    cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(){
	int size;
	int num[100];
	int flag = 1;
	scanf("%d", &size);
	for(int i=0; i<size; i++){
		scanf("%d", &num[i]);
	}

	for(int i=0; i<size; i++){
		if(num[i] % 2 ==0){
			if(num[i] % 3 != 0 && num[i] % 5 != 0) flag = 0; 
		}
	}

	if(flag == 0)puts("DENIED");
	else puts("APPROVED");

	return 0;
}


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

#define mod 1000000007LL
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res + m) * ( a + m) % m;
        a = a * a % m;
        b >>= 1;
    }
    return (res + m) % m;
}

long long mul(long long a, long long b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return ((a + mod) * (b + mod))%mod;
}
long long add(long long a, long long b){
    a += mod;
    b += mod;
    return (a + b)%mod;
}
ll inv(ll x){
    return binpow(x, mod - 2, mod);
}
int main(){

    string s;cin>>s;
    int ans = 0;
    for(int i = 0, j ;i<s.length();i = j){
        if(s[i] == 'S')j = i + 1;
        else{
            int cnt = 0;
            j = i;
            while(j < s.length() && s[j] == 'R')
                cnt++, j++;
            ans = max(ans, cnt);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3592
package main

import (
  "fmt"
  "strconv"
)

func HarshadNumber(s string) int {
  ret := 0
  for i := 0; i < len(s); i++ {
    num, _ := strconv.Atoi(string(s[i]))
    ret += num
  }
  return ret
}

func main() {
  var N string
  fmt.Scanf("%s", &N)

  ret := HarshadNumber(N)
  NN, _ := strconv.Atoi(N)

  if NN % ret == 0 {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}


Measured memory_bytes: 512
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans = B[A[0]-1]
for i in range(1, N):
    if A[i-1] + 1 == A[i]:
        ans += C[A[i-1]-1]
    ans += B[A[i] - 1] 
print(ans)

Measured memory_bytes: 61696
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] < a[i + 1]) ans++;
	}
	cout << n - ans << endl;
	cout << n << endl;
}


Measured memory_bytes: 3632
a=input()
b=len(a)
c=0
s=0
m=0
while c<b:
    if a[c]=='R':
    	s=s+1
    	if m<s:
      		m=s
    if a[c]=='S':
      
      s=0
    c=c+1
print(m)
  

Measured memory_bytes: 9036
A = [ int(input()) for _ in range(5) ]

modMax, index = 0, 0
for i in range(5):
    if A[i]%10 != 0 and modMax < 10-A[i]%10:
        modMax = 10-A[i]%10
        index = i

ans = 0
for i in range(5):
    if i == index: ans += A[i]
    elif A[i]%10 != 0: ans += A[i] + 10-A[i]%10
    else: ans += A[i]

print( ans )


Measured memory_bytes: 3060
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")



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

using namespace std;

//#define FILE_IO

typedef long long LL;

LL K;
LL ans = 0;

map <int, int> mp;
vector <int> v;

vector <long long> coef[] = {
    {},
    {},
    {1LL},
    {11LL},
    {111LL, 10LL},
    {1111LL, 110LL},
    {11111LL, 1110LL, 100LL},
    {111111LL, 11110LL, 1100LL},
    {1111111LL, 111110LL, 11100LL, 1000LL},
    {11111111LL, 1111110LL, 111100LL, 11000LL},
    {111111111LL, 11111110LL, 1111100LL, 111000LL, 10000LL},
    {1111111111LL, 111111110LL, 11111100LL, 1111000LL, 110000LL},
    {11111111111LL, 1111111110LL, 111111100LL, 11111000LL, 1110000LL, 100000LL},
    {111111111111LL, 11111111110LL, 1111111100LL, 111111000LL, 11110000LL, 1100000LL},
    {1111111111111LL, 111111111110LL, 11111111100LL, 1111111000LL, 111110000LL, 11100000LL, 1000000LL},
    {11111111111111LL, 1111111111110LL, 111111111100LL, 11111111000LL, 1111110000LL, 111100000LL, 11000000LL},
    {111111111111111LL, 11111111111110LL, 1111111111100LL, 111111111000LL, 11111110000LL, 1111100000LL, 111000000LL, 10000000LL},
    {1111111111111111LL, 111111111111110LL, 11111111111100LL, 1111111111000LL, 111111110000LL, 11111100000LL, 1111000000LL, 110000000LL},
    {11111111111111111LL, 1111111111111110LL, 111111111111100LL, 11111111111000LL, 1111111110000LL, 111111100000LL, 11111000000LL, 1110000000LL, 100000000LL},
    };

void bck(int pas, LL num, LL cnt, vector<LL> cf)
{
    if(pas >= cf.size())
    {
        if(num == K)    ans += cnt;
        return;
    }

    int st = -9, dr = 9;
    if(pas == 0)    st = -8, dr = 8;

    for(int i = st; i <= dr; i++)
    {
        LL newnum = num + (1LL * i * cf[pas]);
        LL newcnt = 9 - abs(i) + 1;
        if(pas == 0)    newcnt--;

        LL maxdif = 0LL;
        for(int i = pas + 1; i < cf.size(); i++)
            maxdif += cf[i];
        maxdif *= 9;

        if(newnum + maxdif < K) continue;
        if(newnum - maxdif > K) continue;

        bck(pas + 1, newnum, 1LL * cnt * newcnt, cf);
    }
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    int N;
    scanf("%d", &N);

    if(N % 9)
    {
        printf("0\n");
        return 0;
    }

    K = N / 9;
    int cif = -1;
    for(auto cf: coef)
    {
        cif++;
        LL cnt = 1LL;
        if(cif & 1)    cnt *= 10LL;
        bck(0, 0LL, cnt, cf);
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
#include <iostream>
#include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define deb(x) cerr << ">>>>>>>>>>>>>>>>>>>> "#x" = " << x << " <<<<<<<<<<<<<<<<<<<<\n"
#define debd(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %d <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define debs(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %s <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define debll(x) fprint(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %lld <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
//bitmask
int onbit(int x, int pos) {x |= (1 << pos); return x;}
int offbit(int x, int pos) {x &= ~(1 << pos); return x;}
int test(int x, int pos) {return x & (1 << pos);}
int flip(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int onbitall(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int k;
char n[123456];
set<int> s;

bool cek(int x) {
	string str = its(x);
	fr(i, 0, str.length()) {
		if(has(s, str[i]-'0')) return false;
	}
	return true;
}

int main() {
//  freopen("input.in", "r", stdin);
	sf("%s %d", n, &k);
	fr(i, 0, k) {
		int qwe;
		sf("%d", &qwe);
		s.insert(qwe);
	}

    int nn = atoi(n);
	fr(i, nn, INT_MAX-1) {
//		deb(i);
		if(cek(i)) {
			pf("%d\n", i);
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	copy_n(istream_iterator<string>(cin), h, a.begin());
	const int inf = numeric_limits<int>::max();
	vector<vector<int>> dist(h, vector<int>(w, inf));
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> q;
	dist[0][0] = 1;
	vector<pair<int, int>> dr{{0, 1}, {1, 0}};
	q.push(tuple<int, int, int>{1, 0, 0});
	while(!q.empty()){
		int d, x, y;
		tie(d, x, y) = q.top();
		q.pop();
		if(d == dist[x][y]){
			for(int t = 0; t < 2; ++ t){
				int dx, dy;
				tie(dx, dy) = dr[t];
				int nx = x + dx, ny = y + dy;
				if(nx < h && ny < w){
					int nd = d + (a[x][y] != a[nx][ny]);
					if(nd < dist[nx][ny]){
						q.push(tuple<int, int, int>{dist[nx][ny] = nd, nx, ny});
					}
				}
			}
		}
	}
	cout << (dist[h - 1][w - 1] + (a[0][0] == '#')) / 2;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m,p,q,r,x,y;
	vector<int>::iterator itx,ity,it;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
		vector<int> v1(1),v2;
		
		for(v1.push_back(r);m--;v2.clear()){
			cin>>x>>y;
			itx=upper_bound(v1.begin(),v1.end(),x);
			ity=upper_bound(v1.begin(),v1.end(),y);
			
//			if( ity-v1.begin()+1 & 1 )v2.push_back(0);
//			v2.push_back(0);
			v2.insert(v2.end(),ity-v1.begin()&1?1:2,0);
			for(it=ity;it!=v1.end();++it)
				v2.push_back(*it - y);
			
			if(v1.end()-itx & 1)v2.push_back(n-y);
			for(it=itx;it!=ity;++it)
				v2.push_back(*it-x+n-y);
			
			it = v1.begin();
			if(ity-v1.begin() & 1)++it;
			if(!it[1])it+=2;
			if(*it+n-x==v2.back())++it,v2.pop_back();
			for(;it!=itx;++it)
				v2.push_back(*it+n-x);
			
			v1.swap(v2);
		}
		v1.insert( upper_bound(v1.begin(),v1.end(),p-1), 2, p-1);
		v1.insert( lower_bound(v1.begin(),v1.end(),q), q );
		v1.push_back(n);
		it = upper_bound(v1.begin(),v1.end(),p-1);
		if(it-v1.begin() & 1) --it;
		for(x=0;*it<q;++it){
			m=*it,
			x+=*++it-m;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll n; cin >> n;
  vector<ll> hoge(5);
  string s;
  rep_i(i, n){
    cin >> s;
    switch (s[0]){
    case 'M':
      hoge[0]++;
      break;
    case 'A':
      hoge[1]++;
      break;
    case 'R':
      hoge[2]++;
      break;
    case 'C':
      hoge[3]++;
      break;
    case 'H':
      hoge[4]++;
      break;
    default:
      break;
    }
  };
  ll sum = 0;
  for (int i = 0; i < 3; i++){
    for (int a = i + 1; a < 4; a++){
      for (int b = a + 1; b < 5; b++){
        if(hoge[i] == 0 || hoge[a] == 0 || hoge[b] == 0){
          continue;
        }
        sum += hoge[i]*hoge[a]*hoge[b];
      }
    }
  }
  cout << sum << endl;
}

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

using namespace std;

#define nmax 100005
#define oo 1000000007
#define reset(x) memset(x, 0, sizeof (x))
#define s second
#define f first
#define PB(x) push_back(x)
#define Task ""
#define For(i, x, y) for(int i = x; i <= y; i++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vti;
int n,dem=0,par[nmax],xrank[nmax];
ll res=0;
pii x[nmax],y[nmax];
struct ed{
    int u,v,w;
}e[2*nmax];
bool cmp(ed x,ed y){
    return x.w<y.w;
}
void Enter() {
    cin>>n;
    for(int u,v,i=1;i<=n;i++){
        cin>>u>>v;
        x[i]={u,i};
        y[i]={v,i};
        }

}
int root(int u){
    if(par[u]!=u)
        par[u]=root(par[u]);
    return par[u];
}
bool isjoint(int u, int v){
    u=root(u);
    v=root(v);
    if(u==v) return false;
    if(xrank[u]==xrank[v])
        xrank[u]++;
    if(xrank[u]<xrank[v])
        par[u]=v;
    else
        par[v]=u;
    return true;
}
void Solve() {
    sort(x+1,x+n+1);
    sort(y+1,y+n+1);
    for(int i=1;i<n;i++)
        e[++dem]={ x[i].s , x[i+1].s,abs(x[i].f-x[i+1].f)};
    for(int i=1;i<n;i++)
        e[++dem]={y[i].s,y[i+1].s,abs(y[i].f-y[i+1].f)};
    sort(e+1,e+dem+1,cmp);
    for(int i=1;i<n;i++)
        par[i]=i,xrank[i]=0;
    for(int i=1;i<=dem;i++)
    {
        if(isjoint(e[i].u,e[i].v))
            res+=e[i].w;
    }
    cout<<res;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    Enter();
    Solve();
}


Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
    int a,b,c,k,j;

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

    for( j = 0;a >= b || b >= c;j ++){
        if(a >= b){
            b = b*2;
        }else if(b >= c){
            c = c *2;
        }
    }
    if(j <= k){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;



    
}

Measured memory_bytes: 1664
i = list(map(int, input().split()))
n = i[0]
k = i[1]
str = input()
hoge = ""

for m in range(n):
  if m == k-1:
    hoge = hoge + str[m].lower()
  else:
    hoge = hoge + str[m]
  
print(hoge)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x; cin >> x;
  for(int i = 1; i < 10; i++){ 
   if( x%i == 0 && x/i <= 9){ cout << "Yes" << endl; return 0;
                }
    
  }
  cout << "No" << endl; return 0;
}

Measured memory_bytes: 256
from numpy import *
N = int(input())
A = array([list(map(int,input().split())) for n in range(N)])

fill_diagonal(A, 10**10)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    d = min(A[i]+A[j])
    if A[i][j] < d:
      ans += A[i][j]
    elif d < A[i][j]:
      print(-1)
      exit()

print(ans)


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

int n;
int A[100001];

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    
    while(left < right){
        mid = (right + left)/2;
        if(A[mid] == key){
            return 1;
        }else if(A[mid] < key){
            left = mid + 1;
        }else if(A[mid] > key){
            right = mid;
        }    
    }
    
    return 0;
}

int main(){
    //int A[100001];
    int m, key;
    int sum = 0;
    
    scanf("%d",&n);
    for(int i = 0;i < n; i++) scanf("%d",&A[i]);
    scanf("%d",&m);
    
    for(int i = 0;i < m; i++){
        scanf("%d",&key);
        if(binarySearch(key)) sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

void BFS(vvll &g,vll &cnt,int n,queue<int> &q){
	int d = cnt.at(n) ;
	for(int i=0;i<g.at(n).size();i++){
		if(cnt.at(g.at(n).at(i))>d+1){
			cnt.at(g.at(n).at(i)) = d+1 ;
			q.push(g.at(n).at(i)) ;
		}
	}
	if(q.empty()) return ;
	n = q.front() ; q.pop() ;
	BFS(g,cnt,n,q) ;
}

int main(){
	ll n ; cin >> n ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<n-1;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g.at(a).emplace_back(b) ;
		g.at(b).emplace_back(a) ;
	}
	vll f(n,INF),s(n,INF) ;
	f.at(0) = s.at(n-1) = 0 ;
	queue<int> q ;
	BFS(g,f,0,q) ;
	BFS(g,s,n-1,q) ;
	ll f_cnt,s_cnt ;
	f_cnt = s_cnt = 0 ;
	int d = f.at(n-1) ;
	for(int i=0;i<n;i++){
		if(f.at(i)<=s.at(i)) f_cnt++ ;
		else s_cnt++ ;
	}
	cout << (f_cnt>s_cnt?"Fennec":"Snuke") << endl ;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[300001];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; string s;
    cin >> n >> s;
    for (int i = 1; i <= n; ++i)
    {
        a[i] = (s[i - 1] == 'E');
        a[i] += a[i - 1];
    }
    int sol = 1e9;
    for (int i = 1; i <= n; ++i)
    {
        int e = a[n] - a[i];
        int w = i - 1 - a[i - 1];
        sol = min(sol, e + w);
    }
    cout << sol;
}


Measured memory_bytes: 1812
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int N,T;
char field[10001];
double dp[2001][2001];

double calc(){
    for(int i=T;i>=0;i--){
        for(int j=0;j<N;j++){
            double res=0;
            if(i==T){
                if(field[j]=='R')res=1;
            }
            else{
                for(int k=1;k<=6;k++){
                    int npos=(j+k)%N;
                    res+=dp[i+1][npos]/6.0;
                }
            }
            dp[i][j]=res;
        }
    }
    double res=dp[0][0];
    for(int i=1;i<N;i++)res=max(res,dp[0][i]);
    return res;
}

int main(){

    while(cin>>N>>T&&(N|T)){
        for(int i=0;i<N;i++)cin>>field[i];
        double res=calc();
        printf("%.10f\n",res);
    }

    return 0;
}

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

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7

int main(){
    int n, k, q;
    cin>> n >> k >> q;
    int a[q];
    int sanka[n];
    rep(i, q) cin >> a[i];
    rep(i, n) sanka[i] = k-q;

    rep(i, q){
        sanka[a[i]-1] += 1;
    }

    rep(i, n){
        if(sanka[i]>0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

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

int main(int argc, char const *argv[]) {
    ll n,a,b; cin>>n>>a>>b;
    ll x = a+b;
    ll y = n/x;
    ll z = n-(y*x);
    cout << (a*y)+min(z,a) << '\n';
    return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int X, A, B; cin >> X >> A >> B;
    X -= A;
    while(X - B >= 0) {
        X -= B;
    }
    cout << X << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3648