akhauriyash/Code-Regression huggingface dataset:
use strict;
use warnings;
use List::Util qw/ max /;

my ($n, $m, $k) = glob <>;
my @a = glob <>;
my @b = glob <>;

my @sum_a = ();
my @sum_b = ();

$sum_a[0] = $a[0];
$sum_b[0] = $b[0];

for (1..$n-1) {
    $sum_a[$_] = $sum_a[$_-1] + $a[$_];
}

for (1..$m-1) {
    $sum_b[$_] = $sum_b[$_-1] + $b[$_];
}

my $max_a = scalar grep { $k >= $_ } @sum_a;
my $max_b = scalar grep { $k >= $_ } @sum_b;

my $max = max($max_a, $max_b);
my @memory = ($m-1) x $max_a;

for(my $a_i = 0; $a_i < $max_a; ++$a_i) {
    for(my $b_i = ($a_i > 0) ? $memory[$a_i-1] : $max_b-1; $b_i>= 0; --$b_i) {
        if($k >= $sum_a[$a_i] + $sum_b[$b_i]) {
            $memory[$a_i] = $b_i;
            if ($max < $a_i + $b_i + 2) {
                $max = $a_i + $b_i + 2;
            }
            last;
        }
    }
}

print $max;

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

int main(){
    string s; cin >> s;
    int t[200200];
    int n=0;
    for(int i=0; i<s.size(); i++){
        if(i==s.size()-1){ t[n]=2; n++; }
        else{
            if(s.at(i)=='B' && s.at(i+1)=='C'){
                t[n]=1; i++; n++;
            }
            else if(s.at(i)=='A'){ t[n]=0; n++; }
            else{t[n]=2; n++; }
        }
    }


    long long sum=0;
    int num=0;
    for(int i=0; i<n; i++){
        if(t[i]==0){num++;}
        if(t[i]==1){sum +=num;}
        if(t[i]==2){num=0;}
    }
    cout << sum << endl;
}

Measured memory_bytes: 1412
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

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

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];

  static int dp[110][101010];
  m0(dp);
  dp[0][0] = 1;

  for (int i = 0; i < N; i++) {
    vector<int> sum(K + 10);
    for (int j = 0; j <= K + 1; j++) {
      if (j == 0) {
        sum[j] = dp[0][0];
      } else {
        sum[j] = (sum[j - 1] + dp[i][j - 1]) % MOD;
      }
    }

    for (int k = 0; k <= K; k++) {
      dp[i + 1][k] = (sum[k + 1] - sum[max(0LL, k - a[i])] + MOD) % MOD;
    }
  }

  cout << dp[N][K] << endl;
  return 0;
}


Measured memory_bytes: 87808
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int l,r,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[500000/2+2],b[500000/2+2],c[5000005];
int maxn=1000000001;int sum=0;
void f(int l,int m,int r)
{
    int n1=m-l;
    int n2=r-m;
    for(int i=0;i<n1;i++)
    {
        a[i]=c[l+i];
    }
    for(int i=0;i<n2;i++)
    {
        b[i]=c[m+i];
    }
    a[n1]=maxn;
    b[n2]=maxn;
    for(int i=l,o=0,p=0;i<r;i++)
    {
        sum++;
        if(b[p]>a[o])
        {
            c[i]=a[o++];
        }
        else
        {
            c[i]=b[p++];
        }
    }
}
void fg(int l,int r)
{
    if(l+1<r)
    {
        int m=(l+r)>>1;
        fg(l,m);
        fg(m,r);
        f(l,m,r);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
    }
    fg(0,n);
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
        printf("%d ",c[i]);
        else printf("%d\n",c[i]);
    }
    printf("%d\n",sum);
    return 0;
    }

Measured memory_bytes: 6604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int W,a,b;
    cin >> W >> a >> b;
    if(a+W < b) {cout << b-(a+W) << endl; return 0;}
    else if(b+W < a) {cout << a-(b+W) << endl; return 0;}
    else cout << 0 << endl;
}

Measured memory_bytes: 256
N = int(input())
n = str(N)
n1 = n[-1]
if n1 == "2" or n1 == "4" or n1 == "5" or n1 == "7" or n1 == "9":
    print("hon")
