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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int X = 0;
  while(1) {
    vector<vector<int>> tmp(3, vector<int>(3));
    tmp[0][0] = A;
    tmp[0][1] = B;
    tmp[1][1] = C;
    tmp[2][1] = X - B - C;
    tmp[2][2] = X - A - C;
    tmp[0][2] = X - A - B;
    tmp[1][2] = X - tmp[0][2] - tmp[2][2];
    tmp[1][0] = X - C - tmp[1][2];
    tmp[2][0] = X - tmp[2][1] - tmp[2][2];
    if(tmp[0][0] + tmp[1][0] + tmp[2][0] == X && tmp[0][2] + tmp[1][1] + tmp[2][0] == X) {
      REP(i,3) {
        REP(j,3) {
          if(j) cout << " ";
          cout << tmp[i][j];
        }
        cout << endl;
      }
      break;
    }
    ++X;
  }
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
#define	MAXPRIME	999999
using namespace std;

typedef unsigned int uint;

void setPrimeFlag(bool *primeFlag, uint maxPrime) {
	uint sq = (uint)sqrt((double)maxPrime) + 1;
	for (uint i = 2; i <= maxPrime; ++i) { primeFlag[i] = true; }
	primeFlag[0] = primeFlag[1] = false;
	for (uint i = 2; i <= sq; ++i) {
		if (primeFlag[i]) {
			for (uint j = i + i; j <= maxPrime; j += i) {
				primeFlag[j] = false;
			}
		}
	}
}

void setPrimeArray(vector<uint> &primeArray, uint maxPrime) {
	bool *primeFlag = new bool[maxPrime + 1];
	setPrimeFlag(primeFlag, maxPrime);

	primeArray.clear();
	for (uint i = 2; i <= maxPrime; ++i) {
		if (primeFlag[i]) {
			primeArray.push_back(i);
		}
	}
	delete [] primeFlag;
}

int main() {
	vector<uint> primeArray;
	setPrimeArray(primeArray, MAXPRIME);

	for (;;) {
		uint n, num;
		cin >> n;
		if (cin.eof()) { break; }

		for (num = 0; num < primeArray.size() && primeArray[num] <= n; ++num);

		cout << num << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXK = -1;
const int MAXN = 1 << MAXK;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1.01e9;

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n;
	while (cin >> n) {
		vector<pair<int, int> > ed(n - 1);
		vector<set<int> > e(n);
		for (int i = 0; i < n - 1; i++) {
			cin >> ed[i].first >> ed[i].second;
			ed[i].first--;
			ed[i].second--;
			e[ed[i].first].insert(ed[i].second);
			e[ed[i].second].insert(ed[i].first);
		}
		//set<int> leafs;
		vector<vector<int> > neib(n);
		for (int i = 0; i < n; i++) {
			if (e[i].size() == 1) {
				//leafs.insert(i);
				neib[*e[i].begin()].push_back(i);
			}
		}
		set<pair<int, int> > st;
		for (int i = 0; i < n; i++) {
			st.insert(make_pair(-(int)neib[i].size(), i));
		}
		bool ans = 0;
		while (!st.empty()) {
			if (-st.begin()->first != 1) {
				ans = 1;
				break;
			}
			int v = st.begin()->second;
			int le = neib[v][0];
			st.erase(make_pair(-(int)neib[v].size(), v));
			st.erase(make_pair(-(int)neib[le].size(), le));
			for (int to : e[v]) {
				e[to].erase(v);
				if (to != le && e[to].size() == 1) {
					int toto = *e[to].begin();
					st.erase(make_pair(-(int)neib[toto].size(), toto));
					neib[toto].push_back(to);
					st.insert(make_pair(-(int)neib[toto].size(), toto));
				}
			}
		}
		cout << (ans ? "First" : "Second") << endl;
	}

	return 0;
}

Measured memory_bytes: 23296
N =int(input())
A = list(map(int,input().split()))
COUNT = [0]*10000

def cnt_sort(A):
    res = [""] * len(A)
    for a in A:
        COUNT[a]+=1
    for i in range(1,len(COUNT)):
        COUNT[i] = COUNT[i] + COUNT[i-1]
    for a in A:
        res[COUNT[a]-1] = str(a)
        COUNT[a] -=1
    return res

print(" ".join( cnt_sort(A)))


Measured memory_bytes: 224504
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N, K, Q = InputToInt()
    S = [K-Q]*N
    for i in range(Q):
        S[int(input())-1] += 1
    for i in range(N):
        if S[i] > 0:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 6580
//#include <bits/stdc++.h>/*
#include <unordered_map>
#include <functional> //greater
#include <algorithm> //sort
#include <iostream>
#include <iterator>
#include <utility> //pair
#include <sstream>
#include <cstring> //memset
#include <complex>
#include <cassert>
#include <random>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype> //isaplha, tolower
#include <deque>
#include <queue>
#include <stack>
#include <array>
#include <cmath> //sqrt, sin
#include <ctime>
#include <list>
#include <map>
#include <set>
//*/
 
#define int long long
#define uns unsigned
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl '\n'
using namespace std;
 
template<class T> ostream &operator<<(ostream &os, const pair<T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const pair<const T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const array<T,3> &p){
	return os<<"("<<p[0]<<","<<p[1]<<","<<p[2]<<")";}
template<class T> ostream &operator<<(ostream &os, const vector<T> &p){
	for(auto x: p) os<<x<<' '; return os;}
#define dbug(x) cerr<<">>>> "<<#x<<" = "<<x<<endl
#define _ <<", "<<
#define FOR(X,L,R) for(int X=L;X<R;X++)
#define FI(I,X) for(auto I=(X).begin();I!=(X).end();I++)
#define print(X) {cerr<<"{ ";FI(I,X)cerr<<*I<<' ';cerr<<"}"<<endl;}
#define mset(V,X) memset(V,X,sizeof(V))
#define all(X) (X).begin(),(X).end()
#define upperb(V,X) (int)(upper_bound(all(V),(X))-V.begin())
#define lowerb(V,X) (int)(lower_bound(all(V),(X))-V.begin())
 
const double EPS = 1e-9, PI = acos(-1);
const ll LINF = 0x3f3f3f3f3f3f3f3f, mod = 1e9+7;
const int INF = 0x3f3f3f3f, SZ = 2e5+20;

int n,v[100010],k;
int dp[100010];
int pd(int i){
	if(dp[i] != -1) return dp[i];
	dp[i] = INF;
	for(int j=i-1; j>=max(0LL,i-k); j--) dp[i] = min(dp[i], pd(j)+abs(v[i]-v[j]) );
	return dp[i];
}
 
int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);
	
	mset(dp,-1);
	cin>>n>>k;
	FOR(i,0,n) cin>>v[i];
	dp[0] = 0;
	cout<<pd(n-1)<<endl;
 
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in);
        
        for(int i=0;i<5;i++){
            int in = scan.nextInt();
            if(in==0)
                System.out.println(i+1);
        }
    }
}

