akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	vector<ll> A(26);
	string S;
	cin >> S;
	rep(i, S.size()) {
		int s = S.at(i) - 97;
		A.at(s)++;
	}
	ll an = -1;
	rep(i, 26) {
		if (A.at(i) == 0) {
			an = i;
			break;
		}
	}
	if (an > -1) {
		char AN = an + 97;
		cout <<AN<< endl;
	}
	else {
		cout << "None" << endl;
	}
	
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;

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

    vector<int> a(n), b(n), c(n-1);
    rep(i, n) {
        cin >> a[i];
        --a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    rep(i, n - 1) {
        cin >> c[i];
    }

    int sum = 0;
    rep(i, n) {
        //cout << a[i];
        sum += b[a[i]];
        if(i >= 1 && a[i]-1 == a[i-1]) sum += c[a[i-1]];
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	private static int sumA = 0;
	private static int sumB = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		for (int i = N - 1; i >= 0; i -= 2) {
			sumA += a[i];

		}
		for (int i = N - 2; i >= 0; i -= 2) {

			sumB += a[i];
		}

		System.out.println(sumA - sumB);
	}

}

Measured memory_bytes: 21076
const M=10^9+7
function main()
	K=parse(Int,readline())
	S=chomp(readline())
	T=K+length(S)
	fac=zeros(Int64,T+1)
	fac[1]=1
	for i=1:T
		fac[i+1]=fac[i]*i%M
	end
	inv=zeros(Int64,T+1)
	inv[T+1]=invmod(fac[T+1],M)%M
	for i=T:-1:1
		inv[i]=inv[i+1]*i%M
	end
	ans=0
	for i=length(S):T
		ans+=fac[T+1]*inv[T-i+1]%M*inv[i+1]%M*powermod(25,T-i,M)%M
	end
	println(ans%M)
end
main()


Measured memory_bytes: 201424
#include <iostream>
using namespace std;
int main()
{
  int a,b,c,d[6],e = 0;
  cin >> a >> b >> c;
  d[0] = a * 10 + b + c;
  d[1] = a * 10 + c + b;
  d[2] = b * 10 + a + c;
  d[3] = b * 10 + c + a;
  d[4] = c * 10 + a + b;
  d[5] = c * 10 + b + a;
  for(int i = 0;i < 6;i++){
    if(e <= d[i]){
      e = d[i];
    }
  }
  cout << e << endl;
  return(0);
}


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