elif n1 == "0" or n1 == "1" or n1 == "6" or n1 == "8":
    print("pon")
elif n1 == "3":
    print("bon")

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  string N;
  cin >> N;
  int ans = 0;
  for (int i=0; i<N.size(); i++) {
    if (N[i]=='2') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {

    int x, y;

    scanf("%d %d", &x, &y);

    int isCheck = 0;

    for (int i = 0; i <= x; i++) {

        int turu = i;
        int kame = x - i;

        int mysum = turu * 2 + kame * 4;

        if (mysum == y) {
            isCheck = 1;
            break;
        }


    }

    printf("%s", (isCheck == 0 ? "No" : "Yes"));


    return 0;
}


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

long long dp[105][100005];
//map <long long,long long> cek[105];
long long weight[105];
long long value[105];
long long z,x;

long long rekur(int a,long long s)
{
	if(a>z)return 0;
	if(dp[a][s]!=0)return dp[a][s];
//	cek[a][s]=1;
	long long temp;
	if(s-weight[a]>=0)
	{
		dp[a][s]=max(value[a]+rekur(a+1,s-weight[a]),rekur(a+1,s));
	}
	else dp[a][s]=rekur(a+1,s);
//	asd[a][s]=temp;
	return dp[a][s];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
//	memset(dp,-1,sizeof(dp));
	cin>>z>>x;
	for(int q=1;q<=z;q++)
	{
		cin>>weight[q]>>value[q];
	}
	long long ans=rekur(1,x);
	cout<<ans<<endl;
}

Measured memory_bytes: 78080
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long gcd(long long a, long long b);

int main()
{
	int n, k;
	cin >> n >> k;
	int mx = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mx = max(mx, a[i]);
	}

	if (mx < k) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		int g = a[0];
		for (int i = 1; i < n; i++) {
			g = gcd(g, a[i]);
		}

		if (k % g == 0) {
			cout << "POSSIBLE" << endl;
		} else {
			cout << "IMPOSSIBLE" << endl;
		}
	}

	return 0;
}

long long gcd(long long a, long long b)
{
	if (a < b) {
		long long t = a;
		a = b;
		b = t;
	}

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

	return b;
}

Measured memory_bytes: 640
import numpy as np
N,M,C=map(int, input().split())
B=np.array(list(map(int, input().split())))
A=[np.array(list(map(int, input().split()))) for _ in range(N)]
c=0
for i in range(N):
  if np.dot(B,A[i])+C>0:
    c+=1
print(c)

Measured memory_bytes: 12424
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, a[200003], k, ans, sum, f[1000003][2];
char s[1000003];

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	scanf("%s", s + 1);
	n = strlen(s + 1), s[0] = '0';
	f[n + 1][0] = 0, f[n + 1][1] = 100;
	for (int i = n; i >= 0; i-=1) 
	{
		int u = s[i] - '0' ; 
		f[i][1] = min(f[i + 1][1] - u - 1, f[i + 1][0] - u) + 10;
		f[i][0] = min(f[i + 1][1] + u + 1, f[i + 1][0] + u);
	}
	cout << f[0][0] << endl;
	return 0;
}


Measured memory_bytes: 16896
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int a, b, d, r;
	long double f;
	cin >> a >> b;
	d = floor(a / b);
	r = a%b;
	f = (long double)a / b;
	printf("%d %d %LF", d, r, f);
	cin >> a;
}

Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, count=0, k, max, key;
	
	cin >> N;
	
	max = 0;
	key = 1;
	
	for(int i=2; i<=N; i++){
		k = i;
		count = 0;
		while(k%2 == 0){
			count++;
			k /= 2;
		}
		if(count > max){
			max = count;
			key = i;
		}
	}
	
	cout << key;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;

const int MAX_N = 1000000;
bool prime[MAX_N+1];

void make_prime (void )
{
	fill (prime, prime + MAX_N, true );

	prime[0] = false;
	prime[1] = false;

	for (int i = 2; i < MAX_N + 1; ++i ){
		if (prime[i] ){
			for (int j = 2*i; j < MAX_N + 1; j += i ){
				prime[j] = false;
			} // end for
		} // end if
	} // end for
}