Measured memory_bytes: 26856
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    map<int, int> m1, m2;
    int f = 0;
    while(getline(cin, s)){
        if(s.empty()){
            f++;
            continue;
        }
        int a = 0, b = 0, c = 0;
        for (auto &&i : s) {
            if(i == ',') c++;
            else if(!c) a = a*10+(i-'0');
            else b = b*10+(i-'0');
        }
        if(f) m2[a]++;
        else m1[a]++;
    }
    for (auto &&i : m1) {
        if(m2.count(i.first)){
            printf("%d %d\n", i.first, i.second+m2[i.first]);
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef double db;
typedef pair<int, int> pii;typedef pair<ll, ll> pll;
typedef pair<int,ll> pil;typedef pair<ll,int> pli;
#define Fi first
#define Se second
#define _Out(a)	cerr<<#a<<" = "<<(a)<<endl
const int INF = 0x3f3f3f3f, MAXN = 1e3 + 7;
const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 1e9+7;
const db Pi = acos(-1), EPS = 1e-6;
void test(){cerr << "\n";}template<typename T,typename...Args>void test(T x,Args...args){cerr<<x<<" ";test(args...);}
inline ll qpow(ll a, ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;}
inline ll qpow(ll a, ll b,ll c){return b?((b&1)?a*qpow(a*a%c,b>>1,c)%c:qpow(a*a%c,b>>1,c)) %c:1;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll cede(ll a,ll b){if(b<0)return cede(-a,-b);if(a<0)return a/b;return (a+b-1)/b;}
inline ll flde(ll a,ll b){if(b<0)return flde(-a,-b);if(a<0)return (a-b+1)/b;return a/b;}
inline int sign(db x){return x<-EPS ? -1:x>EPS;}
inline int dbcmp(db l,db r){return sign(l - r);}
namespace Fast_IO{ //orz laofu
    const int MAXL((1 << 18) + 1);int iof, iotp;
    char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55];
    char Getchar(){
        if (ioiS == ioiT){
            ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++);
        }else return (*ioiS++);
    }
    void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;}
    void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();}
    inline int read(){
        int x=0;for(iof=1,ioc=Getchar();ioc<'0'||ioc>'9';)iof=ioc=='-'?-1:1,ioc=Getchar();
        for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
    }
    inline long long read_ll(){
        long long x=0;for(iof=1,ioc=Getchar();ioc<'0'||ioc>'9';)iof=ioc=='-'?-1:1,ioc=Getchar();
        for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
    }
    template <class Int>void Print(Int x, char ch = '\0'){
        if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10;
        while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch);
    }
    void Getstr(char *s, int &l){
        for(ioc=Getchar();ioc <'a'||ioc>'z';)ioc=Getchar();
        for(l=0;ioc<='z'&&ioc>='a';ioc=Getchar())s[l++]=ioc;s[l] = 0;
    }
    void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);}
} // namespace Fast_IO
using namespace Fast_IO;