int n, pos;
long long ans, a, b, x;

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

	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (i) {
			ans += min(a * (x - pos), b);
		}

		pos = x;
	}

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

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

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

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

    vector<vector<int>> a(n, vector<int>(3));
    rep(i, n)
    {
        if (i != 0)
        {
            a[i][0] = a[i - 1][0];
            a[i][1] = a[i - 1][1];
            a[i][2] = a[i - 1][2];
        }

        if (s[i] == 'R')
        {
            a[i][0]++;
        }
        else if (s[i] == 'G')
        {
            a[i][1]++;
        }
        else if (s[i] == 'B')
        {
            a[i][2]++;
        }
    }

    rep(i, n)
    {
        char temp_f = s[i];
        for (int j = i + 1; j < n; j++)
        {
            if (s[j] != temp_f)
            {
                char temp_s = s[j];
                if ((temp_f == 'R' && temp_s == 'B') || (temp_f == 'B' && temp_s == 'R'))
                {
                    ans += a[n - 1][1] - a[j][1];
                    if (2 * j - i < n && s[2 * j - i] == 'G')
                    {
                        ans--;
                    }
                }
                else if ((temp_f == 'R' && temp_s == 'G') || (temp_f == 'G' && temp_s == 'R'))
                {
                    ans += a[n - 1][2] - a[j][2];
                    if (2 * j - i < n && s[2 * j - i] == 'B')
                    {
                        ans--;
                    }
                }
                else if ((temp_f == 'G' && temp_s == 'B') || (temp_f == 'B' && temp_s == 'G'))
                {
                    ans += a[n - 1][0] - a[j][0];
                    if (2 * j - i < n && s[2 * j - i] == 'R')
                    {
                        ans--;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3756
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    for (int i = 0 ; i < n; i++){
        cout << s[i];
    }
    cout << endl;

    return 0;
}








Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[][] candidate = {{'d', 'r', 'e', 'a', 'm', 'e', 'r'},
                                {'e', 'r', 'a', 's', 'e', 'r'},
                                {'d', 'r', 'e', 'a', 'm'},
                                {'e', 'r', 'a', 's', 'e'}};

        for(int i = 0;i < s.length / 2;i++) {
            char tmp = s[i];
            s[i] = s[s.length - i - 1];
            s[s.length - i - 1] = tmp;
        }

        for(int i = 0;i < 4;i++) {
            for(int j = 0;j < candidate[i].length / 2;j++) {
                char tmp = candidate[i][j];
                candidate[i][j] = candidate[i][candidate[i].length - j - 1];
                candidate[i][candidate[i].length - j - 1] = tmp;
            }
        }

        int i = 0;
        boolean isSuccess = false;
        while(true) {
            boolean isSame = false;
            for(int j = 0;j < 4;j++) {
                if(i + candidate[j].length > s.length) continue;

                isSame = true;
                for(int k = 0;k < candidate[j].length;k++) {
                    if(s[i + k] != candidate[j][k]) {
                        isSame = false;
                        break;
                    }
                }

                if(isSame) {
                    i += candidate[j].length;
                    break;
                }
            }

            if(isSame && i == s.length) {
                isSuccess = true;
                break;
            }
            else if(!isSame) {
                break;
            }
        }

        String ans = isSuccess ? "YES" : "NO";
        System.out.println(ans);
    }
}

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

int main(void){
    int n, p, d1, d2, d, q;
    while(true){
        cin >> n;
        d = 0;
        if(n == 0){
            break;
        }
        for(int i = 0; i < n; i++){
            cin >> p >> d1 >> d2;
            if((d1+d2) > d){
                d = d1+d2;
                q = p;
            }
        }
        cout << q << " " << d << endl;
    }
}


Measured memory_bytes: 2968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)

const ll MOD = 1e9 + 7;
const ll INF = 1e9;

struct key {
    int price;
    int lock;
};

void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  vector<int> dp(10000, INF);
  vector<key> keys(m, key{0, 0});
  int n2 = 1 << n;

  dp[0] = 0;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    REP(j, b) {
      int c;
      cin >> c;
      c--;
      keys[i].lock |= 1 << c;
    }
    keys[i].price = a;
    dp[keys[i].lock] = a;
  }

  REP(i, m) {
    REP(j, n2) {
      dp[keys[i].lock | j] = min(dp[keys[i].lock | j], keys[i].price + dp[j]);
    }
  }

  if (dp[n2 - 1] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[n2 - 1] << endl;
  }
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize -O3
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = double;
using ull = uint64_t;

const int MAXN = 200228;

ll fen[MAXN];

void ad(int x, ll y) {

    for (int i = x; i < MAXN; i |= (i + 1)) {
        fen[i] += y;
    }
}

ll gt(int x) {
    ll ans = 0;
    for (int i = x + 1; --i >= 0; i &= (i + 1)) {
        ans += fen[i];
    }

    return ans;
}

int a[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    ll med = (ll(n) * (n + 1) + 2)/ 4;

    int l = 0, r = 1e9 + 2;
    while (l < r) {
        int md = (l + r + 1) / 2;
        ll s = 0;
        int b = n;
        memset(fen, 0, sizeof(fen));
        ad(b, 1);

        for (int i = 0; i < n; ++i) {
            if (a[i] >= md) {
                ++b;
            } else {
                --b;
            }

            s += gt(b);
            ad(b, 1);
        }

        if (s >= med) {
            l = md;
        } else {
            r = md - 1;
        }
    }

    cout << l << "\n";
}

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