bool dp[MAX_N+1];

int main()
{
//	cut here before submit 
//	freopen ("testcase.be", "r", stdin );
	int n, x;

	make_prime ();

	while (cin >> n >> x && n && x ){
		vector <int> cost (n, 0 );
		for (int i = 0; i < n; ++i ){
			cin >> cost[i];
		} // end for
		memset (dp, false , sizeof (dp ) );

		dp[0] = true;
		for (int i = 0; i < n; ++i ){
			for (int j = cost[i]; j <= x; ++j ){
				dp[j] |= dp[j - cost[i]];
			} // end if
		} // end for

		int res = 0;
		for (int j = MAX_N; j >= 0; --j ){
			if (dp[j] && prime[j] ){
				res = j;
				break;
			} // end if
		} // end for

		if (res == 0 ){
			cout << "NA" << endl;
		}else{
			cout << res << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<long long>a(N+1),b(N);
    for(int i=0;i<N+1;i++)cin >> a[i];
    for(int i=0;i<N;i++)cin >> b[i];
    long long ans=0;
    for(int i=0;i<N;i++){
        long long res=b[i];
        if(a[i]<b[i]){
            ans+=a[i];
            b[i]-=a[i];
            if(a[i+1]<b[i]){
                ans+=a[i+1];
                a[i+1]=0;
            }
            else{
                ans+=b[i];
                a[i+1]-=b[i];
            }
        }
        else{
            ans+=b[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
using namespace std;

int main(void){
    string s;
    cin >> s;
    for (int i = 0; i <= 3; i++) cout << s[i];
    cout << " ";
    for (int i = 4; i <= 11; i++) cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, m; cin >> n >> m;
    VI h(n); cin >> h;
    vector<VI> g(n);
    FOR(i, 0, m) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;
    FOR(i, 0, n) {
        bool ok = true;
        each(j, g[i])ok &= h[i] > h[j];
        if (ok)++ans;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 8744
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))


ac, wa_list = 0, [0 for _ in range(N)]
solved = [False for _ in range(N)]
for _ in range(M):
    p, s = input().split(' ')
    p = int(p) - 1

    if solved[p]:
        continue

    else:
        if s == 'AC':
            solved[p] = True
            ac += 1

        elif s == 'WA':
            wa_list[p] += 1

wa = sum([wa for wa, s in zip(wa_list, solved) if s])

print(ac, wa)




Measured memory_bytes: 52016
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a <b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(b < c){
            int tmp = b;
            b = c;
            c = tmp;
        }
        if(a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        System.out.println(b + c);
    
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci()
{
    string binary = bitset<8>(128).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();
    cout<<decimal<<"\n";
}

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a;
    string b;
    cin>>b;
    ll x=0,y=0;
    for(int i=0; i<b.size(); i++)
    {
        if(b[i]=='1')
        {
            x++;
        }
        else
        {
            y++;
        }
    }
    cout<<2*min(x,y)<<endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

long long sum(int a, int b)
{
	return 1LL * b * (b + 1) / 2 - 1LL * a * (a - 1) / 2;
}

const int MOD = 1000 * 1000 * 1000 + 7;

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

	long long ans = 0;
	for (int x = K; x <= N + 1; ++x) {
		long long l = sum(0, x - 1);
		long long u = sum(N + 1 - x, N);
		ans += (u - l + 1) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}


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

void die(){
	cout << "NO";
	exit(0);
}
long long arr[100005];
int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long long n; cin >> n;
	long long T = (n) * (n + 1) / 2;
	
	
	long long total = 0;
	for(int i = 0;i < n;i++){
		cin >> arr[i];
		total += arr[i];
	}
	arr[n] = arr[0];
	
	if(total % T != 0) die();
	
	long long E = total / T;
	
	long long match = 0;
	for(int i = 0;i < n;i++){
		long long diff = arr[i+1] - arr[i];
		
		if(diff > E) die();
		if((E - diff) % n != 0) die();
		
		long long need = (E - diff) / n;
		match += need;
	}
	
	if(match != E) die();
	cout << "YES";
}


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

int main(void) {
    int n, a;
    cin >> n;

    a = n % 10;
    switch ( a ) {
    case 2: 
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    }
}

Measured memory_bytes: 3620
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    char c; cin >> c;

    if (c >= 'a') cout << 'a';
    else cout << 'A';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 2e9+7;
const ll  longinf = 1LL<<62;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};



int main(){
  ll a,b;
  cin>>a>>b;
  ll mi=inf;
  for(ll i=0;i<a;i++){
   if(i%2==0||b%2==0)
     mi=min(mi,abs(b*i/2-b*(a-i)));
   else{
     ll mma=(b*i+min(b,i))/2,mmi=(b*i-min(b,i))/2;
     mi=min(mi,max(b*(a-i),mma)-min(b*(a-i),mmi));
     }
   }
  swap(a,b);
    for(ll i=0;i<a;i++){
   if(i%2==0||b%2==0)
     mi=min(mi,abs(b*i/2-b*(a-i)));
   else{
     ll mma=(b*i+min(b,i))/2,mmi=(b*i-min(b,i))/2;
     mi=min(mi,max(b*(a-i),mma)-min(b*(a-i),mmi));
     }
   }
  cout<<mi<<endl;    
  return 0;
                                                
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

typedef
tree<
	pair<int, int>,
	null_type,
	less<pair<int, int>>,
	rb_tree_tag,
	tree_order_statistics_node_update>
ordered_set;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

struct tr{
    tr* nxt[26];
    ll c=0;
};

ll n,k;
        
void insert(tr* p, string s)
{
    tr *cur=p;
    repf(i,0,s.length())
    {
        if(!cur->nxt[s[i]-'A']) 
        {
            cur->nxt[s[i]-'A']=new tr();
        }
        cur=cur->nxt[s[i]-'A'];
        cur->c++;
    }
}

ll f(tr *p)
{
    if(!p) return 0;
    ll ans=p->c/k;
    repf(i,0,26)
    {
        if(p->nxt[i]) ans+=f(p->nxt[i]);
    }
    return ans;
}

int main()
{
    IOS;
    ll n,m;
    cin>>n>>m;
    ll ans=(n*(n-1))/2+(m*(m-1))/2;
    cout<<ans<<endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;
int N, M;
const int MAX_M = 50, MAX_N = 50;
int a[MAX_M], b[MAX_M], c[MAX_M];


void solve() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (a[j] == i+1 || b[j] == i+1) {
				c[i] += 1;
			}
		}
	}

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

int main() {

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
	}
	int* c = new int[N];
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else {
    return treeSearch(u->right,k);
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
    z->parent = y;

    if(y==NIL){
      root=z;
    }
    else if(z->key < y->key){
      y->left = z;
    }
    else {
      y->right = z;
    }
  
}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
 
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }  
}


int main(){
  int n,x,i;
  char com[20];
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } 
    
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}

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

int main (){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A+B > C+D){
    cout << "Left" << endl;
  }
  else if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	print1(min(a*b,c));
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string s; cin >> s;
	map<char, int> MP;
	for (auto i : s) MP[i]++;
	if ((int)MP.size() & 1) cout << "No";
	else {
		if (MP.size() == 2) {
			if (MP.count('N') && MP.count('S')) cout << "Yes";
			else if (MP.count('W') && MP.count('E')) cout << "Yes";
			else cout << "No";
		}
		else cout << "Yes";
	}
	return 0;
}

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

int main() {
  int N, Alice, Bob;
  cin >> N;
  
  vector<int> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  Alice = 0;
  Bob = 0;
  for(int i = 0; i < N; i++) {
    if(i%2==0) {
      Alice += a.at(i);
    }
    else {
      Bob += a.at(i);
    }
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

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

    vector<int> cnt(2,0);
    vector<int> ans((int)S.size(),0);
    for(int i=0; i<(int)S.size(); i++){
        if(S[i]=='R'){
            cnt[i%2]++;
        }else{
            ans[i-1]+=cnt[(i-1)%2];
            ans[i]+=cnt[i%2];
            cnt={0,0};
        }
    }
    for(int i=(int)S.size()-1; i>=0; i--){
        if(S[i]=='L'){
            cnt[i%2]++;
        }else{
            ans[i+1]+=cnt[(i+1)%2];
            ans[i]+=cnt[i%2];
            cnt={0,0};
        }
    }

    cout_vec(ans);
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		double max = 0;
		double min = Double.MAX_VALUE;
		while (in.hasNext()) {
			double val = in.nextDouble();
			max = Math.max(max, val);
			min = Math.min(min, val);
		}
		System.out.println(max - min);
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
  int n,u,v,w,i,c;
  static vector < pair <int,int> > path[100000];
  static int color[100000];
  memset(color,-1,sizeof(color));

  cin>>n;
  for(i=0;i<n-1;i++){
    cin>>u>>v>>w;
    u--;
    v--;
    w=w%2;
    path[u].push_back({v,w});
    path[v].push_back({u,w});
  }

  queue<int> q;
  color[0]=0;
  q.push(0);

  while(!q.empty()){
    u=q.front();
    q.pop();
    for(i=0;i<path[u].size();i++){
      v=path[u][i].first;
      if(color[v]==-1){
        if(path[u][i].second){
          color[v]=(color[u]+1)%2;
        }
        else{
          color[v]=color[u];
        }
        q.push(v);
      }
    }
  }

  for(i=0;i<n;i++){
    cout<<color[i]<<endl;
  }

	return 0;
}


Measured memory_bytes: 6784
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()
Q = I()
B,C = LIR(Q,2)

ans = []
d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1

sum_ = sum(A)
for i in range(Q):
    num = d[B[i]]
    sum_ = sum_+num*(C[i]-B[i])
    ans.append(sum_)
    d[B[i]] -= num
    d[C[i]] += num

for a in ans:
    print(a)

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

int main () {
  int A,B,c,d;
  cin>>A>>B>>c>>d;
  if(A+B > c+d){
    cout<<"Left"<<endl;
  }
  if(A+B==c+d){
    cout<<"Balanced"<<endl;
  }
  if(A+B < c+d){
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int f,n;
  scanf("%d",&n);
  f=fibonacci(n);
  printf("%d\n",f);

  return 0;
}

fibonacci(n){
  int i;
  int F[n];
  F[0]=1;
  F[1]=1;
  for(i=2;i<=n;i++){
    F[i]=F[i-2]+F[i-1];
  }
  return F[n];
}



Measured memory_bytes: 2056
#include <iostream>
#include<utility>
#include<vector>
#include<algorithm>
#include<set>
#include <climits>
#include<map>
#include<string>
#include<math.h>
#include<stack>
using namespace std;
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ll long long 
#define so(v) sort(v.begin(),v.end())
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define test 0
// const ll md=1000000007;
// ll dp[N],vis[N];

int main()
{
    ll t=1,n;
    if(test==1) cin>>t;
    while(t--)
    {
        int k,a,b;
        cin>>k>>a>>b;
        string ans="NG";
        for(int i=k;i<=b;i+=k)
        {
            if(i>=a)
            {
                ans="OK";
                break;
            }
        }
        cout<<ans;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define INF 100000000;
bool comp[10];
int d, g, p[10], c[10], ans=INF;

int nocomp(int score){
  if(score>=g) return 0;
  for(int i=d-1; i>=0; i--){
    if(comp[i]) continue;
    REP(j,p[i]-1){
      score += (i+1)*100;
      if(score>=g) return j+1;
    }
    return INF;
  }
}

void dfs(int i, bool s){
  comp[i]=s;
  if(i==d-1){
    int sc=0, num=0;
    REP(j,d){
      sc += comp[j]*c[j];
      num += comp[j]*p[j];
    }
    num += nocomp(sc);
    if(ans>num) ans=num;
  }else{
    dfs(i+1, 1);
    dfs(i+1, 0);
  }
}

int main(){
  REP(i,10) {comp[i]=0; p[i]=0; c[i]=0;}
  cin >> d >> g;
  REP(i,d) cin >> p[i] >> c[i];
  REP(i,d) c[i]=(i+1)*100*p[i]+c[i];
  dfs(0,1);
  dfs(0,0);
  cout << ans << endl;
}


Measured memory_bytes: 256
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strings"
    "strconv"
    "regexp"
)
 
func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var r string
    r, _ = readOneLine(scanner)
    ios := strAry2intAry(split(r))
    var tk = ios[0]
    var ao = ios[1]
    var k = ios[2]

    if k >= tk {
        k = k - tk
        tk = 0
        if k >= ao {
            ao = 0
        } else {
            ao -= k
        }
    } else {
        tk -= k
    }
    fmt.Println(tk,ao)
}

func readOneLine(scanner *bufio.Scanner) (string, bool) {
    var s string
    var eof = false
    if scanner.Scan() {
        s = scanner.Text()
    } else {
        eof = true
    }
    return s, eof
}
 
func s2i(s string) int {
    var intVal,_ = strconv.Atoi(s)
    return intVal
}
 
func i2s(i int) string {
    return string(i)
}
 
func s2f(s string) float64 {
    var floatVal,_ = strconv.ParseFloat(s, 64)
    return floatVal
}
 
func sum(i []int) int {
    sum := 0
    for _,val := range i {
        sum += val
    }
    return sum
}
 
func split(s string) []string {
    return strings.Fields(s)
}
 
func strAry2intAry(strs []string) []int64 {
    var ret = make([]int64, 0, len(strs))
    for _ , str := range strs {
        var intVal, _ = strconv.Atoi(string(str));
        ret = append(ret, int64(intVal))
    }
    return ret
}
 
func intAry2strAry(nums []int) []string {
    var ret = make([]string, 0, len(nums))
    for _ , num := range nums {
        var strVal = strconv.Itoa(num);
        ret = append(ret, strVal)
    }
    return ret
}
 
func ary2str(strs []string) string {
    return strings.Join(strs, " ")
}
 
func regexpExample() {
    // Your code here!
    var str = "13:20"
    r := regexp.MustCompile(`(\d+):(\d+)`)
    fmt.Println(r.FindStringSubmatch(str))
}
 
func reverse(res []int) []int {
    for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
        res[i], res[j] = res[j], res[i]
    }
    return res
}

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

int n, m;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	string s;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			cin >> s;
			if (s == "snuke")
			{
				cout << (char)('A' + j) << i + 1 << endl;
				return 0;
			}
		}
	throw;


	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int dp[4][7600];
int main(void)
{
    int K,S;
    cin>>K>>S;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=S&&i<=K;i++)
    {
        dp[1][i]=1;
    }
    for(int i=2;i<=3;i++)
    {
        for(int j=0;j<=S;j++)
        {
            for(int k=0;k<=K&&k<=j;k++)
            {
                dp[i][j]+=dp[i-1][j-k];
            }
        }
    }
    cout << dp[3][S]<<endl;
    return 0;
}

