akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

const ll mod = 1000000007LL;

// kの階乗を計算する.(sgnを0以外に設定すると逆元を返す)
ll fact(ll k, int sgn = 0) {
	static vector<ll> fac(2, 1LL);
	static vector<ll> inv(2, 1LL);
	static vector<ll> finv(2, 1LL);
	static ll nx = 2LL;
	while (nx <= k) {
		fac.push_back(fac[nx - 1] * nx % mod);
		inv.push_back(mod - inv[mod % nx] * (mod / nx) % mod);
		finv.push_back(finv[nx - 1] * inv[nx] % mod);
		++nx;
	}
	if (sgn == 0)
		return fac[k];
	return finv[k];
}

// aCbを計算する.
ll comb(ll a, ll b) {
	if (b < 0 || b > a) return 0;
	return fact(a) * fact(b, 1) % mod * fact(a - b, 1) % mod;
}

signed main() {
	int n, k; cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = 0;
	// a[i]がminになる場合をそれぞれ引いていく
	for (int i = 0; i < n; ++i) {
		ll tmp = a[i];
		tmp = (tmp * comb(n - 1LL - i, k - 1LL)) % mod;
		ans = (ans + tmp) % mod;
	}
	ans *= -1;
	ans = (ans + mod) % mod;
	// a[i]がmaxになる場合をそれぞれ足していく
	for (int i = 0; i < n; ++i) {
		ll tmp = a[i];
		tmp = (tmp * comb((ll)i, k - 1LL)) % mod;
		ans = (ans + tmp) % mod;
	}
	ans = (ans + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
#include <functional>
using namespace std;
int main(){
	int d[6]={};
	for(int i=0;i<5;i++){
		cin>>d[i];
	}
	sort(d,d+5,greater<int>());
	for(int i=0;i<4;i++){
		cout<<d[i]<<" ";
	}
	cout<<d[4]<<endl;
	
	return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>

int main(void)
{
    int a, b;

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

    if (a > b) {
        printf("a > b\n");
    } else if (a < b) {
        printf("a < b\n");
    } else {
        printf("a == b\n");
    }        

    return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MX = 120000;

int n, m, q;
int a[MX];
vector<int> vv;
int us[MX];
int cnt[MX];

int main() {
	cin >> n >> m;
	cin >> q;
	for (int i = 0; i < q; ++i)
		cin >> a[i], --a[i];
	for (int i = 0; i < m; ++i)
		us[i] = -1;
	for (int i = q - 1; i >= 0; --i) {
		if (us[a[i]] == -1) {
			us[a[i]] = vv.size();
			vv.push_back(a[i]);
		}
	}
	for (int i = 0; i < m; ++i)
		if (us[i] == -1)
			us[i] = vv.size(), vv.push_back(i);
	int nd = vv.size() - 1;
	for (int i = (int)vv.size() - 1; i >= 1; --i) {
		if (vv[i] > vv[i - 1])
			--nd;
		else
			break;
	}
	cnt[0] = n;
	for (int i = q - 1; i >= 0; --i) {
		int x = us[a[i]];
		if (cnt[x] != 0)
			--cnt[x], ++cnt[x + 1];
	}
	for (int i = 0; i < nd; ++i)
		if (cnt[i] != 0) {
			cout << "No\n";
			return 0;
		}
	cout << "Yes\n";

	return 0;
}




Measured memory_bytes: 1912
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int[] ary = new int[10];
    	int i;
    	for(i=0;i<10;i++){
    		ary[i]=sc.nextInt();
    	}
    	Arrays.sort(ary);
    	System.out.println(ary[9]);
    	System.out.println(ary[8]);
    	System.out.println(ary[7]);
    }
}


Measured memory_bytes: 26152
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=3e3+3,mo=1e9+7;
int n,m,f[mn][mn][2];
int main(){
	scanf("%d%d",&n,&m);
	f[0][0][1]=1;
	fo(j,1,n)f[0][j][0]=1;
	fo(i,0,m-1)fo(j,0,n)fo(k,0,1)if(f[i][j][k]){
		if(j){
			f[i+1][j-1][k|(j==1)]=(f[i+1][j-1][k|(j==1)]+f[i][j][k])%mo;
			f[i+1][j][k|(j==1)]=(f[i+1][j][k|(j==1)]+f[i][j][k])%mo;
		}
		if(j!=n){
			f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%mo;
			f[i+1][j+1][k]=(f[i+1][j+1][k]+f[i][j][k])%mo;
		}
	}
	int ans=0;
	fo(j,0,n)ans=(ans+f[m][j][1])%mo;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
const int nn=1e5+10;
bool f[nn];
vector<int>son[nn];
int fa[nn];
bool dfs(int p){
	for(int i=0,t;i<son[p].size();i++)
	if((t=son[p][i])!=fa[p]){
		fa[t]=p,dfs(t);
		if(f[p])f[p]^=f[t];
		else if(f[t])printf("First"),exit(0);
	}return f[p];
}int main(){
  	int n;
	scanf("%d",&n);
	memset(f,true,sizeof f);
	for(int i=1,a,b;i<n;i++){
		scanf("%d%d",&a,&b);
		son[a].push_back(b);
		son[b].push_back(a);
	}if(dfs(1))printf("First");
	else printf("Second");
	return 0;
}

Measured memory_bytes: 9812
n = int(input())
li = list(map(int, input().split())) + [0]

dp = [0] + [float("inf")] * n

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(li[i+1] - li[i]))
    dp[i+2] = min(dp[i+2], dp[i] + abs(li[i+2] - li[i]))

print(dp[n-1])

Measured memory_bytes: 13980
from fractions import gcd
inpl = lambda: list(map(int,input().split()))

N = int(input())
A = inpl()
L = [A[0]]
R = [A[-1]]
for i in range(1,N-1):
    L.append(gcd(L[i-1],A[i]))
    R.append(gcd(R[i-1],A[-i-1]))

ans = max(L[-1],R[-1])
for i in range(1, N-1):
    g = gcd(L[i-1],R[-i-1])
    if g > ans:
        ans = g
print(ans)

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

using namespace std;

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

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

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

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

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

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

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

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

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


const int MAXN = (int)1e5+1;
int N, heights[MAXN], dp[MAXN];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> heights[i];
    }
    for(int i=1; i<N; i++)
    {
        dp[i] = INF;
    }
    dp[1] = abs(heights[1] - heights[0]);
    for(int i=2; i<N; i++)
    {
        dp[i] = min(dp[i], dp[i-1]+abs(heights[i]-heights[i-1]));
        dp[i] = min(dp[i], dp[i-2]+abs(heights[i]-heights[i-2]));
    }
    cout << dp[N-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define gcd(a, b)       __gcd(a, b)
#define here            cout<<"here";
#define lcm(a, b)       ((a)*1ll * (b)) / gcd(a, b)
#define pb              push_back
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl              "\n"
#define vi              vector<int>
#define vvi             vector<vector<int> >
#define F               first
#define S               second
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define w(x)            int x; cin>>x; while(x--)
#define fre(i,a,n)      for (int i = a; i <= n; ++i)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define rf(i,n,a)       for (int i = n; i >=a; --i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pqi		   priority_queue<int>
#define pqgi            priority_queue<int,vector<int>,greater<int>>
#define MN              min_element
#define MX              max_element
#define all(x)          x.begin(),x.end()
#define YN(ans)         ans ? cout << "YES" : cout << "NO";
#define d0(x)           cout<<(x)<<" "
#define d1(x)           cout<<(x)<<endl
#define d2(x,y)         cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z)       cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d)     cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e)   cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define max3(a,b,c)     max(max((a),(b)),(c))
#define max4(a,b,c,d)   max(max((a),(b)),max((c),(d)))
int pow(int a, int b, int m) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % m;
		b /= 2;  a = (a * a) % m;
	}
	return ans;
}
//when m is prime
int modinv(int a, int m)  {return pow(a, m - 2, m);}
void start()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