long long int gcd(long long int a,long long int b)
{
	if(b==0)
	{
		return a;
	}
	return gcd(b,a%b);
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    long long int res = 0,a,b;

    cin >> a >> b;

    res = (a*b)/gcd(a,b);

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

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

int main(){
    int N,T,A;
    cin >>N>>T>>A;
    vector<double>vec(N);
    for(int i=0;i<N;i++){
        cin >>vec.at(i);
    }
    vector<double>vec2(N);
    for(int i=0;i<N;i++){
        double a=(T-vec.at(i)*0.006);
      vec2.at(i)=abs(a-A);
    }
 double b=9999;
 int c;
    for(int i=0;i<N;i++){
      if(vec2.at(i)<b){
          b=vec2.at(i);
          c=i+1;
      }
    }
    cout << c<<endl;
}

Measured memory_bytes: 3748
use std::collections::HashSet;
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let v: Vec<char> = get!(String).chars().collect();
    let k = get!(usize);
    if v.len() == 1 {
        println!("{}", v[0]);
        return;
    }
    let mut set = HashSet::new();
    let mut n = 0;
    while n != v.len() {
        if k < n {
            break;
        }
        for i in 0..v.len() - n {
            let mut sub = v[i].to_string();
            for j in i + 1..i + 1 + n {
                sub += &v[j].to_string();
            }
            //eprintln!("i: {}, sub: {}", i, sub);
            set.insert(sub);
        }
        n += 1;
        //eprintln!("n: {}", n);
    }
    //eprintln!("{:?}", set);
    let mut nv = set.into_iter().collect::<Vec<String>>();
    nv.sort();
    //eprintln!("{:?}", nv);
    println!("{}", nv[k - 1]);
}


Measured memory_bytes: 6396
n = int(input())
a = []
b = []
for i in range(n):
  x,y = map(int,input().split())
  a.append((x,y))
for i in range(n):
  x,y = map(int,input().split())
  b.append((x,y))

a.sort()
b.sort()
res = 0
used = [False for i in range(n)]
for i in range(n):
  ind = -1
  cur = b[i]
  best = -1
  for j in range(n):
    if not used[j] and a[j][0] < cur[0] and a[j][1] < cur[1] and best < a[j][1]:
      ind = j
      best = max(best, a[j][1])
  if ind != -1:
    res+=1
    used[ind] = True

print(res)

Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
 
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
signed main(){
    int N,K;
    cin>>N>>K;
    vint A(N);
    rep(i,N)cin>>A[i];
 
    int ans=LLONG_MAX;
    rep(i,1<<N){
        vint v;
        rep(j,N)if(i>>j&1)v.pb(j);
        if(v.size()!=K)continue;
        int cost=0;
        int pre=-1;
        for(int j=0;j<v.size();j++){
            int ma=pre;
            for(int k=(j?v[j-1]:0);k<v[j];k++)chmax(ma,A[k]);
            cost+=max(0ll,ma-A[v[j]]+1);
            pre=max(ma+1,A[v[j]]);
        }
        chmin(ans,cost);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# Problem - サイコロ

# input
t, s, e, w, n, b = map(int, input().split())
p_num = int(input())

# initialization
dice_dic = {}
dice_dic[t] = {s:e, e:n, n:w, w:s}
dice_dic[b] = {n:e, w:n, s:w, e:s}
dice_dic[s] = {e:t, t:w, w:b, b:e}
dice_dic[n] = {t:e, e:b, b:w, w:t}
dice_dic[e] = {s:b, b:n, n:t, t:s}
dice_dic[w] = {s:t, t:n, n:b, b:s}

# process
for i in range(p_num):
    in_1, in_2 = map(int, input().split())
    print(dice_dic[in_1][in_2])



Measured memory_bytes: 5600
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        int o = 0;

        for (int i = 0; i<3; i++){
            if (a.charAt(i) == 'o')
                o++;
        }
        System.out.println(700+(100*o));
    }
}


Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, A, B;
  cin >> N >> A >> B;
  vector<long> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  long left = 0, right = (data.at(N - 1) + B - 1) / B, mid, count, flag;
  while(right > left){
    count = 0;
    mid = (right + left) / 2;
    flag = 1;
    for(int i = 0; i < N; i++){
      if(data.at(i) - mid * B <= 0)continue;
      count += (data.at(i) - mid * B + (A - B) - 1) / (A - B);
      if(count > mid){
        flag = 0;
        break;
      }
    }
    if(flag == 0)left = mid + 1;
    else right = mid;
  }
  if(flag == 0)cout << mid + 1 << endl;
  else cout << mid << endl;
  return 0;
}


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

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

    int n;
    cin>>n;
    int v[n], c[n];
    for(int i = 0;i < n;i++) cin>>v[i];
    for(int i = 0;i < n;i++) cin>>c[i];
    int ans = INT_MIN;
    for(int i = 0;i < (1 << n);i++) {
        int value = 0, cost = 0;
        for(int j = 0;j < n;j++) {
            if(i & (1 << j)) {
                value += v[j], cost += c[j];
            }
        }
        ans = max(ans, value - cost);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	ll a[n];
	rep(i,n) cin >> a[i];

	ll num[n];
	rep(i,n) num[i]=0;

	ll sum=0;

	//rep(i,n-1){
	for(int i=0;i<n;++i){
		if(a[i]>a[i+1]) {
			num[i+1]=a[i]-a[i+1];
			a[i+1]+=num[i+1];
			sum+=num[i+1];
		}
	}

	//rep(i,n)
	//	cout << num[i] << " " ;
	//cout << sum << " " ;
	cout << sum << endl;

}

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


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int k,a,b;
    cin>>k>>a>>b;
    if(b-a>2)
    {
        if(k<a+1)
        {
            cout<<k+1;
        }
        else
        {
            int z=a;
            k-=a-1;
            int tt=(k/2);
            int ans=a+(tt*(b-a));
            ans+=(k%2);
            cout<<ans;
        }
        
    }   
    else
    {
        int z=k+1;
        cout<<z;
    }
     

}