Measured memory_bytes: 384
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = defaultdict(int)

for i in a:
  d[i] += 1
s = sum(a)

for i in range(q):
  b, c = map(int, input().split())
  if b < c:
    x = (c-b)*d[b]
    s += x
  else:
    x = (b-c)*d[b]
    s -= x
  d[c] += d[b]
  d[b] = 0
  print (s)

Measured memory_bytes: 89700
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  if(195<=N)
    cout<<5<<endl;
  else if(189<=N)
    cout<<4<<endl;
  else if(165<=N)
    cout<<3<<endl;
  else if(135<=N)
    cout<<2<<endl;
  else if(105<=N)
    cout<<1<<endl;
  else
    cout<<0<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  double a, l, x, t1, t2, s;

  while(cin >> a >> l >> x){
    x += l;
    x /= 2;
    t1 = acos((2*l*l - a*a)/(2*l*l));
    t2 = acos((2*x*x - l*l)/(2*x*x));
    s = l*l*sin(t1)/2 + x*x*sin(t2);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cout << s << endl;
  }
  return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int a,b,c,d,m,n;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    m=(a*10)+b;
    n=(c*10)+d;
    if(m>0&&m<13&&n>0&&n<13) cout<<"AMBIGUOUS"<<endl;
    else if(m>0&&m<13) cout<<"MMYY"<<endl;
    else if(n>0&&n<13) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
    return 0;
}


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