char S[MAXN],T[MAXN];
void work()
{
    int n,m;
    Getstr(S+1,n);
    Getstr(T+1,m);
    int ans=INF;
    for(int i=1;i<=n-m+1;i++)
    {
        int now=0;
        for(int j=1;j<=m;j++)
        {
            if(S[i+j-1]!=T[j])now++;
        }
        ans=min(ans,now);
    }
    printf("%d\n",ans);
}

int main()
{
    //std::ios::sync_with_stdio(false);
   // int T=read();for(int cas=1;cas<=T;cas++)
    //int T;scanf("%d",&T);for(int i=1;i<=T;i++)
    work();
    // Write();
}
/*
3
6 9 2 1 1 1 4 1 3 3
6 9 2 1 1 1 5 1 4 3
6 9 2 1 1 1 5 1 5 3
6 9 2 1 1 1 8 1 6 3
6 9 2 1 1 1 8 1 7 4

5 6 4 1 1 4 3 999 1 10
10 10 4 1 1 3 7 999 1 100
10 10 4 1 1 8 9 999 1 100
*/

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int s = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  int x = round((double)s / n);
  s = 0;
  for (int i = 0; i < n; i++) {
    s += (x - a[i]) * (x - a[i]);
  }
  cout << s << '\n';
  return 0;
}

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

ll sum(ll k, vector<ll> e){
    ll sum = 0;
    rep(i,k) sum += e[i];
    return sum;
}

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    rep(i,n) cin >> p[i];
    vector<ll> e(n);
    rep(i,n) e[i] = p[i]+1;
    vector<ll> s(n-k+1);
    s[0] = sum(k,e);
    ll champ = s[0];
    rep(i,n-k){
        s[i+1] = s[i] - e[i] + e[i+k];
        if (s[i+1] > champ) champ = s[i+1];
    }
    double res = (double)(champ)/2;
    
    printf("%f\n",res);
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

int main(){
  int X, Y;
  cin >> X >> Y;
  if(2*X<=Y&&Y<=4*X&&Y%2==0){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3640
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

import javax.swing.plaf.synth.SynthSeparatorUI;

public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int K = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		
		for(int i = 0; i < N; i++){
			int a = in.nextInt();
			Integer count = map.get(a);
			if(count == null) map.put(a, 1);
			else map.put(a, count+1);
		}
		
		if(map.size() <= K){
			System.out.println(0);
			return;
		}
		
		List<Entry<Integer, Integer>> listEntries = new ArrayList<Entry<Integer, Integer>>(map.entrySet());
        
        Collections.sort(listEntries, new Comparator<Entry<Integer, Integer>>() {
            public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
                return obj2.getValue().compareTo(obj1.getValue());
            }
        });
        
        int ans = 0;
        for(int i = K; i < listEntries.size(); i++) {
        	Entry e = listEntries.get(i);
        	ans += (int)e.getValue();
            //System.out.println(e.getKey() + " : " + e.getValue());
        }
        System.out.println(ans);
	}
}

Measured memory_bytes: 98292
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long sum = 0;
    long sumMax = 0;

    for(int i = 0; i < k; i++) sum += nums[i];
    sumMax = sum;

    for(int i = 0; i < n-k; i++)
    {
      sum -= nums[i];
      sum += nums[i+k];

      sumMax = Math.Max(sumMax,sum);
      //Console.WriteLine(i+" "+sum);
    }

		Console.WriteLine((sumMax+k)/(double)2);
	}
}


Measured memory_bytes: 31068
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;
const int MAX_V = 1001;