Measured memory_bytes: 3668
import heapq

Q = int(input())


def update(ans, a, b):
    heapq.heappush(lq, -a)
    heapq.heappush(rq, a)
    lmax, rmin = -lq[0], rq[0]
    ans += b
    if lmax > rmin:
        lmax, rmin = rmin, lmax
        ans += rmin - lmax
        heapq.heappop(lq)
        heapq.heappop(rq)
        heapq.heappush(lq, -lmax)
        heapq.heappush(rq, rmin)
    return ans


def query():
    return str(-lq[0]) + ' ' + str(ans)


lq = []
rq = []
ans = 0

for i in range(Q):
    q = list(map(str, input().split()))
    if len(q) == 1:
        print(query())
    else:
        one, a, b = q
        ans = update(ans, int(a), int(b))

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

#define fi first
#define se second
#define endl '\n'
#define lc (rt<<1)
#define rc (rt<<1|1)
#define mp make_pair
#define pb push_back
#define lowbit(a) (a&(-a))
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define mst(a,v) memset(a,v,sizeof(a))
#define debug(x) cout<<#x": "<<x<<'\n';
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

const int N=200010;
const int mod=1e9+7;
const ld PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template<class T> inline void gmax(T &A,T B)
{
    (A<B)&&(A=B);
}
template<class T> inline void gmin(T &A,T B)
{
    (A>B)&&(A=B);
}

template<class T> inline bool re(T &ret)
{
    char c;
    int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}

int n,a,b,c;
ld dp[333][333][333];

ld solve(int a, int b, int c)
{
    if(a<0||b<0||c<0) return 0;
    if(a==0&&b==0&&c==0) return 0;
    if(dp[a][b][c]!=-1.0) return dp[a][b][c];
    ld t=a*solve(a-1,b,c)+b*solve(a+1,b-1,c)+c*solve(a,b+1,c-1);
    return dp[a][b][c]=(n+t)/(a+b+c);
}

int main()
{
#ifdef local
    freopen("in.txt", "r", stdin);
#endif
    IOS;
    cin>>n;
    for(int i=0,x; i<n; i++)
    {
        cin>>x;
        if(x==1) a++;
        else if(x==2) b++;
        else c++;
    }
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++) dp[i][j][k]=-1.0;
    cout<<fixed<<setprecision(15)<<solve(a,b,c);
    return 0;
}


Measured memory_bytes: 522368
#include<iostream>

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

int main(void){
	int m;

	std::cin >> m;

	rep(h,m){
		long int money[101];
		int itr;	//手数料

		long int amount;
		int year;
		int n;

		std::cin >> amount >> year >> n;

		int r;
		double itr_rate;
		int fee;

		int max = 0;

		rep(i,n){
			std::cin >> r >> itr_rate >> fee;

			itr = 0;

			money[i] = amount;

			rep(j,year) {
				if (r == 0) { //単利
					itr += money[i] * itr_rate;
					money[i] -= fee;
				}else{
					money[i] += money[i] * itr_rate;
					money[i] -= fee;
					itr = 0;
				}
			}
			money[i] = money[i] + itr;
			if(max < money[i]){
				max = money[i];
			}
		}

		std::cout << max << std::endl;

	}
	return 0;
}

Measured memory_bytes: 0
i=int(input())
l=[""]*i
for k in range(i):
  l[k]=input()