int m1, d1, m2, d2;

int main() {
	scanf("%d%d%d%d", &m1, &d1, &m2, &d2);
	if (m1 != m2) printf("1");
	else printf("0");
	return 0;
}

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

const long long mod =1e+7 ;
const int N = 1e5+5;


#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i,l,m) for(int i=l;i<m;i++)
# define vii vector<int>
#define vpr vector<pair<ll,ll> >
ll pwr(ll x,ll y);
bool isprime(int n) ;

int wt[N],val[N];
ll dp[N];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);

int n,w;
cin>>n>>w;
int max_val=0;
fr(i,1,n+1)
{
    cin>>wt[i]>>val[i];
     max_val+=val[i];
}
fr(i,0,max_val+1){dp[i]=INT_MAX;}
dp[0]=0;
fr(i,1,n+1)
{
    for(int j=max_val;j>=val[i];j--)
    {
        dp[j]=min(dp[j],wt[i]+dp[j-val[i]]);
    }

}

int l=max_val;
while(dp[l]>w)
{
    l--;
}

cout<<l<<endl;


return 0;
}
ll pwr(ll x,ll y)
{
    ll ans=1;
    x=x%mod;
    while(y>0){
    if(y&1)ans=(x*(ans%mod))%mod;
    x=(x*x)%mod;
    y=y/2;

    }
    return ans%mod;
}