const int N = 200005;
void solve()
{
	int n;cin>>n;
	int h[n];
	int dp[N];

	fr(i,n) cin>>h[i];
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	fre(i,2,n-1){
		int op1=dp[i-1]+abs(h[i]-h[i-1]);
		int op2=dp[i-2]+abs(h[i]-h[i-2]);
		dp[i]=min(op1,op2);
	}
	cout<<dp[n-1];


}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////


int32_t main()
{
	FIO;
	//start();
	solve();
// w(x)    {solve();}
#ifndef ONLINE_JUDGE
	cerr << "\nTime Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}


Measured memory_bytes: 5228
import sys
n = int(input())
w = input()
www = [w]
for i in range(n-1):
  w = input()
  if not www[-1][-1] == w[0]:
    print("No")
    sys.exit()
  if w in www:
    print("No")
    sys.exit()
  www.append(w)
print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int GCD(int a, int b) {
  if(b == 0) return a;
  return GCD(b, a % b);
}

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << (c % GCD(a, b) == 0 ? "YES" : "NO") << endl;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

ll n, x, m;
vector<bool> used;
vector<ll> res, cyc;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> x >> m;
    used.assign(m, false);
    while(!used[x]){
        used[x] = true;
        res.pb(x);
        x = (x * x)%m;
    }
    ll rep = -1, ans = 0;
    for(int i = 0; i < sz(res); ++i){
        if(res[i] == x) rep = i;
    }
    assert(rep != -1);
    for(int i = rep; i < sz(res); ++i) cyc.pb(res[i]);
    for(int i = 0; i < rep; ++i){
        if(n <= 0) break;
        ans += res[i]; --n;
    }
    if(n == 0){
        cout << ans;
        return 0;
    }
    // cout << rep << " " << n << " " << sz(res) << " "  << sz(cyc) << "\n";
    // for(auto i : res) cout << i << " ";
    // cout << "\n" << rep << "\n";
    ll tot = 0;
    for(auto i : cyc){
        tot += i;
    }
    ans += tot * (n/(sz(cyc)));
    for(int i = 0; i < n%(sz(cyc)); ++i){
        ans += cyc[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4256
N = int(input())
A = [int(x) for x in input().split()]

all_cost = 0
prev = 0
for a in A:
    all_cost += abs(a-prev)
    prev = a
all_cost += abs(A[-1])

prev = 0
for i, a in enumerate(A[:-1]):
    print(all_cost - abs(a-prev) - abs(a-A[i+1]) + abs(A[i+1]-prev))
    prev = a
print(all_cost - abs(A[-2]-A[-1]) - abs(A[-1]) + abs(A[-2]))


Measured memory_bytes: 65004
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    string s,t;
    cin >> s >> t;

    int count=0;
    for (int i=0;i<=s.length()-1;i++)
    {
        if (s[i]!=t[i])
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3788
#include <iostream>

using namespace std;

int main() {
    int N;
    int T;
    int c[100], t[100];
    cin >> N >> T;
    for (int i = 0; i < N; i++) {
        cin >> c[i] >> t[i];
    }
    int m = -1;
    for (int i = 0; i < N; i++) {
        if (t[i] > T) continue;
        if (c[i] < m || m < 0) {
            m = c[i];
        }
    }
    if (m == -1) {
        cout << "TLE" << endl;
    } else {
        cout << m << endl;
    }

    return 0;
}


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


  while(1)
    {
      int H,W;
      int i,j;
      scanf("%d %d",&H,&W);
      if (H == 0 && W == 0)break;

      for(j = 0;j<H;j++)
        {
      for(i = 0;i<W;i++)
        {
          if (j == 0)printf("#");
          else if (j == H-1 )printf("#");
          else if (i == 0 || i == W-1)printf("#");
          else printf(".");
        }
          printf("\n");
          if (j == H-1)printf("\n");
        }
    }
return 0;
}

Measured memory_bytes: 572
import Control.Monad
f x = do
  hw_in <- (return . words) =<< getLine
  let h:w:[] = map (read::String->Int) hw_in
  if (h==0)&&(w==0)
    then return ()
    else do
      forM_ [1..h] (\i -> do
        if (i == 1)||(i == h) then putStrLn ['#'|_<-[1..w]]
        else putStrLn ("#" ++  ['.'|_<-[2..w-1]] ++ "#"))
      putStrLn ""
      f (x+1)
main = f 0


Measured memory_bytes: 4140
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

//////////////////////////



ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 25000004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}


int main(){fastio
    calc();
    ll n;cin>>n;
    ll ans=po(3,n);
    ll gen=0;
    rep(a,n/2+1,n){
        Add(gen,comb(n,a)*po(2,n-a));
    }
    cout<<mod(ans-gen*2)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 390912
/*
ID: jerrywcy
TASK: AtCoder Beginner Contest 106 Problem B
LINK: https://abc106.contest.atcoder.jp/tasks/abc106_b
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

int n;
int ans;

int divisor(int x){
	int ret=1;
	int i,j;
	for (i=2;i<=x;i++){
		int m=0;
		while (x%i==0){
			x/=i;
			m++;
		}
		ret*=m+1;
	}
	return ret;
}

int main() {
	cin>>n;
	int i,j;
	for (i=3;i<=n;i+=2){
		if (divisor(i)==8)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> config;

int l[105];
void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  int ret = 1e9;
  for(int x = 0; x <= 100; x++) {
    int cand = 0;
    for(int i = 0; i < n; i++) {
      int d = x - l[i];
      cand += d * d;
    }
    ret = min(ret, cand);
  }
  cout << ret << "\n";
}

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


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

even_num=0
odd_num=0

for a in A:
    if a%2==0:
        even_num+=1
    else:
        odd_num+=1

ev_case = 2**even_num


from math import factorial

res=0
for i in range(P,odd_num+1,2):                                                                   res += factorial(odd_num) / factorial(i) / factorial(odd_num - i)

print(int(ev_case*res))

Measured memory_bytes: 3064
import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

w, h = map(int, input().split())
P = [int(input()) for _ in range(w)]
Q = [int(input()) for _ in range(h)]

E = []
for p in P:
    E.append((p, 0))
for q in Q:
    E.append((q, 1))
E.sort(reverse=True)

a = w+1
b = h+1
ans = 0
while a >1 or b > 1:
    c, t = E.pop()
    if t == 0:
        ans += c*b
        a -= 1
    else:
        ans += c*a
        b -= 1
print(ans)


Measured memory_bytes: 94500
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

int main() {
    string S; cin>>S;
    int N=S.length()+1;
    vector<int> left(N,-1),right(N,-1);

    if(S[0]=='<') {
        left[0] = 0;
        right[0]=0;
    }

    if(S[N-2]=='>') {
        left[N-1] = 0;
        right[N-1]=0;
    }

    for (int i = 0; i < N - 2; ++i) {
        if(S[i]=='>'&&S[i+1]=='<'){
            left[i+1]=0;
            right[i+1]=0;
            //cout<<i+1<<endl;
        }
    }

    for (int i = 0; i < N-1; ++i) {
        if(S[i]=='<') left[i+1]=left[i]+1;
    }

    for (int i = N-2; i >=0; --i) {
        if(S[i]=='>') right[i]=right[i+1]+1;
    }
/*
    for (int i = 0; i < N; ++i) {
        cout<<left[i]<<" ";
    }
    cout<<endl;
    for (int i = 0; i < N; ++i) {
        cout<<right[i]<<" ";
    }
    cout<<endl;
*/

    ll ans=0ll;
    for (int i = 0; i < N; ++i) {
        ans+=(ll)max(left[i],right[i]);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4740
N = int(input())
A = [int(x) for x in input().split()]
MIN,MAX = min(A),max(A)

cost = 100000000000
for i in range(MIN,MAX+1):
	c = 0
	for a in A:
		c += (i - a)*(i - a)
	cost = min(cost,c)
print(cost)


Measured memory_bytes: 2940
function main()
	lines=readlines()
	A,B,Q=map(x->parse(Int,x),split(shift!(lines)))
	S=Array{Int}(0)
	push!(S,-10^12)
	for i=1:A
		push!(S,parse(Int,shift!(lines)))
	end
	push!(S,10^12)
	T=Array{Int}(0)
	push!(T,-10^12)
	for i=1:B
		push!(T,parse(Int,shift!(lines)))
	end
	push!(T,10^12)
	function bsearch(A,x)
		L=1
		R=length(A)+1
		while R-L>1
			M=div(L+R,2)
			if A[M]>=x
				R=M
			else
				L=M
			end
		end
		R
	end
	CS=Array{Int}(0)
	push!(CS,10^15)
	for i=1:A
		id=bsearch(T,S[i+1])
		push!(CS,min(S[i+1]-T[id-1],T[id]-S[i+1]))
	end
	push!(CS,10^15)
	CT=Array{Int}(0)
	push!(CT,10^15)
	for i=1:B
		id=bsearch(S,T[i+1])
		push!(CT,min(T[i+1]-S[id-1],S[id]-T[i+1]))
	end
	push!(CT,10^15)
	for x=lines
		x=parse(Int,x)
		ans=10^18
		ids=bsearch(S,x)
		idt=bsearch(T,x)
		ans=min(ans,S[ids]-x+CS[ids])
		ans=min(ans,x-S[ids-1]+CS[ids-1])
		ans=min(ans,T[idt]-x+CT[idt])
		ans=min(ans,x-T[idt-1]+CT[idt-1])
		println(ans)
	end
end
main()


Measured memory_bytes: 156712
#include <stdio.h>

int main(void) {
  
  char S[100001];
  scanf("%s", &S);
  
  int len = strlen(S);
  int even_count = 0, odd_count = 0;
  for(int i = 0; i < len; ++i) {
    if((i % 2 == 0 && S[i] != S[0]) || (i % 2 == 1 && S[i] == S[0])) ++even_count;
    if((i % 2 == 0 && S[i] == S[0]) || (i % 2 == 1 && S[i] != S[0])) ++odd_count;
  }
  
  even_count > odd_count ? printf("%d\n", odd_count) : printf("%d\n", even_count);
  
  return 0;
  
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> L(N);
    rep(i, N) cin >> L[i];

    sort(L.begin(), L.end());

    if (L.back() < accumulate(L.begin(), L.end() - 1, 0)) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CLinearApproximation solver = new CLinearApproximation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CLinearApproximation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                a[i] -= (i + 1);
            }

            Arrays.sort(a);

            long b = a[n / 2];

            long answer = 0;
            for (long x : a) {
                answer += Math.abs(x - b);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 44500
#include<stdio.h>
#include<string.h>
main(){
  int i,j,n;
  char *a;
  scanf("%d%*c",&n);
  char s[n][1024];
  for(i=0;i<n;i++)
    fgets(s[i],1024,stdin);
  for(i=0;i<n;i++){
    for(j=0;j<strlen(s[i]);j++)
      if((a=strstr(s[i]+j,"Hoshino"))!=NULL)
	*(a+6)='a';
    printf("%s",s[i]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n>8||m>8)
        {
            puts(":(");
            continue;
        }
        else
            puts("Yay!");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long int ll;

int main(){

  int a, b, ans=0;
  cin >> a >> b;
  for(int i=a; i<=b; i++){
    if(i/10000==i%10 && (i/1000)%10==(i%100)/10){
      ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut line: Vec<String> = vec![];
    loop {
        let mut s = String::new();
        match io::stdin().read_line(&mut s) {
            Ok(0) => break,
            Ok(_) => line.push(s),
            Err(_) => break
        }
    }

    for i in 'a' as u8 .. 'z' as u8 + 1 {
        let count = line.iter().flat_map(|x| x.chars()).map(|c| c.to_lowercase().to_string()).filter(|x| x.chars().next().unwrap() == i as char).count();
        println!("{} : {}", i as char, count);
    }
}


Measured memory_bytes: 5060
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = []
    ok = False
    for l, count in sorted(dic.items(), reverse=True):
        if count >= 4:
            if len(ans) == 0:
                print(l*l)
                ok = True
                break
            else:
                print(ans[0] * l)
                ok = True
                break
        elif count >= 2:
            if len(ans) == 1:
                print(ans[0] * l)
                ok = True
                break
            else:
                ans.append(l)

    if not ok:
        print(0)

if __name__ == "__main__":
    main()

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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int x[6]={};

    for(int i=1;i<=5;i++){
        cin>>x[i];
        if(x[i]==0){
            cout<<i<<endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];





int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  string s;
  cin >> s;
  
  ll ans=0;
  vector<ll> rv, wv;
  
  for(i=0; i<N; i++) {
    if(s[i]=='R') rv.push_back(i);
    else wv.push_back(i);
  }
  sort(rv.rbegin(), rv.rend());
  
  
  for(i=0; i<min(rv.size(), wv.size()); i++) {
    if(wv[i]>rv[i]) break;
    swap(s[rv[i]], s[wv[i]]);
    ans++;
  }
  
    
  pt(ans);
  
}




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

int main(){
  int N,X,T,count;
  
  cin >> N >> X >> T;
  
  while(count <= 1000){
    count++;
    if(N <= X*count){
      break;
    }
  }
  cout << T*count << endl;
  
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
int len = 500000;
vector<int>L(len / 2), R(len / 2);
int cnt(0);

void merge(vector<int>&a, int l, int mid, int r) {
	int n1 = mid - l;
	int n2 = r - mid;
	rep(i, 0, n1)L[i] = a[l + i];
	L[n1] = INF;
	rep(i, 0, n2)R[i] = a[mid + i];
	R[n2] = INF;
	int i(0), j(0);
	rep(k, l, r) {
		cnt++;
		if (L[i] < R[j])a[k] = L[i++];
		else a[k] = R[j++];
	}
}
void mergeSort(vector<int>&a, int l, int r) {
	if (r - l > 1) {
		int mid = (l + r) / 2;
		mergeSort(a, l, mid);
		mergeSort(a, mid, r);
		merge(a, l, mid, r);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	mergeSort(v, 0, N);
	rep(i, 0, N)cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 6608
/*
                                             ::                     ::
                                             ':                     :
                                              :.                    :
                                           ;' ::                   ::  '
                                          .'  ';                   ;'  '.
                                         ::    :;                 ;:    ::
                                         ;      :;.             ,;:     ::
                                         :;      :;:           ,;"      ::
                                         ::.      ':;  ..,.;  ;:'     ,.;:
                                          "'"...   '::,::::: ;:   .;.;""'
                                              '"""....;:::::;,;.;"""
                                          .:::.....'"':::::::'",...;::::;.
                                         ;:' '""'"";.,;:::::;.'""""""  ':;
                                        ::'         ;::;:::;::..         :;
                                       ::         ,;:::::::::::;:..       ::
                                       ;'     ,;;:;::::::::::::::;";..    ':.
                                      ::     ;:"  ::::::"""'::::::  ":     ::
                                       :.    ::   ::::::;  :::::::   :     ;
                                        ;    ::   :::::::  :::::::   :    ;
                                         '   ::   ::::::....:::::'  ,:   '
                                          '  ::    :::::::::::::"   ::
                                             ::     ':::::::::"'    ::
                                             ':       """""""'      ::
                                              ::                   ;:
                                              ':;                 ;:"


                                                     P_r_A_d_Y
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 300005;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void cs(int &x)
{
    cout << "Case #" << x << ": ";
}
bool cmp(string a, string b)
{
    return a + b < b + a;
}

int32_t main()
{
      fastIO;
    // int t; cin >> t;
    // int x = 1;
    // while (t--)
    // {
       int n;cin>>n;

       int c=0,fl=-1,x,y;
       for(int i=0;i<n;i++)
       {
            cin>>x>>y;
            if(x==y)
                c++;
            else
                c=0;

            if(c==3)
                fl++;
       }
       if(fl!=-1)
        cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        
    // }
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>

using namespace std;
typedef long long ll;
ll a, b, n;
ll f(ll x) {
  return a * x / b;
}
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  printf("%lld\n", f(min(n, b - 1)));
  return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>

void print_rectangle(int height, int width);

int main(void){

    int h, w;

    while(1){
        //input
        scanf("%d %d", &h,&w);

        if(h==0 && w==0){
            return 0;
        }
        else{
            print_rectangle(h,w);
            printf("\n");
        }
    }

}

void print_rectangle(int height, int width){

    int i,j;

    for(i=0; i<height; i++){
        for(j=0; j<width; j++){
            printf("#");
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
// AtCoder Beginner Contest 092 - Problem B: Chocolate (https://atcoder.jp/contests/abc092/tasks/abc092_b)
#include <bits/stdc++.h>

using namespace std;

int solve(int D, int X, const vector<int>& as)
{
    int ans = X;

    for (auto a : as)
        ans += 1 + (D - 1)/a;

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, D, X;
    cin >> N >> D >> X;

    vector<int> as(N);

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

    auto ans = solve(D, X, as);

    cout << ans << '\n';

    return 0;
}


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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long H;
        H = sc.nextLong();
        long W;
        W = sc.nextLong();
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(H, W, A, B);
    }
}

class Solver {
    public void solve(long H, long W, long A, long B) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (i < B && j < A) {
                    stringBuffer.append(0);
                }
                else if (i < B && j >= A) {
                    stringBuffer.append(1);
                }
                else if (i >= B && j < A) {
                    stringBuffer.append(1);
                }
                else {
                    stringBuffer.append(0);
                }
            }
            stringBuffer.append("\n");
        }
        System.out.println(stringBuffer.toString());
    }
}



Measured memory_bytes: 31460
/*
{

AuThOr Gwj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n,m,k;
int have2[300000+20];
vector<int> havex[300000+20];
int have3[300000+20],is[300000+20];
vector<int > havee[300000+20];
bool cmp(mp A,mp B){
	return A.SEC>B.SEC;
}
int main(){
	fastio;
	cin>>n>>m>>k;
	rb(i,1,k){
		int x,y;
		R2(x,y);
		havex[y].PB(x);
		have2[x]++;
		have3[y]++;
	}
	vector<mp> best;
	rb(i,1,m){
		best.PB(II(i,have3[i]));
	}
	sort(ALL(best),cmp);
	rep(i,m){
		for(auto it:havex[best[i].FIR]){
			havee[it].PB(i);
		}
	}
	rb(i,1,n){
		is[i]=0;
		for(auto it:havee[i]){
			if(is[i]!=it){
				break;
			}
			is[i]++;
		}
	}
	int rest=-INF;
	rb(i,1,n){
		rest=max(rest,best[0].SEC-1+have2[i]);
		if(is[i]!=m)
		rest=max(rest,best[is[i]].SEC+have2[i]);
	}
	cout<<rest;
	return 0;
}



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

class Main {

	void solve () {

		int a = in.nextInt(), p = in.nextInt();
		p += a * 3;
		out.println(p/2);
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#define NUM 200003
using namespace std;

int main() {
	int n;
	cin >> n ;
	int a[NUM] = { 0 };
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	int v[NUM] = { 0 };
	copy(a, a + n + 1, v);
	sort(a + 1, a + n +1);
	for (int i = 1;i <= n;i++) {
		if (v[i] > a[n/2])
			cout << a[ n / 2] << endl;
		else
			cout << a[(n / 2) + 1 ] << endl;

	}
	

	return 0;
}


Measured memory_bytes: 3712
from heapq import *
import sys
I=sys.stdin.readlines()
V,E,r=map(int,I[0].split())
s,t,d=0,0,0
G=[[] for i in range(V)]
for i in range(E):
  s,t,d=map(int,I[i+1].split())
  G[s].append((t,d))
D=[0]*V
INF=10**9+1
def ijk(s):
  global V,D,G,INF
  Q=[]
  heapify(Q)
  for i in range(V):
    D[i]=INF
  D[s]=0
  v,p,e=0,0,0
  heappush(Q,(0,s))
  while len(Q):
    p=heappop(Q)
    v=p[1]
    if D[v]<p[0]:
      continue
    for i in range(len(G[v])):
      e=G[v][i]
      if D[e[0]]>D[v]+e[1]:
        D[e[0]]=D[v]+e[1]
        heappush(Q,(D[e[0]],e[0]))

ijk(r)
for i in range(V):
  if D[i]==INF:
    print('INF')
  else:
    print(D[i])


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

struct Cake {
    int t;
    int h, w;
    Cake(){}
    Cake(int _t, int _h, int _w) : t(_t), h(_h), w(_w) {}
    bool operator<( const Cake& o ) const {
        if (t != o.t) return t < o.t;
        return h * w < o.h * o.w;
    }
};

int n, h, w;
vector<Cake> vec;
int p, s;

void cut(int t) {
    Cake c = vec[p];
    vec.erase(vec.begin() + p);
    Cake c1 = c, c2 = c;
    c1.t = t; c2.t = t;
    s %= (c.h + c.w);
    if (s < c.w) {
        c1.w = s;
        c2.w = c.w - s;
    }
    else {
        s -= c.w;
        c1.h = s;
        c2.h = c.h - s;
    }
    vec.emplace_back(c1);
    vec.emplace_back(c2);
    sort(all(vec));
}

void solve() {
    vec.clear();
    vec.emplace_back(Cake(0, h, w));
    rep(i, n) {
        cin >> p >> s;
        p--;
        cut(i);
    }
    vi ans;
    for (auto c : vec) {
        ans.emplace_back(c.h * c.w);
    }
    sort(all(ans));
    rep(i, ans.size()) {
        cout << (i ? " " : "") << ans[i];
    }
    cout << endl;
}

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

    while (cin >> n >> w >> h, h) {
        solve();
    }
}

Measured memory_bytes: 3240
n, x, y = map(int,input().split())
l = [0]*(n-1)
for i in range(n-1):
  for p in range(n-i-1):
    d = min(abs(i+1-x)+1+abs(i+1+p+1-y),p+1)
    l[d-1] += 1
[print(j) for j in l]

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n; cin >> n;
  vector<int> a(n), b(n), c(n-1);
  for(int i = 0; i < n; i++){
    int temp; cin >> temp;
    a[i] = temp;
  }
  for(int i = 0; i < n; i++){
    int temp; cin >> temp;
    b[i] = temp;
  }
  for(int i = 0; i < n-1; i++){
    int temp; cin >> temp;
    c[i] = temp;
  }

  int ans=0;
  for(int i = 0; i < n; i++){
    ans += b[a[i]-1];
    if(i >= 1 && a[i-1]+1 == a[i]){
      ans += c[a[i]-2];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;	
		


int32_t main()
{   
	IOS
	int n;cin>>n;
	string s;cin>>s;
	s='$'+s;
	vector<int>r(n+2),g(n+2),b(n+2);
	for(int i=1;i<=n;i++){
		if(s[i]=='R')r[i]++;
		else if(s[i]=='G')g[i]++;
		else b[i]++;
		r[i]+=r[i-1];
		g[i]+=g[i-1];
		b[i]+=b[i-1];
	}
	int sum = 0;
	for(int i=1;i<=n;i++){
		if(s[i]=='R'){
			sum+=g[i] * ( b[n]-b[i] );
			sum+=b[i] * ( g[n]-g[i] );
		}
		else if(s[i]=='G'){
			sum+=r[i] * ( b[n]-b[i] );
			sum+=b[i] * ( r[n]-r[i] );
		}
		else {
			sum+=r[i] *( g[n]-g[i]);
			sum+=g[i] *( r[n]-r[i]);
		}
	}
	for(int i=1;i<=n;i++){
		int j=i-1;
		int k=i+1;
		while( j >=1 && k <= n ){
			if( s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i] ){
				sum--;
			}
			j--;
			k++;
		}
	}
	cout << sum << endl;
		
}





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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    ll all=0;
    int mod = 1000000007;

    for(int i=0; i<N; i++){
        cin >> A.at(i);
        all+=A.at(i);
        all%=mod;
    }

    ll sum=0;

    for(int i=0; i<N; i++){
        all-=A.at(i);
        if(all<0){
            all+=mod;
        }
        sum+=A.at(i)*all;
        sum%=mod;
    }

    cout << sum << endl;
}

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


    class Program
    {
        static void Main(string[] args)
        {
            long X = long.Parse(Console.ReadLine());
            long num = 100;
            long count = 0;
            do
            {
                num += (long)Math.Floor(num * 0.01);
                count++;
            }while(num < X);
            Console.WriteLine(count);
            
        }
    }



Measured memory_bytes: 17624
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N;
int main(){
	int R=0;
	int S=0;
	int T;
	cin>>N;
	T=N;
	while(T!=0){
		R=T%10;
		S=S*10+R;
		T/=10;
	}
	if(S==N){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


	return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        long[] luca = new long[87];
        luca[0] = 2;
        luca[1] = 1;
        int N = int.Parse(Console.ReadLine());
        for(int i = 2; i <= N; i++)
        {
            luca[i] = luca[i - 1] + luca[i - 2];
        }
        Console.WriteLine(luca[N]);
    }
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 400005;
const i64 MAXM = 20;


i64 n;
i64 a[MAXN];


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);


    i64 a, b;
    cin >> a >> b;
    for (i64 i = 0; i < 1'000'000; i++) {
        if (i * 2 / 25 == a && i / 10 == b) {
            cout << i << endl;
            return 0;
        }
    }


    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int, input().split())
li_1=list(range(m))
li_2=list(range(m))
pr=list(range(n))
wr=list(range(n))
wa=0
ac=0
for i in range(n):
    pr[i]=0
    wr[i]=0
for i in range(m):
    li_1[i],li_2[i]=map(str, input().split())
    li_1[i]=int(li_1[i])

for i in range(m):
    if li_2[i]=='AC':
        a=li_1[i]-1
        if pr[a]==0:
            wa=wr[a]+wa
            pr[a]=1
            ac=ac+1
    else:
        a = li_1[i] - 1
        wr[a]=wr[a]+1
print(ac,wa)


Measured memory_bytes: 18804
#include <iostream>
typedef long long ll;

using namespace std;

int main() {
  ll n;
  ll a[5] = {};
  cin >> n;
  ll ans = 5;
  ll MIN = 1e17;
  for(int i = 0; i < 5; i++) {
    ll a;
    cin >> a;
    MIN = min(MIN,a);
  }

  (n % MIN == 0) ? cout << (n / MIN + 4) << endl : cout << (n / MIN + 5) << endl; 
}


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

int main(){
    int N; cin >> N;
    vector<int> W(N);
    int wsum = 0;
    for (int i=0; i<N; i++){
      cin >> W[i];
      wsum += W[i];
    }
    int hoge = W[0];
    wsum -= W[0];
    int ans = 1e9;
    for (int i=1; i<N; i++){
      ans = min(ans, abs(hoge-wsum));
      hoge += W[i];
      wsum -= W[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
    
int main(){
  string s;
  cin >> s;
  int i,j;
  for(i=0;;i++) if(s[i] == 'A') break;
  for(j=s.size()-1;;j--) if(s[j] == 'Z') break;
  cout << j - i + 1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll ans=100*(1<<m)*(18*m+n);
	cout<<ans<<'\n';
}

Measured memory_bytes: 256