l.sort()
maxi=0
kosu=0
li=[]
subk=""
for k in l:
  if subk!=k:
    kosu=0
    subk=k
  kosu+=1
  if kosu==maxi:
    li.append(k)
  elif kosu>maxi:
    li.clear()
    li.append(k)
    maxi=kosu
for k in li:
  print(k)

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

int main(){
  int n; cin>>n;
  map<int,int> a;
  int x,y;
  rep(i,n){
    int A; cin>>A;
    a[A]=1;
  }
  for(auto p : a){
    x=p.first;
  }
  int center=x/2;
  int div=1001001001;
  if(x%2==0){
    for(auto p : a){
      if(div>abs(p.first-center)){
        div=abs(p.first-center);
        y=p.first;
      }
    }
  }else{
    for(auto p : a){
      if(div>abs(p.first-center)){
        div=abs(p.first-center);
        y=p.first;
      }
      if(div>abs(p.first-(center+1))){
        div=abs(p.first-(center+1));
        y=p.first;
      }
    }
  }
  cout<<x<<" "<<y<<endl;
}

Measured memory_bytes: 8284
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str=br.readLine().split(" ");
		IntStack stack=new IntStack();

		for(int i=0;i<str.length;i++){
			try{stack.push(Integer.parseInt(str[i]));
			
			}catch(NumberFormatException e){
				int num=keisan(stack.pop(),stack.pop(),str[i].charAt(0));
				stack.push(num);
				}
			}System.out.println(stack);
		}

	
	static int keisan(int num1,int num2,char operator){
		switch(operator){
		case '+':num1=num2+num1;break;
		case '-':num1=num2-num1;break;
		case '*':num1=num2*num1;break;
		case '/':num1=num2/num1;break;
		}
		return num1;
	}

}

class IntStack {
	private int pointer=-1;
	ArrayList<Integer> stack;

	IntStack(){
		stack=new ArrayList<Integer>();

	}
	public void push(int a){
		stack.add(a);
		pointer++;
	}
	public int pop(){
		int a=stack.get(pointer);
		stack.remove(pointer);
		pointer--;
		return a;
	}
	public String toString(){
		StringBuilder stb=new StringBuilder();
		for(int i:stack)stb.append(i);
		return stb.toString();

	}

}

Measured memory_bytes: 16980
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    int res=0;
    if(S[0]=='R' && S[1]=='R' && S[2]=='R') res=3;
    else if((S[0]=='R' && S[1]=='R') || (S[1]=='R' && S[2]=='R')) res=2;
    else if(S[0]=='R' || S[1]=='R' ||  S[2]=='R') res=1;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3632