bool isprime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


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

signed main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(12) << W * H / 2.0 << " ";

  if (x == W / 2 && y == H / 2) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;
      
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  int a[n+3],b[n+3],c[n+3];

  reps(i,n){
    cin>>a[i];
  }
  reps(i,n){
    cin>>b[i];
  }
  reps(i,n-1){
    cin>>c[i];
  }

  int sum=0;
  reps(i,n){
    sum+=b[a[i]];

    if(a[i+1]==a[i]+1){
      sum+=c[a[i]];
    }
  }

  cout<<sum<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define out(x) cerr << #x << " = " << x << "\n"
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}

static const int N = 520233, M = 5202333;
struct E {
  int nxt, u, v, w;
}e[M];
int head[N], ct[N], book[N], dis[N];
int cnt = 0, n, m, Q;
int nQ;
int sccno[N], Max[N];
inline void add(int u, int v, int w = 0) {
  e[++ cnt] = (E) {head[u], u, v, w}; head[u] = cnt;
}

inline void dfs(int u, int d, int col) {
  if(d == -1) return ; 
//  cout << u << "\n";
  if(Max[u] < d) {
    if(!sccno[u]) sccno[u] = col;
    Max[u] = d;
    for(int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      dfs(v, d - 1, col);
    }
  }
}