vector<vector<ll> > d(MAX_V, vector<ll>(MAX_V, INFLL)); //距離と隣接行列を兼ねる（ただし対角=0とする）
vector<vector<ll> > pre(MAX_V, vector<ll>(MAX_V, 0)); //iからjへの最短経路でjの前の点
ll n; 
void warshall_floyd(bool rep_pre = true) {
    if(rep_pre) {
        for (ll i = 0; i < n; i++) {
            for (ll j = 0; j < n; j++) {
                pre[i][j] = i;
            }
        }
    }
    for (ll k = 0; k < n; k++) {
        for (ll i = 0; i < n; i++) {
            for (ll j = 0; j < n; j++) {
                ll a = d[i][j];
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                if(rep_pre && a != d[i][j]) {
                    pre[i][j] = pre[k][j]; //iからjへの最短経路でjの前の点
                }
            }
        }
    }
}

void get_path(ll s, ll t) {
    while (t != s) {
        cout << t;
        t = pre[s][t];
    }
    cout << s << endl;
}

int main () {

    cin >> n;  //★ちゃんと指定することに注意！！
    ll m,r; cin >>m>>r;
    ll array[r]; REP(i,r) cin >> array[i];
    REP (i,n) d[i][i] = 0;
    for (ll i = 0; i < m; i++) {
        ll f,t,c; cin >>f>>t>>c;
        f--;
        t--;
        d[f][t] = c;
        d[t][f] = c; //無向グラフのとき
    }
    warshall_floyd(true);
    
    sort(array, array+r);
    ll res = INFLL;
    do {
        ll sum = 0;
        for(ll i=0; i<r-1; i++){
            ll s = array[i];
            s--;
            ll t = array[i+1];
            t--;
            sum += d[s][t];
        }
        res = min(res, sum);
    } while (next_permutation(array, array+r));

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 16000
#include <stdio.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int y;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		y = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) y++;
			}
		}
		printf("%d\n", y);
	}
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int a_func(int x)
{
    return x * 2;
}

int b_func(int x, int k)
{
    return x + k;
}


int main()
{
    int n, k = 0;
    cin >> n >> k;
    int sum = 1;
    int a_num = 0;
    int b_num = 0;

    REP(i, n)
    {
        a_num = a_func(sum);
        b_num = b_func(sum, k);

        sum = min(a_num, b_num);
    }

    COUT(sum);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, m;
    cin >> n >> m;

    vector < vector <int> > vec(m, vector <int>());
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int s;
            cin >> s;
            s--;
            vec[i].push_back(s);
        }
    }

    vector <int> p(m);
    for (int i = 0; i < m; i++) cin >> p[i];

    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        bool f = true;

        for (int j = 0; j < m; j++) {
            int sz = vec[j].size();

            int cnt = 0;
            for (int k = 0; k < sz; k++) {
                int s = vec[j][k];
                if (i & (1 << s)) {
                    cnt++;
                }
            }

            if (cnt % 2 != p[j]) f = false;
        }

        if (f) ans++;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

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


int main() {
  int n; cin>>n;
  string s; cin>>s;
  string ans;
  string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  rep(i, s.size()) {
    char t = abc[s[i]-'A'+n];
    ans += t;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int num = 0;
	int mountains[10];
	for (int i = 0; i < 10; i++){
		cin >> mountains[i];
	}
	sort(mountains,mountains+10);
	cout << mountains[9] << endl;
	cout << mountains[8] << endl;
	cout << mountains[7] << endl;
	return 0;
}

Measured memory_bytes: 3148
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool leap(int y) {
    if (y%4) return false;
    if (y%400==0) return true;
    return y%100;
}

int main() {
    for (int _q = 0;; _q++) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (a == 0 && b == 0) return 0;
        if (_q) puts("");
        int c = 0;
        for (int i = a; i <= b; i++) if (leap(i)) {
            printf("%d\n", i);
            c++;
        }
        if (c == 0) puts("NA");
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
    char X,Y,Z;
    scanf("%c%c%c",&X,&Z,&Y);

    if(X<Y){
        printf("<");
    }
    else if(X>Y){
        printf("> ");
    }
     else if (X==Y){
        printf("=");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,
73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,
179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,
283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,
419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,
547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,
811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,
947,953,967,971,977,983,991,997};
		int[] numPrime = new int[168];
		for(int i=0; i<168; i++){
			numPrime[i] = 0;
		}
		int work=0;
		long ans=1;

		for(int i=2; i<=n; i++){
                        work=i;
			for(int j=0; j<168; j++){
				while( work%prime[j] == 0 ){
					work/=prime[j];
					numPrime[j]++;
				}
			}
		}

		for(int i=0; i<168; i++){
			ans = ans*(numPrime[i] + 1)%1000000007;
		}

		System.out.println(ans);
		return;
	}
}

Measured memory_bytes: 9808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * A-Z Cat
 */
public class Main {

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

		line = br.readLine();
		Deque<Character> az = new ArrayDeque<>();