//sumitraj387
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define string str
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
main()
{
   int n,d;
   cin>>n>>d;
   if(n%((2*d)+1)==0)
      cout<<n/((2*d)+1);
   else
       cout<<(n/((2*d)+1))+1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
  char c;
  cin>>c;
  if(c>='a' && c<='z')
  {
    cout<<"a";
  }
  else
  {
    cout<<"A";
  }
    
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
void IO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define SZ(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main() {
	IO();
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const long double EPS = 1e-10;

template<class Abel> class UnionFind {
    public:
    int n;
    vector<int> par, rank;
    vector<Abel> diff_weight;

    UnionFind(int n, Abel SUM_UNITY = 0) {
        rep(n) {
            par.push_back(i);
            rank.push_back(0);
            diff_weight.push_back(SUM_UNITY);
        }
    }

    int find(int x) {
        if(par[x] == x){
            return x;
        }
        int root = find(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = root;
    }

    Abel weight(int x) {
        find(x);
        return diff_weight[x];
    }

    bool unite(int x, int y, Abel w) {
        w = w + weight(x) - weight(y);
        x = find(x);
        y = find(y);

        if(x == y) return false;

        if(rank[x] < rank[y]){
            par[x] = y;
            diff_weight[x] = -w;
        }else{
            par[y] = x;
            diff_weight[y] = w;
            if(rank[x] == rank[y]) rank[x]++;
        }

        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }

    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,m,l,r,d;
    cin >> n >> m;

    UnionFind<int> uf(n+1);

    rep(m){
        cin >> l >> r >> d;
        if(!uf.unite(l, r, d) && uf.diff(l, r) != d){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) break;
        
        vector<int> a(n), d(n-1);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        for (int i = 0; i < n-1; i++) {
            d[i] = a[i+1] - a[i];
        }
        
        int ans = *min_element(d.begin(), d.end());
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3124
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  int n;
  cin>>n;
  vector<int> v(n+1);
  unordered_map<int,int> countmp_odd;
  unordered_map<int,int> countmp_even;

  int input;
  FOR(i,0,n){
    cin>>input;
    countmp_odd[input]++;
    i++;
    if(i==n) break;
    cin>>input;
    countmp_even[input]++;
  }

  

  vector< pair<int,int> > maxset_odd;
  vector< pair<int,int> > sec_maxset_odd;
  
  int max_o = 0;
  int sec_max_o = 0;
  
  for(auto x:countmp_odd){
    if(x.ND>max_o){
      sec_max_o = max_o;
      max_o=x.ND;
    }else if(x.ND>sec_max_o){
      sec_max_o=x.ND;
    }
  }
  
  for(auto x:countmp_odd){
    if(x.ND==max_o) maxset_odd.PB(x);
    if(x.ND==sec_max_o) sec_maxset_odd.PB(x);
  }



  vector< pair < int,int > > maxset_even;
  vector< pair < int,int > > sec_maxset_even;
  int max_e=0;
  int sec_max_e=0;
  
  for(auto x:countmp_even){
    if(x.ND>max_e){
      sec_max_e = max_e;
      max_e = x.ND;
    }else if(x.ND>sec_max_e){
      sec_max_e=x.ND;
    }
  }
  for(auto x:countmp_even){
    if(x.ND==max_e) maxset_even.PB(x);
    if(x.ND==sec_max_e) sec_maxset_even.PB(x);
  }

  //順序対の集合maxset_oddと集合maxset_evenの元を比較して，それぞれの元の左の要素が相異なるようにそれぞれ一つずつ元を選ぶ

  // cout1<<"max_o :\t"<<max_o<<endl;
  // cout<<"sec_max_o :\t"<<sec_max_o<<endl;
  // cout<<"max_e :\t"<<max_e<<endl;
  // cout<<"sec_max_e :\t"<<sec_max_e<<endl;

  
  int flag=0;
  for(auto x:maxset_even){
    for(auto y:maxset_odd){
      if(x.ST!=y.ST){
        flag=1;
        // cout<<"pattern 1"<<endl;
        cout<<n-x.ND-y.ND<<endl;  return 0; break;
      }
    }
  }


  
  if(flag==0){
    if(max_o==max_e && max_e==n/2){
      // cout<<"pattern 2"<<endl;
      cout<<n/2<<endl;
    }else{
      // cout<<"pattern 3"<<endl;
      cout<<n-max(max_o+sec_max_e,sec_max_o+max_e)<<endl;
    }
  }
  // if(maxset_even.size()==1 && maxset_odd.size()==1 && (*(maxset_even.begin())).ST==(*(maxset_odd.begin())).ND ){
  //   cout<<n/2<<endl;
  // }
  
  return 0;
}


Measured memory_bytes: 6804
K=int(input())

a=7 #第1項
b=10
i=0 #index

if (K%7 == 0):
    L = 9*K/7
else:
    L = 9*K
    
if (L%2==0 or L%5==0):
    print(-1)
else:
    while(i<=L):
        if (b%L==1):
            break
        else:
            b=10*(b%L)
            i += 1
    print(i+1)

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 2e6;
const int INF = 1e9;

#define int ll

int a[N];

void solve() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++ i) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	reverse(a + 1, a + 1 + n);
	int sum = 0;
	for (int i = 1; i <= n; ++ i) {
		if (k <= 0)
			sum += a[i];
		k--;
	}
	cout << sum << " ";
}

main () {
	cerr << "Ready\n";
	solve();
	return 0;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	N := readInt()
	D := readInt()
	X := make([][]int, N)
	for i := range X {
		X[i] = make([]int, D)
		for j := range X[i] {
			X[i][j] = readInt()
		}
	}
	B := make(map[int]bool)
	for i := 0; i < 200; i++ {
		B[pow(i+1, 2)] = true
	}
	ans := 0
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			calc := 0
			for k := 0; k < D; k++ {
				calc += pow(X[i][k]-X[j][k], 2)
			}
			if B[calc] == true {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

/*-----------------------------------------*/

func checkError(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func read() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	res, err := strconv.Atoi(read())
	checkError(err)
	return res
}

func min(a int, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a int, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func pow(a int, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func sqrt(a int) float64 {
	return math.Sqrt(float64(a))
}


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

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

    int check = 0;
    for (int j = 0; j < N; j ++)
        if(A[j]%2 == 0){
            if(A[j]%3 != 0 && A[j]%5 != 0) check = 1;
        }

    string ans;
    if (check == 1){
        ans = "DENIED";
    }else{
        ans = "APPROVED";
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 4044
N = int(input())
Q = [0]*N
for i in range(N):
        Q[int(input())-1] = i

num = 0
ansr = 0
for i in range(N-1):
        if Q[i]<Q[i+1]:
                num += 1
        else:
                ansr = max(ansr,num)
                num = 0
if num == N-1:
        ansr = N-1
print(N-1-ansr)

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

int main() {

  int N ,sumA,sumB;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
  	cin >> vec.at(i);	
  }
   for(int i=0;i<N;i++){
  	for(int j=i+1;j<N;j++){
    	if(vec.at(i)<vec.at(j)){
        	int T;
          T = vec.at(i);
          vec.at(i) = vec.at(j);
          vec.at(j) = T;
        }
    }
  }
  int A = vec.at(N-1);
  int count =1;
  for(int i=N-1;i>=0;i--){
  	if(A < vec.at(i)){
    	A = vec.at(i);
      	count++;
    }
    
  }
   
 cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;
const ll INF = 1000000009000000009;

int n;
int a[N];

ll q[N];

void solv()
{
    scanf("%d", &n);
    for (int i = 0; i <= n; ++i)
        scanf("%d", &a[i]);
    if (n == 0)
    {
        if (a[0] == 1)
        {
            printf("1\n");
        }
        else
        {
            printf("-1\n");
        }
        return;
    }
    if (a[0] != 0)
    {
        printf("-1\n");
        return;
    }
    q[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        ll l = 0, r = INF;
        q[i] = -1;
        while (l <= r)
        {
            ll m = (l + r) / 2;
            if ((m + a[i]) / 2 + (m + a[i]) % 2 <= q[i - 1])
            {
                q[i] = m;
                l = m + 1;
            }
            else
                r = m - 1;
        }
        if (q[i] == -1)
        {
            printf("-1\n");
            return;
        }
    }
    ll u = 0;
    ll ans = 0;
    for (int i = n; i >= 0; --i)
    {
        u = min(u, q[i]);
        u += a[i];
        ans += u;
    }
    printf("%lld\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 5008
S=input()

a = ''
b = ''
s_len = len(S)
for i in range(s_len):
        if (i % 2 == 0):
                a += '1'
                b += '0'
        else :
                a += '0'
                b += '1'


c1,c2 = 0,0
for j in range(s_len):
        if (a[j] != S[j]):
                c1 += 1
        if (b[j] != S[j]):
            c2 += 1

print(min(c1,c2))

Measured memory_bytes: 3316
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <functional>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main(){
	int B, A;
	string str;
	cin >> A >> B;

	if (A < B){
		str = "a < b";
	}
	else if (B < A){
		str = "a > b";
	}
	else{
		str = "a == b";
	}

	cout <<str<< endl;
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

void no() {
    cout << -1 << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (a[0] != 0) {
        no();
        return 0;
    };
    for (int i = 1; i < n; i++) {
        if (a[i] - a[i - 1] > 1) {
            no();
            return 0;
        }
    }
    lint ans = 0;
    int now = n - 1;
    while (now > 0) {
        ans += a[now];
        while (a[now] - a[now - 1] == 1) {
            now--;
        }
        now--;
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> g(N);
  
  for (int i = 0; i < N ; i++) {
    string city;
    int point;
    cin >> city >> point;
    get<0>(g.at(i)) = city;
    get<1>(g.at(i)) = point * (-1);
    get<2>(g.at(i)) = i+1;
  }
  sort(g.begin(), g.end());
  for (int i = 0; i < N; i++) {
    cout << get<2>(g.at(i)) << endl;
  } 
}


Measured memory_bytes: 256
/* while(!success_achieved())
      work_hard(); 

   code by:aman_ayush
  */
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll inf =0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abs(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    int n;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
     cin>>a[i];
     for(int i=1;i<=n;i++)
      cin>>b[i];
      for(int i=1;i<n;i++)
       cin>>c[i];
       c[n]=0;
       int sum=0;
       for(int i=1;i<=n;i++)
       {
           int in=a[i];
           sum+=b[in];
           if((i!=(n))&&(a[i+1]==(in+1)))
            sum+=c[in];
            //cout<<in<<" "<<sum<<'\n';
       }
    cout<<sum<<"\n";
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace agc041_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadLong();
      var A = CIn.ReadLong();
      var B = CIn.ReadLong();

      if ((B - A) % 2 == 0)
      {
        Console.WriteLine((B - A) / 2);
      }
      else if (A - 1 < N - B)
      {
        Console.WriteLine(A + (B - A - 1) / 2);
      }
      else
      {
        Console.WriteLine(N - B + 1 + (B - A - 1) / 2);
      }
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}

Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep2(i, s, e) for(int i=s; i<e; i++)
#define print(i) cout << i << endl;

vector<int> prime;

void calcPrime(int n){

    bool isPrime[n+1];
    fill(isPrime, isPrime+n+1, true);
    isPrime[0] = false;
    isPrime[1] = false;

    int i1 = 2; 
    while(i1 <= n){
        if(isPrime[i1] == false){
            i1++;
            continue;
        }

        int temp = i1;
        int i2 = i1*2;
        while(i2 <= n){
            isPrime[i2] = false;
            i2 += temp;
        }
        i1++;
    }

    prime.clear();
    for(int i=2; i<=n; i++){
        if(isPrime[i]){
            prime.push_back(i);
        }
    }
}

int main(){

    int n; cin >> n;

    calcPrime(2*n);

    // for(auto x : prime){
    //     cout << x << endl;
    // }

    map<int, int> mp;
    
    rep2(i, 2, n+1){
        // cout << i << endl;
        int k = 0;
        int itemp = i;
        while(true){
            // cout << " " << prime[k] << endl;
            if(itemp % prime[k] == 0){
                itemp /= prime[k];
                mp[prime[k]]++;
            }
            else{
                k++;
                if(prime[k] > n){
                    break;
                }
            }
        }
    }

    ll ans = 1;
    for(pair<int, int> x : mp){
        // cout << x.first << " " << x.second << endl;
        ans = (ans * (x.second + 1)) % ll(1e9+7);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>

using namespace std;


int main() {
  int N, M;
  cin >> N >> M;
  long long mod =  1e9+7;

  int a[M+1];
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  a[M] = N+1;
  
  //階段チェック
  for (int i = 1; i < M; i++) {
    if ( a[i]-a[i-1] == 1 ) {
      cout << 0 << endl;
      return 0;
    }
  }

  //事前計算
  long long cases[N+1];
  cases[0] = 1;
  cases[1] = 1;
  cases[2] = 2;
  for (int i = 3; i < N+1; i++) {
    cases[i] = (cases[i-1] + cases[i-2] )% mod;
  }
  
  //集計
  long long ans = 1;
  int startPoint = 0;
  for (int i = 0; i < M+1; i++) {
    int breakPoint = a[i] ;
    ans *= cases[breakPoint - startPoint -1];
    ans %= mod;
    startPoint = breakPoint + 1;
  }
  
  cout << ans % mod << endl;

  return 0;
}


Measured memory_bytes: 1280
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int H = int.Parse(s[0]);
        int W = int.Parse(s[1]);
        string[] C = new string[H];
        for (int i = 0; i < H; i++)
            C[i] = Console.ReadLine();
        for(int i = 0; i < H; i++)
        {
            Console.WriteLine(C[i]);
            Console.WriteLine(C[i]);
        }
    }
}


Measured memory_bytes: 11092
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n)
	br := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	for i := range br {
		fmt.Scan(&br[i])
	}
	ans := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j < n; j++ {
			if i == j {
				sum += ar[j] + br[j]
			}
			if j < i {
				sum += ar[j]
			}
			if i < j {
				sum += br[j]
			}
		}
		if ans < sum {
			ans = sum
		}
	}
	fmt.Println(ans)
}


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

int main(void) {
	int l, m, n;
	scanf("%d%d%d", &l, &m, &n);
	printf("%d\n", (l * m) / 2);
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>

using namespace std;

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

int main(void)
{
  int k;
  cin >> k;
  int ans = 0;
  int a, b, c;
  for (a = 1; a <= k; a++) {
    for (b = 1; b <= k; b++) {
      for (c = 1; c <= k; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628