struct Query {
  int u, d, c;
}q[N];

int main() {
  read(n); read(m);
    fill(Max, Max + n + 1, -2333);
  for(int i = 1; i <= m; i ++) {
    int u, v, w; read(u); read(v);
    add(u, v);
    add(v, u);
     }
  read(Q);
  for(int i = 1; i <= Q; i ++) {
    int u, d, c;
    read(u); read(d); read(c);
     q[i] = (Query) {u, d, c};
  }
  for(int i = Q; i >= 1; i --) {
    Query &u = q[i];
//    cout << u.u << ' ' << u.d << " " << u.c << "\n";
    dfs(u.u, u.d, u.c);
//    for(int i = 1; i <= n; i ++) cout << Max[i] << "\t";
//    putchar('\n');
  }
  for(int i = 1; i <= n; i ++) cout << sccno[i] << "\n";
}

Measured memory_bytes: 16128
N = int(input())
A = list(map(int, input().split()))

p = [0] * N
m = [0] * N

for i in range(N):
    p[i] = A[i] + i + 1
    m[i] = i + 1 - A[i]

from collections import Counter

cp = Counter(p)
cm = Counter(m)

ans = 0

for x, y in cp.items():
    ans += cm[x] * y

print(ans)

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

typedef long long int ll; 