		boolean a = true;
		for (int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			if (c == 'A' && a) {
				az.add(c);
				a = false;
			}
			if (c == 'Z' && !a) {
				az.add(c);
				a = true;
			}
		}
		if (!az.isEmpty() && az.peekLast() == 'A') {
			az.pollLast();
		}

		if (!az.isEmpty()) {
			StringBuilder sb = new StringBuilder();
			for (char c : az) sb.append(c);
			System.out.println(sb.toString());
		} else {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 24512
n, m, x = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

mi = 10**10
for i in range(2**n):
    skill = [0]*m
    price = 0
    for j in range(n):
        if (i>>j)&1:
            price += a[j][0]
            for k in range(m):
                skill[k] += a[j][k+1]
    for k in skill:
        if k<x:
            break
    else:
        mi = min(mi, price)
print(mi if mi<10**10 else -1)

Measured memory_bytes: 68492
using System;
using System.Linq;
using System.Collections.Generic;

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var n = N.ToString().Length;
            var res = 0;
            for(var i = 0; i < n; i++)
            {
                if((i+1) % 2 == 1)
                {
                    if ((i+1) == n) res += N - (int)Math.Pow(10, i) + 1;
                    else res += (int)Math.Pow(10, i + 1) - (int)Math.Pow(10, i);
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include<cstdio>
using namespace std;
typedef long long ll; 


int main(){
    ll t;
    scanf("%lld",&t);
    if(t>=30) printf("Yes");
	else printf("No"); 
    /*while(t--){
    	ll n;
    	scanf("%lld",&n);
    	
    
    }*/

    
    return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin>>N;
	set<string>S;
	
	for(int i=0; i<N; i++)
	{
		string words;
		cin>>words;
		S.insert(words);
	}
	cout<<S.size();
	return 0;
	

}

Measured memory_bytes: 19176
#include <iostream>
#include <algorithm>
static const int MAX_N = 100;
static const int MAX_W = 10000;
using namespace std;

struct Item {
    int v;
    int w;
};

int N, W;
Item items[MAX_N+1];
int dp[MAX_N+1][MAX_W+1];

int main(void) {
    cin >> N >> W;
    for (int w = 0; w <= W; w++) {
        dp[0][w] = 0;
    }
    for (int i = 1; i <= N; i++) {
        cin >> items[i].v >> items[i].w;
    }

    for (int i = 1; i <= N; i++) {
        for (int w = 1; w <= W; w++) {
            if (items[i].w <= w) {
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-items[i].w] + items[i].v);
            } else {
                dp[i][w] = dp[i-1][w];
            }
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 5104
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var a, z int
	var A bool
	for i := 0; i < len(s); i++ {
		if s[i] == 'A' && !A {
			a = i
			A = true
		}
		if s[i] == 'Z' {
			z = i
		}
	}
	fmt.Println(z - a + 1)
}


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

int main() {
  int a,b;
  cin>>a>>b;
  if(a<=5){
    cout<<0<<endl;
  }
  else if(a<13){
    cout<<b/2<<endl;
  }
  else{
    cout<<b<<endl;
  }
  
}



Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
        List<string> input = Console.ReadLine().Split(' ').ToList();
        List<long> v = new List<long>();

        input.ForEach(x => v.Add(long.Parse(x)));

        if(v[0] >= v[2])
        {
            Console.WriteLine("{0} {1}", v[0] - v[2], v[1]);
        }
        else
        {
            Console.WriteLine("{0} {1}", 0, Math.Max(0, v[0] + v[1] - v[2]));
        }

        Console.ReadKey();
    }
}

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

int main()
{
  int N;
  cin >> N;
  int count;
  for (int i = 0; i < N; i++)
  {
    int l, r;
    cin >> l >> r;
    count += (r - l + 1);
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

typedef string::const_iterator State;
int countMinus(State&);
int negative(int,int);
int number(State&);
int factor(State&);
int expression(State&);

int p, q, r;

int inverted(int ret){
    if(ret == 0) return 2;
    else if(ret == 2) return 0;
    else return 1;
}

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;
    if(*begin == 'P') ret = p;
    else if(*begin == 'Q') ret = q;
    else if(*begin == 'R') ret = r;
    else if(isdigit(*begin)) ret = *begin - '0';
    else return 0;

    begin++;
    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    int ret;
    if (*begin == '(') {
        begin++; // '('????£???°??????
        ret = expression(begin);
        begin++; // ')'????£???°??????
        return ret;
    }else {
        return number(begin);
    }
}

int term(State &begin){
    if (*begin == '-') {
        begin++;
        return inverted(term(begin));
    } else {
        return factor(begin);
    }
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret = max(ret, term(begin));
        } else if (*begin == '*') {
            begin++;
            ret = min(ret, term(begin));
        } else {
            break;
        }
    }

    return ret;
}

int main(){
    string s;
    while(cin >> s, s[0] != '.'){
        int cnt = 0;
        for(p = 0; p < 3; p++){
            for(q = 0; q < 3; q++){
                for(r = 0; r < 3; r++){
                    State tmp = s.begin();
                    if(expression(tmp) == 2){
                        //cout << p << ' ' << q << ' ' << r << endl;
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3128
#include <stdio.h>

int main()
{
	int i,j;
	int height[10];
	int maxh,maxn;
	for(i = 0;i < 10;i++)
	{
		scanf("%d",&height[i]);
	}
	for(i = 0;i < 3;i++)
	{
		maxh = height[0];
		maxn = 0;
		for(j = 1;j < 10;j++)
		{
			if(height[j] > maxh)
			{
				maxh = height[j];
				maxn = j;
			}
		}
		printf("%d\n",maxh);
		height[maxn] = 0;
	}
	return 0;
}

Measured memory_bytes: 0
S = list(input())
odds = S[0::2]
evens = S[1::2]

good_odd = ['R', 'U', 'D']
good_even = ['L', 'U', 'D']

for odd in odds:
    if odd in good_odd:
        pass
    else:
        print('No')
        exit()
for even in evens:
    if even in good_even:
        pass
    else:
        print('No')
        exit()
print('Yes')        
    

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

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var abk = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var diff = abk[0] - abk[2];
            var a = diff <= 0 ? 0 : diff;
            var b = abk[1] + (diff >= 0 ? 0 : diff);
            b = (b < 0 ? 0 : b);
            Console.WriteLine($"{a} {b}");
        }
    }
}


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

const ll MOD = 998244353;

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

int main() {
    int N;
    cin>>N;
    vector<ll> D(N),C(N,0);
    rep(i,N){
        cin>>D[i];
        C[D[i]]++;
    }
    if(D[0] != 0||C[0]>1){
        cout<<0<<endl;
        return 0;
    }
    ll ans = 1;
    rep(i,N-1){
        ans *= modpow(C[i],C[i+1],MOD);
        ans %= MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = 0;
        int tap = 1;
        while (tap<b){
            tap--;
            tap+=a;
            ans++;
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,m,k;cin>>n>>m>>k;
  bool ans=false;
  rep(i,n+1){
    rep(j,m+1){
      int sum=i*m+j*n-2*i*j;
      if(sum==k){
        ans=true;
        break;
      }
    }
  }
  	if(ans){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi2;
typedef pair<int,pair<int,int> > pi3;
typedef vector<string> vs;
typedef pair<double,double> pdd;
const double PI  = acos(-1.0);
int dp1[3001][3001];
int fn[3010];
int co[3010];
int main(){
    int n,t,s;
    cin>>n>>t>>s;
    rep(i,n){
        cin>>fn[i];
        cin>>co[i];
    }
    reep(i,n+1,1){
        reep(j,s+1,1){
            dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]);
            if(co[i-1]<=j)dp1[i][j]=max(dp1[i][j],dp1[i-1][j-co[i-1]]+fn[i-1]);
        }
    }
    rep(i,n+1)dp1[i][0]=dp1[i][s];
    rep(i,n+1)
        reep(j,t+1,1)dp1[i][j]=0;
    reep(i,n+1,1){
        reep(j,t-s+1,1){
            dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]);
            if(co[i-1]<=j)dp1[i][j]=max(dp1[i][j],dp1[i-1][j-co[i-1]]+fn[i-1]);
        }
    }
    cout<<dp1[n][t-s]<<endl;
}

Measured memory_bytes: 36368
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using p = pair<int, int>;
using ll = long long;


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

    while(n) {
        n--;
        ans += 'a' + n % 26;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;


int main(){
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	int i;
	for (i = 0;i < N;i++) cin >> S.at(i);
	sort(S.begin(), S.end());
	string t;
	for (i = 0;i < N;i++) t += S.at(i);
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define COUT(a) cout << a << endl;

int main(){
    ll a, b, x , res =0;
    cin >> a >> b >>x;
    ll tmp0 = a%x==0 ? a : x*(a/x)+x;
    ll tmp1 = b%x==0 ? b : x*(b/x);
    res = max((tmp1-tmp0)/x+1,(ll)0);
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    int logk=1;
    while((1LL<<logk)<k){
        logk++;
    }
    vector<vector<int>> d(logk,vector<int>(n));
    rep(i,n){
        d[0][i]=a[i];
    }
    rep(i,logk-1){
        rep(j,n){
            d[i+1][j]=d[i][d[i][j]];
        }
    }
    int now=0;
    int cnt=0;
    while(k){
        if(k&1){
            now=d[cnt][now];
        }
        cnt++;
        k>>=1;
    }
    cout << now+1 << endl;
}

Measured memory_bytes: 51756
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  ll ans = A * x / B - A * (x / B);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define pi pair<int,int>
using namespace std;
int main(){
	int n  , k;
	cin>> n >> k  ; 
	vector<ll> a(n)   , dp(n); 
	for(ll & x: a) cin>> x ; 
	dp[0] = 0 ; 
    for(int i = 1 ; i < k && i < n  ; ++i){
		dp[i] = abs(a[i] - a[0])  ;
	}
	for(int i = k ; i < n  ; ++i){
		   ll ans = LLONG_MAX ; 
		   for(int j = i - 1 ; j >= i - k ; --j){
			   ans = min(ans , dp[j] + abs(a[i] - a[j])) ; 
		   }
		   dp[i] = ans;
	   }
	   cout<<dp[n-1]<<endl;  
    
}


Measured memory_bytes: 1920
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 200010;

ll res;
int f[MAXN];
int c0[MAXN];
int c1[MAXN];
int fa[MAXN];

struct Node {
	int x, c0, c1;

	Node() {}
	Node(int x):x(x) { c0 = ::c0[x], c1 = ::c1[x]; }

	friend bool operator < (Node a, Node b) {
		return 1LL * a.c0 * b.c1 < 1LL * a.c1 * b.c0;
	}
	friend bool operator > (Node a, Node b) {
		return 1LL * a.c0 * b.c1 > 1LL * a.c1 * b.c0;
	}
};

priority_queue<Node, vector<Node>, less<Node> >q;

inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void Merge(int x, int y) {
	x = find(x), y = find(y), fa[x] = y;
	res += 1LL * c0[x] * c1[y];
	c0[y] += c0[x], c1[y] += c1[x];
}

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri;
	for(int i = 2; i <= n; i++) f[i] = ri;
	for(int i = 1; i <= n; i++) fa[i] = i;
	for(int i = 1; i <= n; i++) ri ? c1[i]++ : c0[i]++;
	for(int i = 2; i <= n; i++) q.push(Node(i));
	while(!q.empty()) {
		Node x = q.top(); q.pop();
		if(x.c0 != c0[x.x] || x.c1 != c1[x.x]) continue;
		Merge(x.x, f[x.x]);
		if(find(x.x) > 1) q.push(Node(find(x.x)));
	} cout << res << endl;
	return 0;
}

Measured memory_bytes: 8180
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

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



int main(){
    ld l;
    cin>>l;
    ld ans = (l/3)*(l/3)*(l/3)*1.0;
    cout<<setprecision(100)<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
long int diff(long int a, long int b)
{
    if(a>b)
        return(a-b);
    else
        return(b-a);
}
int main()
{
    long int n,i;
    cin>>n;
    vector<long int>v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    long int dp[n+1];
    dp[0]=0;
    if(v[1]>v[0])
        dp[1]=v[1]-v[0];
    else
        dp[1]=v[0]-v[1];
    for(i=2;i<n;i++)
    {
        if(dp[i-1]+diff(v[i],v[i-1])>dp[i-2]+diff(v[i],v[i-2]))
            dp[i]=dp[i-2]+diff(v[i],v[i-2]);
        else
            dp[i]=dp[i-1]+diff(v[i],v[i-1]);

    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include<iostream>
#include<map>
#include<vector>

using namespace std;
//typedef pair<int,int> P;
int main(void){
    int n;
    cin>>n;
    vector<pair<int,int>> ball;
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        ball.push_back(pair<int,int>(x,y));
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            int x=ball[i].first-ball[j].first;
            int y=ball[i].second-ball[j].second;
            //cout<<x<<" "<<y<<endl;
            auto itr=m.find(pair<int,int>(x,y));
            if(itr==m.end()){
                m.insert(make_pair(pair<int,int>(x,y),1));
            }else{
                int hoge=(*itr).second;
                hoge++;
                m.erase(pair<int,int>(x,y));
                m.insert(make_pair(pair<int,int>(x,y),hoge));
            }

            /*for(auto i=m.begin();i!=m.end();i++){
                cout<<"("<<(*itr).first.first<<" "<<(*itr).first.second<<") "<<(*itr).second<<endl;
            }*/
        }
    }
    int max=0;
    for(auto i=m.begin();i!=m.end();i++){
        if(max<(*i).second)max=(*i).second;
    }
    cout<<n-max<<endl;

    return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!

N=int(input())
res=[0]*4
for i in range(N):
    moji=input()
    if moji == 'AC':
        res[0] += 1
    elif moji == 'WA':
        res[1] += 1
    if moji == 'TLE':
        res[2] += 1
    if moji == 'RE':
        res[3] += 1

print('AC x '+str(res[0]))
print('WA x '+str(res[1]))
print('TLE x '+str(res[2]))
print('RE x '+str(res[3]))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<pair<int,ll>> E[101010];
int mask[2][101010];

ll V[2][101010];
ll ret;
int ok;

void dfs(int id,ll v,int cur) {
	
	if(V[id][cur]==1LL<<60) {
		V[id][cur]=v;
		FORR(e,E[cur]) dfs(id,e.second-v,e.first);
	}
	else if(V[id][cur]!=v) {
		cout<<0<<endl;
		exit(0);
	}
}



void dfs1(int cur,ll v) {
	if(mask[v][cur]) return;
	mask[v][cur]=1;
	FORR(e,E[cur]) dfs1(e.first,v^1);
}

void dfs11(int id,int cur,ll v) {
	if(V[id][cur]==1LL<<60) {
		V[id][cur]=v;
		FORR(e,E[cur]) dfs11(id^1,e.first,e.second-v);
	}
	else if(V[id][cur]!=v) {
		cout<<0<<endl;
		exit(0);
	}
}

void dfs12(int cur,ll v) {
	if(v<=0) {
		ok=0;
		return;
	}
	if(V[0][cur]==1LL<<60) {
		V[0][cur]=v;
		FORR(e,E[cur]) dfs12(e.first,e.second-v);
	}
	else if(V[0][cur]!=v) {
		ok=0;
	}
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
		E[y-1].push_back({x-1,r});
	}
	
	dfs1(0,0);
	
	if(mask[1][0]==1) {
		FOR(x,N) V[0][x]=V[1][x]=1LL<<60;
		dfs11(0,0,0);
		ok=1;
		
		ret=abs(V[0][0]-V[1][0]);
		if(ret%2) {
			cout<<0<<endl;
			return;
		}
		ret/=2;
		FOR(x,N) V[0][x]=1LL<<60;
		dfs12(0,ret);
		cout<<ok<<endl;
		return;
		
		
	}
	else {
		FOR(i,2) {
			FOR(x,N) V[i][x]=1LL<<60;
			dfs(i,i,0);
		}
		
		ll L=1,R=1LL<<60;
		for(i=1;i<N;i++) {
			ll dif=V[1][i]-V[0][i];
			assert(abs(dif)==1);
			
			if(dif==1) {
				L=max(L,1-V[0][i]);
			}
			if(dif==-1) {
				R=min(R,V[0][i]-1);
			}
		}
		cout<<max(0LL,R-L+1)<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

vector<vector<vector<double>>> dp(301,vector<vector<double>>(301,vector<double>(301,-1)));
ll n;

double dfs(ll i, ll j, ll k) {
  if(dp[i][j][k]>-1) return  dp[i][j][k];
  if(i==0&&j==0&&k==0) return 0;
  double res=0;
  if(i) res+=dfs(i-1,j,k)*i;
  if(j) res+=dfs(i+1,j-1,k)*j;
  if(k) res+=dfs(i,j+1,k-1)*k;
  res+=n;
  res*=1.0/(i+j+k);
  return dp[i][j][k]=res;
}

int main() {
  cin >> n;
  ll one=0,two=0,three=0;
  for(ll i=0;i<n;i++) {
    ll a;
    cin >> a;
    if(a==1) one++;
    else if(a==2) two++;
    else three++;
  }
  double ans=dfs(one,two,three);
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 216960
package main
 
import(
  "fmt"
	"bufio"
	"os"
	"strings"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}
 
func abc140b(N int){
	var A []int
	var B []int
	var C []int
	bef := 0
	sum := 0
	for i := 0; i < N; i++{
		fmt.Scan(&bef)
		A = append(A,bef)
	}
	for i := 0; i < N; i++{
		fmt.Scan(&bef)
		B = append(B,bef)
	}
	for i := 0; i < N-1; i++{
		fmt.Scan(&bef)
		C = append(C,bef)
	}
	bef = -1
	for i := 0; i < N; i++{
		sum+=B[A[i]-1]
		if A[i]-1 == bef{
			sum+=C[bef-1]
		}
		bef = A[i]
	}
	fmt.Println(sum)
}	
 
func main(){
	x := 0
	fmt.Scan(&x)
	abc140b(x)
}

Measured memory_bytes: 640