akhauriyash/Code-Regression huggingface dataset:
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-20 16:44:12
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int dp[110][2][5];

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

  string s; int k; cin >> s >> k;

  int n = s.size();

  dp[0][0][0] = 1;

  for (int i = 0; i < n; ++i) {
    int D = s[i] - '0';
    for (int j = 0; j < 2; ++j) {
      for (int l = 0; l < 4; ++l) {
        for (int d = 0; d <= (j ? 9 : D); ++d) {
          dp[i + 1][j || (d < D)][l + (d != 0)] += dp[i][j][l];
        }
      }
    }
  }

  cout << dp[n][0][k] + dp[n][1][k] << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{

    long int a,b,k,p,q;
    scanf("%li %li %li",&a,&b,&k);

    if(a+b<k)
      {

       p=0;
       q=0;
       printf("%li %li\n",p, q);
       return 0;

      }


       else if(a>=k)
          {
              p=a-k;
              q=b;
         printf("%li %li\n",p, q);
         return 0;

          }


         else(a<=k);
        {
              p=0;
             q=b-(k-a);
        printf("%li %li\n",p, q);
         return 0;
        }




 }

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m,l,r,ans=1;
	cin >> n >> m;
	vpll a(m);
	queue<pair<ll,ll>> q;
	rep(i,m){
		cin >> l >> r;
		a[i]=m_p(r,l);
	}
	sort(all(a));
	cerr << a;
	rep(i,m) q.push(a[i]);
	pair<ll,ll> cur=q.front();
	q.pop();
	while(!q.empty()){
		if(cur.first<=q.front().second){
			ans++;
			cur=q.front();
		}
		q.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main(void)
{
	int X,t;
	scanf("%d",&X);
	t=X%7;
	if(t==1)printf("fri\n");
	else if(t==2)printf("sat\n");
	else if(t==3)printf("sun\n");
	else if(t==4)printf("mon\n");
	else if(t==5)printf("tue\n");
	else if(t==6)printf("wed\n");
	else if(t==0)printf("thu\n");
	return 0;
}


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

int find_index(vector <string> PtoS, string name, int number)
{
    int count = 0;
    for(int i = 100; i >= 0; i--)
    {
        if(PtoS[i] == name)
            count++;
        
        if(count == number)
            return i;
    }
    return -1;
}

int main() {
    int N;
    cin >> N;
    vector <string> PtoS(101);
    vector <string> S(N);
    vector <int> P(N);
    vector <int> PtoIndex(101);

    for(int i = 0; i < N; i++)
    {
        cin >> S[i] >> P[i];
        PtoS[P[i]] = S[i];
        PtoIndex[P[i]] = i;
    }
    sort(S.begin(), S.end());
    int equal_count = 0;
    string name = S[0];
    for(int i = 0; i < N; i++)
    {
        if(name == S[i]) equal_count++;
        else             equal_count = 1;
//        cout << "count" << equal_count << endl;
        name = S[i];
        int point = find_index(PtoS, name, equal_count);
        cout << PtoIndex[point] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import product

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

abc = [a, b, c]

res = float('inf')
for p in product(range(4), repeat=n):
    num = [0, 0, 0, 0]
    le = [0, 0, 0, 0]
    for i, category in enumerate(p):
        num[category] += l[i]
        le[category] += 1
    tmp = 0
    if le[0] * le[1] * le[2] == 0:
        continue
    for i in range(3):
        tmp += abs(num[i] - abc[i]) + 10 * (le[i] - 1)
    res = min(res, tmp)

print(res)



Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

const int Size = 1e5 + 5;

int main(){
  ll N; cin >> N;
  ll GA, SA, BA; cin >> GA >> SA >> BA;
  ll GB, SB, BB; cin >> GB >> SB >> BB;

  ll DP1[N + 1] = {};
  for (ll i = 0; i <= N; i++){
    if (i + GA <= N){
      DP1[i + GA] = max(DP1[i + GA], DP1[i] + GB - GA);
    }
    if (i + SA <= N){
      DP1[i + SA] = max(DP1[i + SA], DP1[i] + SB - SA);
    }
    if (i + BA <= N){
      DP1[i + BA] = max(DP1[i + BA], DP1[i] + BB - BA);
    }
  }

  ll M = 0;
  for (ll i = 0; i <= N; i++){
    M = max(M, i + DP1[i]);
  }

  ll DP2[M + 1] = {};
  for (int i = 0; i <= M; i++){
    if (i + GB <= M){
      DP2[i + GB] = max(DP2[i + GB], DP2[i] + GA - GB);
    }
    if (i + SB <= M){
      DP2[i + SB] = max(DP2[i + SB], DP2[i] + SA - SB);
    }
    if (i + BB <= M){
      DP2[i + BB] = max(DP2[i + BB], DP2[i] + BA - BB);
    }
  }
  
  ll ans = 0;
  for (ll i = 0; i <= M; i++){
    ans = max(ans, DP2[i] + i);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 195584
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T = int>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<ll>(INF)
#define REP(i,n)      for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(ll i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int n = in();
	int max = -1;
	vector<int>a(n);
	REP(i, n)a[i] = in();
	REPC(i, a)REPC(j, a)if (max < abs(i - j))max = abs(i - j);
	cout << max << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,max=0;
	cin>>n;
	map<string ,int>s;
	rep(i,n){
		string tmp;
		cin>>tmp;
		if(s.find(tmp)==s.end())s.insert(make_pair(tmp,1));
		else s.at(tmp)++;
	}
	cin>>m;
	rep(i,m){
		string tmp;
		cin>>tmp;
		if(s.find(tmp)==s.end())s.insert(make_pair(tmp,1));
		else s.at(tmp)--;
	}
	each(it,s)chmax(max,(*it).second);
	cout<<max<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 305
#define pi pair<int,int>
#define mk make_pair
#define Mod 1000000007
using namespace std;
int n,m,x,y,z,dp[N][N][N];
vector<pi>G[N];
inline bool check(int x,int y,int z){
	int pos=max(x,max(y,z));
	if (x<y) swap(x,y);if (x<z) swap(x,z);
	if (y<z) swap(y,z);
	for (int i=0;i<(int)G[pos].size();i++){
		int l=G[pos][i].first;
		int limit=G[pos][i].second;
		if (limit==3) if (z<l) return 0;
		if (limit==2){
			if (y<l) return 0;
			if (z>=l) return 0;
		}
		if (limit==1) if (y>=l) return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&z);
		G[y].push_back(mk(x,z));
	}
	dp[0][0][0]=1;
	int ans=0;
	for (int i=0;i<=n;i++){
		for (int j=0;j<=n;j++){
			for (int k=0;k<=n;k++){
				if (!dp[i][j][k]) continue;
				int nxt=max(i,max(j,k))+1;
				if (nxt==n+1){
					ans=(ans+dp[i][j][k])%Mod;
					continue;
				}
				if (check(nxt,j,k)) dp[nxt][j][k]=1ll*(dp[nxt][j][k]+dp[i][j][k])%Mod;
				if (check(i,nxt,k)) dp[i][nxt][k]=1ll*(dp[i][nxt][k]+dp[i][j][k])%Mod;
				if (check(i,j,nxt)) dp[i][j][nxt]=1ll*(dp[i][j][nxt]+dp[i][j][k])%Mod;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 110848
import java.util.Scanner;

public class Main {
	
	static Scanner sc =  new java.util.Scanner(System.in);

	public static void main(String[] args) {
		
		String str = sc.next();
		
		String[] array = str.split("");
		
		int n = array.length;
		
		String str2 = "" ;
		
		for ( int x = n - 1 ; x >= 0 ; x--){
			
			str2 = str2 + array[x] ;
		}
		System.out.println( str2 ) ;
	}

}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N;


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> N;
    cin >> s;
    if(N%2!=0)
    {
        cout << "No";
        return 0;
    }
    int x = N/2;
    for(int i=0; i<x; i++)
    {
        if(s[i] != s[x+i])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

const int mod = 1e9 + 7;

ll modPow(ll a, ll n)
{
    if(n == 0LL)return 1LL;
    ll pola = modPow(a, n/2)%mod;

    if(n % 2 == 0)
    {
        return (pola*pola)%mod;
    }
    else
    {
        return (((pola*pola)%mod)*a)%mod;
    }
}

ll nCr(ll n, ll k)
{
    if(k > n)return 0LL;
    if(k < 0 || n < 0)return 0LL;

    ll proizvodGore = 1LL;
    for(ll i = n; i >= n-k+1; --i)
    {
        proizvodGore = (proizvodGore*i)%mod;
    }

    ll proizvodDole = 1LL;

    for(ll i = 1; i <= k; ++i)
    {
        proizvodDole = (proizvodDole*i)%mod;
    }

    return ((proizvodGore)*modPow(proizvodDole, mod-2LL))%mod;
}

int main()
{
    int x,y;
    cin >> x >> y;

    int k = (x+y)/3;

    if((x+y)%3!=0)
    {
        cout << "0\n";
        return 0;
    }

    //if(2 * x < y || 2*k < y)

    cout << nCr(k, x-k) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

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

    bool res = true;
    for (int i = 0; res && i <= n; i++) {
        for (int j = 0; res && j <= n - i; j++) {
            if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
                cout << i << " " << j << " " << (n - i - j) << endl;
                res = false;
            }
        }
    }

    if (res) {
        cout << "-1 -1 -1" << endl;
    }

    return 0;
}


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

using namespace std;

#define INF 1e9

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

    int n;
    cin>>n;

    vector<long long> a(n);
    
    for(int i=0;i<n;i++)cin>>a[i];

    vector<long long> sum1(n+1),sum2(n+1);
    sum1[0]=0;
    sum2[0]=0;

    for(int i=0;i<n;i++){
        sum1[i+1]=sum1[i]+a[i];
    }

    for(int i=0;i<n;i++){
        sum2[i+1]=sum2[i]^a[i];
    }

    long long ans=0;

    for(int i=0;i<n;i++){
        int l=i,r=n;
        for(int j=0;j<30;j++){
            int mid=(r+l)/2;
            if((sum1[mid]-sum1[i])==(sum2[mid]^sum2[i]))l=mid;
            else r=mid;
        }
        ans+=l-i;
        if((sum1[r]-sum1[i])==(sum2[r]^sum2[i]))ans++;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 4992
def solve(i):
    global cake
    global ans
    global M
    a, b, c = 0, 0, 0
    for j in range(M):
        a += cake[j][0]
        b += cake[j][1]
        c += cake[j][2]
    ans[i] = abs(a) + abs(b) + abs(c)


N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]
ans = [0 for _ in range(8)]
cake.sort(key=lambda x: +x[0] + x[1] + x[2])
solve(0)
cake.sort(key=lambda x: +x[0] + x[1] - x[2])
solve(1)
cake.sort(key=lambda x: +x[0] - x[1] + x[2])
solve(2)
cake.sort(key=lambda x: +x[0] - x[1] - x[2])
solve(3)
cake.sort(key=lambda x: -x[0] + x[1] + x[2])
solve(4)
cake.sort(key=lambda x: -x[0] + x[1] - x[2])
solve(5)
cake.sort(key=lambda x: -x[0] - x[1] + x[2])
solve(6)
cake.sort(key=lambda x: -x[0] - x[1] - x[2])
solve(7)
print(max(ans))

Measured memory_bytes: 40828
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,seki;
  cin >> a >> b;
  seki=a*b;
  if(seki%2==0){
    cout << "Even"<< endl;
  }
  else{
    cout << "Odd" << endl;
  }
}
    

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

const int N = 1e5 + 5;

char s[N];

int n, ar[N], sz[N], p[N], sum[N];

int get (int v)
{
    return v == p[v] ? v : p[v] = get(p[v]);
}

void unite (int a, int b)
{
    a = get(a);
    b = get(b);

    if (a == b) return;

    if (sz[a] > sz[b])
        swap(a, b);

    sum[b] += sum[a];
    sum[b] %= 26;

    sz[b] += sz[a];
    p[a] = b;
}

main ()
{
    scanf("%s", s + 1);
    s[0] = 'a';
    n = strlen(s);
    s[n] = 'a';
    for (int i = 0; i < n; i++)
    {
        sz[i] = 1;
        p[i] = i;

        ar[i] = s[i + 1] - s[i];

        if (ar[i] < 0)
            ar[i] += 26;

        sum[i] = ar[i];
    }
    for (int i = 0; i < n; i++)
        unite(i, n - i - 1);

    int m, a, b;
    cin >> m;
    while (m--)
    {
        scanf("%d%d", &a, &b);
        unite(a - 1, b);
    }
    for (int i = 0; i < n; i++)
    {
        if (p[i] == i && sum[i] != 0)
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}


Measured memory_bytes: 1920
#include<stdio.h>

#define MAX 100
#define INF (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];//M[u][v]にuからvへの辺の重みを記録した隣接行列

int prim();

int main(){

  int i,j,e;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INF:e;
    }
  }
  
  printf("%d\n",prim());

  return 0;
}

int prim(){

  int u,i,v,minv,sum=0;
  int d[MAX];//重みが最少の辺の重みを記録
  int p[MAX];//MSTにおける頂点vの親を記録
  int color[MAX];//color[v]にWHITE,GRAY,BLACKを記録

  for(i=0;i<n;i++){
    d[i]=INF;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;
 
  while(1){
    minv=INF;
    u=-1;
    
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    
    if(u==-1)break;
    color[u]=BLACK;
    
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INF){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
 
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }

  return sum;
}

Measured memory_bytes: 636
import java.io.IOException;
import java.util.InputMismatchException;

public class Main {
	int a, n;

	int bt(int p, int q, int pre, int k, int pi) {
		if (p < 0) return 0;
		if (p == 0) return 1;
		if (n <= k) return 0;

		int res = 0;
		for (int i = pre; pi*i <= a; i++) {
			int np = p*i - q;
			int nq = q*i;
			res += bt(np, nq, i, k + 1, pi * i);
		}
		return res;
	}

	void run() {
		MyScanner sc = new MyScanner();

		while (true) {
			int p = sc.nextInt();
			int q = sc.nextInt();
			a = sc.nextInt();
			n = sc.nextInt();
			if ((p | q | a | n) == 0) {
				break;
			}
			
			System.out.println(bt(p, q, 0, 0, 1));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

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

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

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

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

    vector<long long> A(N, 0);
    for (long long &a : A)
    {
        cin >> a;
        a--;
    }

    vector<long long> sum(N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        sum[i + 1] = (sum[i] + A[i]) % K;
    }
    // for (int i = 0; i < N; i++)
    // {
    //     sum[i] -= i;
    //     sum[i] %= K;
    //     while (sum[i] < 0)
    //     {
    //         sum[i] += K;
    //     }
    // }

    queue<long long> q;
    map<long long, long long> m;
    long long ans = 0;
    for (int i = 0; i < N + 1; i++)
    {
        ans += m[sum[i]];
        m[sum[i]]++;
        q.push(sum[i]);
        while (q.size() >= K)
        {
            m[q.front()]--;
            q.pop();
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

ll n, k, q;
ll a[2005];
vector<ll> ve, ans;
ll ans2 = 4e18;

int main()
{
    scanf("%lld%lld%lld", &n, &k, &q);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        a[n] = -4e18;
        ans.clear();
        for(ll j = 0; j <= n; j++)
        {
            if(a[i] > a[j])
            {
                sort(ve.begin(), ve.end());
                for(ll l = 0; l < (ll)ve.size() - k + 1; l++)
                {
                    ans.push_back(ve[l]);
                }
                ve.clear();
            }
            else
            {
                ve.push_back(a[j]);
            }
        }
        sort(ans.begin(), ans.end());
        if(ans.size() >= q) ans2 = min(ans2, ans[q - 1] - a[i]);
    }
    cout<<ans2<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=5000;
const long long oo=1e16+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int n,a[N+5];
long long A,B,f[N+5];
int main()
{
	//freopen("Rotation Sort.inp","r",stdin);
	//freopen("Rotation Sort.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>n>>A>>B;
    for (int i=1;i<=n;i++) cin>>a[i];
    a[n+1]=n+1; n++;
    for (int i=1;i<=n;i++)
    {
        f[i]=oo;
        int dem1=0, dem2=0;
        for (int j=i-1;j>=0;j--)
        {
            if (a[j]<a[i]) f[i]=min(f[i],f[j]+dem1*B+dem2*A);
            if (a[j]<a[i]) dem1++; else dem2++;
        }
    }
    cout<<f[n];
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

void dfs(vector<ll>* edges,ll ind,ll val,ll* arr,bool* visited){
	visited[ind] = 1;
	arr[ind] = val;
	for(auto it:edges[ind]){
		if(!visited[it])
			dfs(edges,it,val,arr,visited);
	}
}
int main() 
{
	ll arr[3][3];
	REP(i,0,3){
		REP(j,0,3){
			cin>>arr[i][j];
		}
	}
	ll n;
	cin>>n;
	REP(i,0,n){
		ll x;
		cin>>x;
		REP(i,0,3){
			REP(j,0,3){
				if(arr[i][j] == x)
					arr[i][j] = 0;
			}
		}		
	}
	REP(i,0,3){
		if(arr[i][0] == arr[i][1] && arr[i][1] == arr[i][2] && arr[i][0] == 0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	REP(i,0,3){
		if(arr[0][i] == arr[1][i] && arr[1][i] == arr[2][i] && arr[0][i] == 0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(arr[0][0] == arr[1][1] && arr[1][1] == arr[2][2] && arr[0][0] == 0){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(arr[0][2] == arr[1][1] && arr[1][1] == arr[2][0] && arr[0][2] == 0){
			cout<<"Yes"<<endl;
			return 0;
	}
	cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>
 
using namespace std;
 
int N;
size_t MASK;
vector<vector<int>> v;
vector<vector<int>> dp;
 
size_t get_mask()
{ 
  size_t mask = 0;
  for (int i = 0; i < N; ++i)
  { 
    mask |= (1 << i);
  }
  return mask;
}
 
inline size_t add(size_t res, size_t delta)
{ 
  return (res + delta) % 1000000007;
}
 
size_t solution(int i, size_t mask = 0)
{ 
  size_t res = 0; 
  for (int j = 0; j < N; ++j)
  { 
    if (v[i][j] && !(mask & (1<<j)))
    { 
      const size_t new_mask = mask | (1<<j);
      if (new_mask == MASK)
      { 
        res = add(res, 1);
        break;
      }
      if (dp[i+1][new_mask] == -1)
      { 
        dp[i+1][new_mask] = solution(i+1, new_mask);
      }
      res = add(res, dp[i+1][new_mask]);
    }
  }
  return res;
}
 
int main()
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
 
  cin >> N;
 
  MASK = get_mask();
 
  v = vector<vector<int>>(N, vector<int>(N));
  dp = vector<vector<int>>(N+1, vector<int>(1<<N, -1));
 
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < N; ++j)
    {   
      cin >> v[i][j];
    }   
  }
 
  cout << solution(0);
 
  return 0;
}

Measured memory_bytes: 188800
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    deque<int> que;
    rep(i, n) {
        int a; cin >> a;
        if(i % 2 == 0) que.push_back(a);
        else que.push_front(a);
    }
    if(n % 2 == 1) reverse(que.begin(), que.end());
    rep(i, n) {
        if( i != 0) cout << " ";
        cout << que[i];
    }
    cout << endl;

    return 0;
}


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

int main(){
    long long L, R;
    cin >> L >> R;
    
    R = min(R, L + 2019);
    int ans = 2018;
    for(long long i = L; i <= R; i++){
        for(int j = i+1; j <= R; j++){
            int tmp = i * j % 2019;
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val%MOD : val%MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        if (value == 0)return 0;
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

mint dp[3001][3001][2];

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

    int N, M;
    cin >> N >> M;
    
    rep(i, N + 1)dp[0][i][!i] = 1;

    mint cur;
    rep(i, M)rep(j, N + 1)rep(k, 2) if((cur=dp[i][j][k]).toi()){
        if (j < N) {
            dp[i + 1][j][k] += cur;
            dp[i + 1][j + 1][k] += cur;
        }
        if (j > 0) {
            dp[i + 1][j][(!(j - 1)) | k] += cur;
            dp[i + 1][j - 1][(!(j - 1)) | k] += cur;
        }
    }
    mint ans;
    rep(i, N + 1)ans += dp[M][i][1];
    cout << ans << endl;
}

Measured memory_bytes: 70784
//BECAUSE ONE TRUTH PREVAILS
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL GCD(LL A,LL B)
{
    if(A==0)
    {
        return B;
    }
    return GCD(B%A,A);
}
int main() {
    LL N;
    cin>>N;
    if(360%N==0)
    {
        cout<<360/N<<endl;
    }
    else
    {
        LL LCM=(N*360)/GCD(N,360);
        cout<<(LCM)/(N)<<endl;
    }
}

Measured memory_bytes: 3616
N = int(input())

c = [[0]*10 for _ in range(10)]
for n in range(1,N+1):
    s = str(n)
    c[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int tod(string a){
	int n=a.size();
	int res=0;
	size_t cur=0;
	while(cur<n){
		int tmp=1;
		if(isdigit(a[cur]))
			tmp=(a[cur++]-'0');
		if(a[cur]=='m')
			tmp*=1000;
		else if(a[cur]=='c')
			tmp*=100;
		else if(a[cur]=='x')
			tmp*=10;
		res+=tmp;
		cur++;
	}
	return res;
}

string tos(int a){
	string res="";
	int cur=1000;
	while(a){
		int tmp=a/cur;
		if(tmp>=2)
			res+=(tmp+'0');
		if(tmp){
			switch(cur){
				case 1000:
					res+='m';
					break;
				case 100:
					res+='c';
					break;
				case 10:
					res+='x';
					break;
				case 1:
					res+='i';
					break;
			}
		}
		a-=tmp*cur;
		cur/=10;
	}
	return res;
}

int main(void){
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		string a,b;
		cin >> a >> b;
		int aa,bb,cc;
		aa=tod(a);bb=tod(b);
		cc=aa+bb;
		string c=tos(cc);
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define fordebug int hoge;cin>>hoge;

int main(){
  int t[200000],q,it=0,end=0,n;
  string name[200000];
  cin>>n>>q;
  lp(i,n){
    cin>>name[i]>>t[i];
    end++;
  }
  int count=0,now=0;
  while(count<n){
    if(t[it]<=q){
      now+=t[it];
      cout<<name[it]<<" "<<now<<endl;
      count++;
    }
    else{
      t[it]-=q;
      now+=q;
      if(end==200000) end=0;
      t[end]=t[it];
      name[end]=name[it];
      end++;
    }
    it++;
    if(it==200000) it=0;
  }
  return 0;
}




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

int main(){
    int n,m,sum=0;
    cin>>n>>m;
    vector<int> a(m);
    for(int i=0; i<m; i++) {
        cin>>a[i];
        sum += a[i];
    }
    if(sum>n) cout<<-1;
    else cout<<n-sum;
}

Measured memory_bytes: 3636
let () =
  let s = read_line () in
  print_endline @@
  if
    s.[0] = 'A' &&
    1 = List.length (List.filter (( = ) 'C') @@ Array.to_list @@ Array.init (String.length s - 3) @@ fun i -> s.[i + 2]) &&
    2 = List.length (List.filter (fun c -> Char.code 'A' <= Char.code c && Char.code c <= Char.code 'Z') @@ Array.to_list @@ Array.init (String.length s) @@ fun i -> s.[i])
  then "AC"
  else "WA"


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

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

 int divby500;

 divby500 = N / 500;

 int multiples500;

 multiples500  = 500 * divby500;

 int oneyen;

 oneyen = N - multiples500;

if (A >= oneyen ) {
  std::cout << "Yes" << endl;
} else {
  std::cout << "No" << endl;
}

}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl A(N+1), B(N+1), C(N+1);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i+1];
    rep(i, N) cin >> C[i+1];
    
    ll ans = 0;
    rep(i, N){
        ans += B[A[i]];
    }
    rep(i, N-1){
        if(A[i]+1 == A[i+1]){
            ans += C[A[i]];
        }
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;

long long f(long long n) {
  long long s = 0;
  if (n % 4 == 1 || n % 4 == 2) s ^= 1;
  for (int i = 1; i < 40; i++) {
    long long t = 1LL << i;
    if (n % (2 * t) >= t) {
      if (n % 2 == 0) {
        s ^= 1LL << i;
      }
    }
  }
  return s;
}

int main() {
  long long a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << endl;
}

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

int main()
{
  int n, m; cin >> n >> m;
  vector<int> a(n);
  vector<int> b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  set<int> sta, stb;
  rep(i, n) sta.insert(a[i]);
  rep(i, m) stb.insert(b[i]);
  if (sta.size() != a.size() || stb.size() != b.size()) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  for (int x=n*m; x>=1; x--) {
    if (*lower_bound(a.begin(), a.end(), x) == x
        && *lower_bound(b.begin(), b.end(), x) == x) {
          continue;
        }

    if (*lower_bound(a.begin(), a.end(), x) == x) {
      int t = b.end() - lower_bound(b.begin(), b.end(), x);
      ans *= t;
    } else if (*lower_bound(b.begin(), b.end(), x) == x) {
      int u = a.end() - lower_bound(a.begin(), a.end(), x);
      ans *= u;
    } else {
      int t = b.end() - lower_bound(b.begin(), b.end(), x);
      int u = a.end() - lower_bound(a.begin(), a.end(), x);
      ans *= t * u - (n*m - x);
    }
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {

  int N,x;
  
  cin >>N;
  
  int M=N;
  
  int count=0;
   
  while(N!=0){
  
    x=N%10;
    
    N=(N-x)/10;
    
      count+=x;
    
    
  }
  if(M % count ==0)
    cout<<"Yes"<<endl;
  
  else
    cout<<"No"<<endl;
  
  
  
    
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int gcd(int p, int q){
	while(q != 0){
    	int r = p % q;
      	p = q;
      	q = r;
    }
  	return p;
}
 
int main(){
	int n;
  	cin >> n;
  
  	ll ans = 0;
  	for(int i = 1; i <= n; i++){
    	for(int j = 1; j <= n; j++){
          	for(int k = 1; k <= n; k++){
				ans += gcd(gcd(i, j), k);
            }
        }
    }
 
	cout << ans << endl;  
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void){
  int m,d,w;
  int sum;
  int i;
  while(1){
    scanf("%d %d",&m,&d);
    if(m==0&&d==0)      break;
    else{
      sum=d;
      for(i=1;i<m;i++){
	if(i==2){
	  sum+=29;
	}else if(i==4||i==6||i==9||i==11){
	  sum+=30;
	}else{
	  sum+=31;
	}
      }
      switch(sum%7){
      case 1:
	printf("Thursday\n");
	break;
      case 2:
	printf("Friday\n");
	break;
      case 3:
	printf("Saturday\n");
	break;
      case 4:
	printf("Sunday\n");
	break;
      case 5:
	printf("Monday\n");
	break;
      case 6:
	printf("Tuesday\n");
	break;
      default:
	printf("Wednesday\n");
	break;
      }
    }
    
  }

  return 0;
}

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

using namespace std;

int main()
{
	long long N;

	cin >> N;

	long long X;
	long long ans = -1;


	X = N / 1.08;

	if ((long long)((X + 1) * 1.08) == N)
		ans = X + 1;
	else if ((long long)((X - 1) * 1.08) == N)
		ans = X - 1;
	else if ((long long)(X) * 1.08 == N)
		ans = X;


	if (ans != -1)
		cout << ans << endl;
	else
		cout << ":(" << endl;
}


Measured memory_bytes: 3568
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e3 + 5;
int main() {
    abdelrahman010
    char c;
    for(int i = 0;i < 3;i++) {
        cin >> c;
        if(c == '7')
            return cout << "Yes" , 0;
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans=0;
  vector<int> v(n);
  vector<int> c(n);
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n;i++)cin>>c[i];
  for(int i=0;i<n;i++){
    if(v[i]>c[i])ans+=v[i]-c[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,m;
while(cin>>m>>n){
 int x[m+1]={0};
 for(i=0;i<n;i++){
    cin>>k>>j;
    x[j]++;
    x[k]++; }
    j=0;
    for(i=1;i<=m;i++) cout<<x[i]<<endl;
} return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_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())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) a=a*a%MOD;
		else res=res*a%MOD;
		b>>=1;
	}
	res=res*a%mod;
	return res;
}
*/


int main()
{
	//IOS;
	int n;
	cin>>n;
	cout<<n/3;

	return 0;
}


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

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

    auto min_counts = array<int, 26>{};
    min_counts.fill(numeric_limits<int>::max());

    for (auto i = 0; i < n; i++)
    {
        string s; cin >> s;

        auto counts = array<int, 26>{};
        for (const auto c : s)
            counts[c-'a']++;

        for (auto i = 0; i < 26; i++)
            min_counts[i] = min(min_counts[i], counts[i]);
    }

    for (auto i = 0; i < 26; i++)
        for (auto j = 0; j < min_counts[i]; j++)
            cout << char('a'+i);
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string x;
  cin >> x;
  int ans = 0;
  int s = 0;
  for(auto c:x){
    if(c=='S') s++;
    else if(s == 0) ans++;
    else s--;
  }
  ans += s;
  cout << ans << endl;
}

Measured memory_bytes: 3704
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    vll a(n), b(n);
    rep(i, n) cin >> a[i];
    b = a;
    ll s = 0;
    rep(i, n) {
        s += a[i];
    }

    ll ans = 0;
    rep(i, n-1){
        s = (s - a[i] + MOD)%MOD;
        ll t = (a[i] * s)%MOD;
        ans = (ans+t)%MOD;
    }
    pr(ans);

    return 0;}

Measured memory_bytes: 6360