unordered_map <ll,ll> umap;
// Function to compute num (mod a) 
void mod(ll a) 
{ 
	// Initialize result 
	ll res = 0 ; 
	for (ll i = 1; i <= a+1; i++)
	{ 
		res = (res*10 + 7) %a; 
		if(res == 0)
		{
			cout << i << endl;
			return ;
		}
		if(umap[res] == 0)
			umap[res] = i;
		else
		{
			ll m = umap[res];
			ll n = i;
			cout << i - umap[res];
			return;
		}

	}
} 

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

	if(n%2 == 0 || n%5 == 0)
		cout << "-1\n";
	else
		mod(n);

	
	return 0; 
} 


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, 0), b(n, 0), c(n, 0);
  vector<int> ap(n, 0), bp(n, 0), cp(n, 0);
  for (int i = 0; i < n; i++) {
    int a_, b_, c_;
    cin >> a_ >> b_ >> c_;
    a[i] = a_;
    b[i] = b_;
    c[i] = c_;
  }
  ap[0] = a[0];
  bp[0] = b[0];
  cp[0] = c[0];
  for (int i = 1; i < n; i++) {
    ap[i] = a[i] + max(bp[i - 1], cp[i - 1]);
    bp[i] = b[i] + max(cp[i - 1], ap[i - 1]);
    cp[i] = c[i] + max(ap[i - 1], bp[i - 1]);
  }
  int ans = max(ap[n - 1], max(bp[n - 1], cp[n - 1]));
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int x;
  cin >> x;
  if(x>=30)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
while True:
    m,f,r=map(int,input().split())
    if m==f==r==-1:break
    
    if m==-1 or f==-1 or m+f<30:
        jdg='F'
    elif m+f>=80:
        jdg="A"
    elif m+f>=65:
        jdg="B"
    elif m+f>=50:
        jdg="C"
    else:
        jdg="C" if r>=50 else "D"
    print(jdg)


Measured memory_bytes: 5592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
	int N; cin >> N;
	vector<string> S(N);
	vector<int> enda, beginb, btoa;

	int cnt = 0;

	for(int i = 0; i < N; ++i) cin >> S[i];

	for(int i = 0; i < N; ++i){
		int begin = 0, end = S[i].size()-1;
		if(S[i][begin] == 'B' && S[i][end] == 'A') btoa.push_back(i);
		else if(S[i][end] == 'A') enda.push_back(i);
		else if(S[i][begin] == 'B') beginb.push_back(i);
	}

	for(int i = 1; i < btoa.size(); ++i){
		S[btoa[0]] += S[btoa[i]];
		S[btoa[i]] = "";
	}

	if(btoa.size() > 0){
		if(enda.size() > 0){
			S[enda[0]] += S[btoa[0]];
			S[btoa[0]] = "";
		}else{
			enda.push_back(btoa[0]);
		}
	}

	int tmpi = 0;
	while(enda.size() > tmpi){
 		int i = tmpi;

		for(int j = 0; j < beginb.size(); ++j){
			int e = enda[i], b = beginb[j];
			if(e != b && b != -1 && e != -1){
				S[e] = S[e] + S[b];
				S[b] = "";
				if(S[e][S[i].size()-1] == 'A') enda.push_back(i);
				vector<int>::iterator iter = find(enda.begin(), enda.end(), b);
				if(iter != enda.end()){
					enda[distance(enda.begin(), iter)] = -1;
				}
				beginb[j] = -1;
				
				break;
			}
		}
		tmpi++;
	}

	// cout << endl;
	for(int i = 0; i < N; ++i){
		// cout << "i:" << i << ", " << S[i] << endl;
		for(int j = 0; j < S[i].size(); ++j){
			if(S[i][j] == 'A' && S[i][j+1] == 'B') cnt++;
		}
	}

	cout << cnt << endl;


	return 0;
}


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

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

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

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

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


//cout<<""<<endl;
int main(){
  int N;cin>>N;
  vi a(N);
  rep(i,N)cin>>a[i];
  sort(all(a));
  bool ok=true;
  rep(i,N-1){
    if(a[i]==a[i+1])ok=false;
  }
  if(ok) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}





Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	long long ans=0;
	for (int i=1;i<=n;i++){
		
		int t=i,sum=0;
		while (t>0){
			sum+=t%10;
			t/=10;
		}
		if (sum>=a&&sum<=b) ans+=i;
		
		
	}
	cout<<ans;

}

Measured memory_bytes: 256