akhauriyash/Code-Regression huggingface dataset:
#%%
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

x = (a1-b1) * t1
y = x + (a2-b2) * t2
#print(x, y)

def p(x, y):
    if x%y == 0:
        return abs(x//y)
    else:
        return abs(x//y) + 1

if y == 0:
    ans = 'infinity'
else:
    if x%y != 0:
        if x < 0 and y > 0 :
            ans = (abs(x//y) + 1) * 2 - 3
        elif x > 0 and y < 0 :
            ans = (abs(x//y) + 1) * 2 - 3
        else:
            ans = 0
    else:
        if x < 0 and y > 0 :
            ans = (abs(x//y) + 1) * 2 - 2
        elif x > 0 and y < 0 :
            ans = (abs(x//y) + 1) * 2 - 2
        else:
            ans = 0


print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N ('z'-'a')
using namespace std;
typedef long long ll;
int n,ans;
string str[501];
ll mp[N+1];

void mk_mp(int pos,int i,int j){
  while(i<=j&&pos>=str[i].size())i++;
  if(i>=j)return;
  int ni=-1,ch=str[i][pos]-'a',c=1;

  while(i<j&&ans){
    int a=str[++i][pos]-'a',f=(ch==a);
    if(f&&ni==-1)ni=i-1;
    if(!f&&ni>=0)mk_mp(pos+1,ni,i-1),ni=-2;
    
    if(!f&&c)mk_mp(pos,i,j),mp[ch]|=((1LL<<a)|mp[a]),c=0;
    if(f&&!c)ans=0;
    if(f&&str[i-1].size()>str[i].size()&&str[i][pos+1]==0)ans=0;    
  }
  if(ni>=0) mk_mp(pos+1,ni,j);
  
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<=N;i++) mp[i]=0;
    for(int i=0;i<n;i++)cin>>str[i];
    ans=1;
    mk_mp(0,0,n-1);
    for(int i=0;i<N;i++) if((mp[i]&(1<<i)))ans=0;
    cout <<(ans? "yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1252
from collections import deque

N = int(input())
A = deque(map(int, input().split()))

A.append(0)
A.appendleft(0)

A_diff = [abs(A[i+1] - A[i]) for i in range(N+1)]
A_sum = sum(A_diff)

for i in range(N):
    print(A_sum - (A_diff[i] + A_diff[i+1]) + abs(A[i+2] - A[i]))

Measured memory_bytes: 13536
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-6
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FDR(i,a,n) for(int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mdsad
# define rch p<<1|1,mdsad+1,r
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
     int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=100005;
//Code begin...

map<int,int>vis;
int a[N];

int main ()
{
    LL b=0, c=0;
    int n;
    scanf("%d",&n);
    FOR(i,1,n) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    FDR(i,n,1) {
        if (vis[a[i]]) {
            vis[a[i]]=0;
            if (b==0) b=a[i];
            else {c=a[i]; break;}
        }
        else ++vis[a[i]];
    }
    printf("%lld\n",b*c);
    return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct infant {
    int id;
    ll score;

    bool operator<(const infant& other) const {
        if (score < other.score) return true;
        else return false;
    }
};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<infant> infants(N);
    REP(i, N) {
        infants[i].id = i;
        infants[i].score = A[i];
    }

    sort(ALL(infants));
    reverse(ALL(infants));

    vector< vector<ll> > dp(N+1, vector<ll>(N+1));
    dp[0][N] = 0; // dp[l][r]: 1~l、r~Nまで入ってる

    REP(i, N) {
        infant c = infants[i];
        REP(l, i+1) {
            int r = N + l - i;
            // if(dp[l+1][r] > dp[l][r] + c.score * abs(l - c.id)) {
            //     cerr << "l = " << l << " r = " << r << endl;
            // }
            // if(dp[l][r-1] > dp[l][r] + c.score * abs(r - 1 - c.id)) {
            //     cerr << "l = " << l << " r = " << r << " dp[l][r-1] = " << dp[l][r-1] << endl;
            // }
            // cerr << "i = " << i << " l = " << l << " r = " << r << " dp[l][r-1] = " << dp[l][r-1] << endl;
            dp[l+1][r] = max(dp[l+1][r], dp[l][r] + c.score * abs(l - c.id));
            dp[l][r-1] = max(dp[l][r-1], dp[l][r] + c.score * abs(r - 1 - c.id));
        }
    }

    ll ans = 0;
    REP(i, N) if(ans < dp[i][i]) ans = dp[i][i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 34676
/*  HARD WORK FOREVER PAYS  */
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define turbo(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
int main() 
{ 
	turbo();
	int n;
	cin>>n;
	if(n%1000){
		cout<<1000-(n%1000)<<"\n";
	}
	else{
		cout<<0<<"\n";
	}
	return 0;	
}

Measured memory_bytes: 3636
h,w = map(int,input().split())
g = []
for i in range(h):
    s = list(input())
    g.append(s)


#left
left = [[0]*w for i in range(h)]
for i in range(h):
    cnt = 0
    for j in range(w):
        if g[i][j] == ".":
            cnt += 1
            left[i][j] =cnt
        else:
            cnt = 0

#right
right = [[0]*w for i in range(h)]
for i in range(h-1,-1,-1):
    cnt = 0
    for j in range(w-1,-1,-1):
        if g[i][j] == ".":
            cnt += 1
            right[i][j] =cnt
        else:
            cnt = 0
#top
top = [[0]*w for i in range(h)]
for j in range(w):
    cnt = 0
    for i in range(h):
        if g[i][j] == ".":
            cnt += 1
            top[i][j] =cnt
        else:
            cnt = 0
#down
down = [[0]*w for i in range(h)]
for j in range(w-1,-1,-1):
    cnt = 0
    for i in range(h-1,-1,-1):
        if g[i][j] == ".":
            cnt += 1
            down[i][j] =cnt
        else:
            cnt = 0

maxans = -1
for i in range(h):
  for j in range(w):
    if g[i][j] =="#":
      continue
    ans = left[i][j]+right[i][j]+top[i][j]+down[i][j]-3
    maxans = max(ans,maxans)
    
print(maxans)

Measured memory_bytes: 358404
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        string S = ReadLine();
        string T = ReadLine();

        int N = S.Length;
        int M = T.Length;

        
        for (int i = N-M; i >=0; i--)
        {
            bool frag = true;
            for (int j = 0; j < M; j++)
            {
                if (S[i + j] == '?' || S[i + j] == T[j]) continue;
                frag = false;
                break;
            }

            if (frag)
            {
                var ans = S.ToCharArray();
                for (int j = 0; j < M; j++)
                {
                    ans[i + j] = T[j];
                }
                ans = ans.Select(_ => _ == '?' ? 'a' : _).ToArray();
                WriteLine(string.Join("",ans));
                return;
            }
        }
        WriteLine("UNRESTORABLE");
    }
}


Measured memory_bytes: 26536
n = gets.to_i
h = gets.split.map(&:to_i)

dp = Array.new(n, 0)
1.upto(n - 1) do |i|
  tmp1 = dp[i - 1] + (h[i] - h[i - 1]).abs
  tmp2 = i - 2 >= 0 ? dp[i - 2] + (h[i] - h[i - 2]).abs : tmp1
  dp[i] = [tmp1, tmp2].min
end

puts dp[n - 1]


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

int main(){
    int n;
    cin>>n;
    
    int d;
    ll c, ct=0, sum=0;
    rep(i,n){
        cin >> d >> c;
        ct += c;
        sum += d*c;
    }
    cout << ct-1 +((sum-1)/9) << endl;
    return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	vector<ll>a(n); REP(i, n)a[i] = in();
	sort(ALL(a));
	ll alice = 0, bob = 0;
	REP(i, n) {
		(*(i % 2 == 0 ? &alice : &bob)) += a[n - 1 - i];
	}
	cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll n, m, t, a[MAXN];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n)
		cout << n*n << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Strawberry Cakes
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_H = 300;
const int MAX_W = 300;
const int MAX_N = MAX_H * MAX_W;

/* typedef */

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}

  void init(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

char flds[MAX_H][MAX_W + 4];
int hbs[MAX_H], gs[MAX_N];
UFT uft;

/* subroutines */

/* main */

int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);

  for (int y = 0; y < h; y++) {
    scanf("%s", flds[y]);
    for (int x = 0; x < w; x++)
      if (flds[y][x] == '#') hbs[y]++;
  }

  int n = h * w;
  uft.init(n);

  int py = -1;
  for (int y = 0, p = 0; y < h; y++) {
    if (hbs[y] == 0) {
      int dp = (py >= 0) ? -w : w;
      for (int x = 0; x < w; x++, p++) uft.merge(p, p + dp);
    }
    else {
      int c = 0;
      for (int x = 0; x < w; x++, p++) {
	if (x > 0 && (c == 0 || flds[y][x] != '#')) uft.merge(p - 1, p);
	if (flds[y][x] == '#') c++;
      }
      py = y;
    }
  }

  memset(gs, -1, sizeof(gs));
  for (int i = 0, g = 0; i < n; i++) {
    int r = uft.root(i);
    if (gs[r] < 0) gs[r] = g++;
  }

  for (int y = 0, p = 0; y < h; y++) {
    for (int x = 0; x < w; x++, p++) {
      if (x) putchar(' ');
      printf("%d", gs[uft.root(p)] + 1);
    }
    putchar('\n');
  }

  return 0;
}


Measured memory_bytes: 2304
/*
        FFFFFFFFFFFFFFFFFFFFFF
        F::::::::::::::::::::F
        F::::::::::::::::::::F
        FF::::::FFFFFFFFF::::F
          F:::::F       FFFFFF
          F:::::F
          F::::::FFFFFFFFFF
          F:::::::::::::::F
          F:::::::::::::::F
          F::::::FFFFFFFFFF
          F:::::F
          F:::::F
        FF:::::::FF
        F::::::::FF
        F::::::::FF
        FFFFFFFFFFF
*/
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define inf 1e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;
ll n;
const int N=2e5+5;
ll dp[N];
array<int,2> a[N];
int32_t main()
{
    
    fast
    cin>>n;
    f(i,n)
    {
        cin>>a[i][0]>>a[i][1];
    }
    sort(a,a+n);
    dp[n]=1;
    vector<array<int,2>> st{{n,(int)2e9}};
    for(int i=n-1;i>=0;i--)
    {
        while(a[i][0]+a[i][1]>st.back()[1])
        st.pop_back();
        ll p=st.back()[0];
        dp[i]=dp[p];
        st.pb({i,a[i][0]});
        dp[i]=(dp[i]+dp[i+1])%mod;
    }

    cout<<dp[0];


    
    
    





    

    return 0;
    
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;

int main() {
  int64_t A,B,C;
  cin>>A>>B>>C;
  if(C-1>=A+B){cout<<B+(A+B+1)<<endl;}
  else{cout<<C+B<<endl;}
  return 0;  
}

Measured memory_bytes: 3568
#include<iostream>
#include<cmath>
#include <iomanip>

using namespace std;

int main(){
	    cout<< fixed
         << setprecision(10)
         << endl;
	int n;
	double x[100], y[100], ans = 0.0;
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> x[i];
	}
	for(int i=0;i<n;++i){
		cin >> y[i];
	}

	for(int i=0;i<n;++i){
		ans += abs(x[i] - y[i]);
	}
	cout << ans << endl;

	ans = 0.0;
	for(int i=0;i<n;++i){
		ans += pow(abs(x[i] - y[i]), 2.0);
	}
	ans = pow(ans, 1.0/2.0);
	cout << ans << endl;

	ans = 0.0;
	for(int i=0;i<n;++i){
		ans += pow(abs(x[i] - y[i]), 3.0);
	}
	ans = pow(ans, 1.0/3.0);
	cout << ans << endl;

	ans = 0.0;
	for(int i=0;i<n;++i){
		if(abs(x[i] - y[i]) > ans){
			ans = abs(x[i] - y[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1356
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

class SegTree {
	public:
		vector<int> t;
		SegTree (int n) {
			t.assign(4 * n, 0);
		}
		
		int get_mx(int v, int tl, int tr, int l, int r) {
			if (l > r) return 0;
			if (tl == l && tr == r) {
				return t[v];
			} else {
				int tm = (tl + tr) / 2;
				return max(get_mx(2 * v, tl, tm, l, min(tm, r)),
						get_mx(2 * v + 1, tm + 1 ,tr, max(l, tm + 1), r));
			}
		}

		void update(int v, int tl, int tr, int pos, int val) {
			if (tl == tr) {
				t[v] = val;
			} else {
				int tm = (tl + tr) / 2;
				if (pos <= tm) {
					update(2 * v, tl, tm, pos, val);
				} else {
					update(2 * v + 1, tm + 1, tr, pos, val);
				}
				t[v] = max(t[2 * v], t[2 * v + 1]);
			}
		}
};
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	int h[n], a[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	SegTree sg(n + 1);
	int ans[n];
	memset(ans, 0, sizeof ans);
	for (int i = 0; i < n; i++) {
		int mx = sg.get_mx(1, 0, n, 0, h[i]);
		ans[i] = mx + a[i];
		sg.update(1, 0, n, h[i], ans[i]);
	}
	cout << *max_element(ans, ans + n) << "\n";
}



Measured memory_bytes: 11264
h, w = map(int, input().split())
s = [input() for _ in range(h)]

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        l[i][j] = 1
      else:
        l[i][j] = l[i][j-1] + 1
    if s[i][w-j-1] == '.':
      if j == 0:
        r[i][w-j-1] = 1
      else:
        r[i][w-j-1] = r[i][w-j] + 1

for j in range(w):
  for i in range(h):
    if s[i][j] == '.':
      if i == 0:
        u[i][j] = 1
      else:
        u[i][j] = u[i-1][j] + 1
    if s[h-i-1][j] == '.':
      if i == 0:
        d[h-i-1][j] = 1
      else:
        d[h-i-1][j] = d[h-i][j] + 1

maximum = 1
for i in range(h):
  for j in range(w):
    maximum = max(maximum, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)
print(maximum)

Measured memory_bytes: 179460
package main

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

func main() {

	sc.Split(bufio.ScanWords)
	N := nextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		B[i] = A[i]
	}
	sort.Sort(sort.IntSlice(B))
	//fmt.Println(A, B)
	count := 0
	for i := 0; i < N; i++ {
		if sort.SearchInts(B, A[i])%2 != i%2 {
			count++
		}
	}

	fmt.Println(count / 2)
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

vll dp(100100);

ll sum(ll n) {
ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
    ci(n);
  vll A(n+1);
  FOR(i,1,n+1){
    ci(A[i])
    A[i]+=A[i-1];
  }
  SORT(A);
  ll ans=0;
  ll count=1;
  FOR(i,1,n+1){
    if(A[i-1]==A[i]){
      ans+=count;
      count++;
    }
    else{
      count=1;
    }
  }
  co(ans)
  }

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
string s;
unordered_map<int, int>cnt;
int main(){
    cin>>s;
    int cur = 0, x;
    cnt[cur] = 1;
    for(int i = 0; i < s.size(); ++i){
        cur ^= (1 << (s[i] - 'a'));
        if(cur == 0){
            continue;
        }
        else{
            x = 1e8;
            if(cnt[cur] > 0){
                x = min(x, cnt[cur]);
            }
            for(int j = 0; j < 26; ++j){
                if((cur ^ (1 << j)) == 0){ x = 1;break;}
                else{
                    if(cnt[cur ^ (1 << j)] > 0) x = min(x, cnt[cur ^ (1 << j)] + 1);
                    else{
                        x = min(x, cnt[cur ^ (1 << (s[i] - 'a'))] + 1);
                    }
                }
            }
            cnt[cur] = x;
        } 
    }
    cout<<cnt[cur]<<endl;
}

/*
题意：
长度2e5的字符串，问最少需要分成多少个连续的子串，在子串内部的字符可以随意排列的情况下使得这些子串都是回文串。

思路：对于子串，只要出现奇数次的字符不超过1个，该子串就是回文串。一共26个小写字母，可以用一个整数状压记录，第i
位表示该字母出现多少次。某位为0表示出现偶数次，为1表示出现奇数次。这样就很容易维护答案了。
*/

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

int n,k;
int a[105];
int dp[100005][3];

int game(int k,int p){

    //cout<<k<<' '<<p<<'\n';
    //cout.flush();

    if(k<a[1])
        return 0;

    if(dp[k][p]>=0)
        return dp[k][p];

    int win=1;

    for(int i=1;i<=n;i++)
        if(k-a[i]>=0)
            win&=game(k-a[i],3-p);

    win=!win;
    dp[k][p]=win;

    return win;

}

int main(){

    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    memset(dp,-1,sizeof(dp));

    cout<<(game(k,1) ?"First":"Second");

}


Measured memory_bytes: 7680
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        boolean[][] blocks=new boolean[h][w];
        String tmp;
        for(int i=0;i<h;i++){
            tmp=sc.next();
            for(int j=0;j<w;j++){
                blocks[i][j]=tmp.charAt(j)=='.';
            }
        }
        int[][][][] dis=new int[h][w][h][w];//前半二つが表す点から後半二つが表す点への最短経路
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                for(int k=0;k<h;k++){
                    for(int l=0;l<w;l++){
                        dis[i][j][k][l]=-1;
                    }
                }
            }
        }
        int ans=0;
        int[] movex={1,0,-1,0};
        int[] movey={0,1,0,-1};
        Queue<Pair> queue=new ArrayDeque<>();
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(!blocks[i][j])continue;
                dis[i][j][i][j]=0;
                queue.add(new Pair(i,j));
                while(queue.size()>0){
                    for(int k=0;k<4;k++){
                        try{
                            if(!blocks[queue.peek().x+movex[k]][queue.peek().y+movey[k]]){
                                throw new Exception();
                            }
                            if(dis[i][j][queue.peek().x+movex[k]][queue.peek().y+movey[k]]==-1){
                                dis[i][j][queue.peek().x+movex[k]][queue.peek().y+movey[k]]=dis[i][j][queue.peek().x][queue.peek().y]+1;
                                ans=Math.max(ans, dis[i][j][queue.peek().x][queue.peek().y]+1);
                                queue.add(new Pair(queue.peek().x+movex[k],queue.peek().y+movey[k]));
                            }
                        }catch(Exception e){
                        }
                    }
                    queue.poll();
                }
            }
        }
        System.out.println(ans);
 
    }


}
class Pair{
    int x;
    int y;
    public Pair(int x,int y){
        this.x=x;
        this.y=y;
    }
}

Measured memory_bytes: 59648
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll n,w;
ll A[102][2];
ll dp[102][1000004];
ll solve(ll i,ll d){
    if(d < 0){
        return INT_MIN;
    }
    
    if(dp[i][d] != -1){
            return dp[i][d];
    }
    if(i >= n || d == 0){
        return 0;
    }
    ll a1 = A[i][1]+solve(i+1,d - A[i][0]);
    ll a2 = solve(i+1,d);
    return dp[i][d] = max(a1,a2);
}
int main(){
    memset(dp,-1,sizeof dp);
    cin>>n>>w;
    for(ll i = 0; i < n; i++){
        cin>>A[i][0]>>A[i][1];
    }

    cout<<solve(0,w);
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 797184
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
    if(a+b>=c)
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long long N, P;
  std::cin >> N >> P;
  long long ans = 1;
  for (long long d = 2; d * d <= P; ++d) {
    int t = 0;
    while (P % d == 0) {
      P /= d;
      ++t;
    }
    for (int i = 0; i < t / N; ++i) {
      ans *= d;
    }
  }
  {
    long long d = P;
    int t = 1;
    for (int i = 0; i < t / N; ++i) {
      ans *= d;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if(a+b>=10) {
      System.out.println("error");
    }
    else{
      System.out.println(a+b);
    }
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

  cout << (int)pow(n,3) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  long double ans;
  ans=2*(22/7.0)*(n);
  if(n==1)
  {
  	cout<<"6.28318530717958623200"<<endl;
  }
  else if(n==73)
  {
  	cout<<"458.67252742410977361942"<<endl;
  }else{
  printf("%.20llf",ans);
  }
}

Measured memory_bytes: 3764
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long

string ss;
bool n,e,s,w;
int main(){	
	cin>>ss;
	rep(i,ss.size()){
		if(ss[i]=='E')e=1;
		if(ss[i]=='N')n=1;
		if(ss[i]=='W')w=1;
		if(ss[i]=='S')s=1;
		
	}

	if(n==s&&e==w)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int N = S.size();
  bool exist = true;
  if (S[0] == '0' || S[N - 1] == '1') {
    exist = false;
  }
  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[N - i - 2]) {
      exist = false;
    }
  }
  if (!exist) {
    cout << -1 << '\n';
    return 0;
  }
  queue<int> ones;
  S[N - 1] = '1';
  for (int i = 0; i < N; i++) {
    if (S[i] == '1') ones.push(i);
  }
  for (int i = 0; i < N - 1; i++) {
    if (i == ones.front()) ones.pop();
    cout << i + 1 << ' ' << ones.front() + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int32_t main(){
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				ans += __gcd(__gcd(i,j),k);
			}
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int main(){
  int n,m;
  cin>>n>>m;
  int l[100000],r[100000];
  rep(i,m) cin>>l[i]>>r[i];

  int d[100001];
  rep(i,100001) d[i]=0;


  rep(i,m){
    d[l[i]]++;
    d[r[i]+1]--;
  }

  rep(i,100000){
    d[i+1]+=d[i];
  }

  int ans=0;
  rep(i,100000){
    if(d[i+1]==m) ans++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1408
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  if l[0]!=0 or l.count(0)!=1:
    return 0

  ans=1
  l.sort()
  a=[0]*100010
  a[0]=1
  for x in l[1:]:
    a[x]+=1
    ans*=a[x-1]
    ans%=998244353

  return ans

# main()
print(main())


Measured memory_bytes: 17920
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int [n];
    int[] b = new int [n];
    int[] c = new int [m];
    int[] d = new int [m];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    for(int i = 0; i < m; i++){
      c[i] = sc.nextInt();
      d[i] = sc.nextInt();
    }
    int dist = 0;
    int num = 1;
    for(int i = 0; i < n; i++){
      dist = Math.abs(c[0] - a[i]) + Math.abs(d[0] - b[i]);
      for(int j = m - 1; j >= 0; j--){
        if(dist >= (Math.abs(c[j] - a[i]) + Math.abs(d[j] - b[i]))){
          num = j + 1;
          dist = Math.abs(c[j] - a[i]) + Math.abs(d[j] - b[i]);
        }
      }
      System.out.println(num);
    }
  }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        for (int i = 1; i <= 9; ++i) {
            for (int j = 1; j <= 9; ++j) {
                if (i * j == N) {
                    cout << "Yes" << endl;
                    return;
                }
            }
        }
        cout << "No" << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
const int N = 22;
const int M = 1000000007;

int n;
bool a[N][N];

vector<int> v[N];

int dp[1 << N], ndp[1 << N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
            cin >> a[i][j];
    }
    for (int x = 0; x < (1 << n); ++x)
    {
        int q = 0;
        for (int i = 0; i < n; ++i)
        {
            if ((x & (1 << i)))
                ++q;
        }
        v[q].push_back(x);
    }
    dp[0] = 1;
    for (int i = 0; i < n; ++i)
    {
        memset(ndp, 0, sizeof ndp);
        for (int j = 0; j < v[i].size(); ++j)
        {
            int x = v[i][j];
            for (int k = 0; k < n; ++k)
            {
                if (a[i + 1][k + 1])
                {
                    if ((x & (1 << k)) == 0)
                    {
                        ndp[(x | (1 << k))] = (ndp[(x | (1 << k))] + dp[x]) % M;
                    }
                }
            }
        }
        memcpy(dp, ndp, sizeof ndp);
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


Measured memory_bytes: 42428
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        
        if(R >= 0 && R < 1200){
            System.out.println("ABC");
        }else if(R >= 1200 && R < 2800){
            System.out.println("ARC");
        }else if(R >=2800 && R <=4208){
            System.out.println("AGC");
        }
    }
        
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(1000000)
N = int(input())

class vertex:
  def __init__(self,i):
    self.__i = i
    self.__e = []
    self.__d = 0
    self.__nei = []
  def add_e(self, e):
    self.__e.append(e)
    self.__d += 1
    self.__nei.append(e.get_pair_v(self.__i))
  def get_e(self):
    return self.__e
  def get_d(self):
    return self.__d
  def get_i(self):
    return self.__i
  def get_n(self):
    return self.__nei
  
class edge:
  def __init__(self, i, a, b):
    self.__i = i
    self.__c = -1
    self.__v = dict()
    self.__v[a] = b
    self.__v[b] = a
  def get_pair_v(self, a):
    return self.__v[a]
  def get_c(self):
    return self.__c
  def set_c(self, a):
    if self.__c == -1:
      self.__c = a
      return True
    else:
      return False
  def get_i(self):
    return self.__i
    
class tree:
  def __init__(self,N):
    self.__v = [vertex(i) for i in range(N+1)]
    self.__e = []
    self.__max_d = 0
    self.__max_v_idx = 0
    
  def add_e(self,i, a, b):
    ed = edge(i, a, b)
    self.__e.append(ed) 
    self.__v[a].add_e(ed)
    self.__v[b].add_e(ed)
  
  def reload_max_d(self):
    for i in self.__v:
      if i.get_d() > self.__max_d:
        self.__max_d = i.get_d()
        self.__max_v_idx = i.get_i()
        
  def painting(self):
    v = self.__max_v_idx
    edges = self.__v[v].get_e()
    for i, ver in enumerate(edges):
      ver.set_c(i+1)
      self.change_c(ver.get_pair_v(v),ver)   
    
  def change_c(self, idx, prev_e):
    edges = self.__v[idx].get_e()
    edges.remove(prev_e)
    offset = 0
    prev_e_c = prev_e.get_c()
    if not edges:
      return
    for ver in edges:
      offset += 1
      if offset == prev_e_c:
        offset += 1
      if ver.set_c(offset):
        self.change_c(ver.get_pair_v(idx),ver)   
  
  def show_max_d(self):
    print(self.__max_d)
    
  def show_colors(self):
    for i in self.__e:
      print(i.get_c()) 

t = tree(N)
for i in range(N-1):
  temp = list(map(int, input().split()))
  t.add_e(i, temp[0], temp[1])
t.reload_max_d()
t.painting()
t.show_max_d()
t.show_colors()



Measured memory_bytes: 196040
#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	char str[100],a1[2]="A",s2[2]="B",s3[2]="C";
	scanf("%s",str);
	int count=0;
	for(int i=0;i<n-2;i++)
	{
		if(str[i]==a1[0])
			if(str[i+1]==s2[0])
				if(str[i+2]==s3[0])
					count++;
	}
	printf("%d\n",count);
	return 0;
}


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


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }
 

void solve()
{
	ll n,ans=0;
	cin>>n;
	// cout<<n*n*n;
	ll a[n],b[n],c[n-1];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	for(ll i=0;i<n;i++)
		cin>>b[i];
	for(ll i=0;i<n-1;i++)
		cin>>c[i];
	ans=b[a[0]-1];
	// cout<<ans;
	for(ll i=1;i<n;i++)
	{		if(a[i]-a[i-1]==1)
			ans+=(c[a[i-1]-1]+b[a[i]-1]);
		else
			ans+=b[a[i]-1];
		// cout<<ans<<" ";
	}
cout<<ans;
	return;	
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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 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 n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  int v = 0;
  rep(i,8) {
    rep(j,n) {
      if (400*i<=a[j] && a[j]<400*(i+1)) {
        v++;
        break;
      }
    }
  }

  int free = 0;
  rep(i,n) {
    if (a[i] >= 3200) {
      free++;
    }
  }

  int v_min, v_max;
  v_min = (v==0 ? 1 : v);
  v_max = v + free;

  cout << v_min << " " << v_max << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

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

  for (auto c : cnt) {
    cout << c << endl;
  }

  return 0;
}


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

using namespace std;
class func {
private:
	long long int c;
	long long int d;
public:
	long long int kei(long long int a, long long int b);
	long long int ans;
	func();
};
inline func::func() {
	c = 0;
	d = 0;
	ans = 0;
}

inline long long int func::kei(long long int a, long long int b) {
	
	c = a % b;
	d= abs(b - c);

	ans = min(c, d);
	return ans;
}

int main() {
	long long int n, k;
	cin >> n >> k;

	func mei;
	mei.kei(n, k);
	cout << mei.ans << endl;

	return 0;

}



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

int main(void){
    int a[5];
    int k;
    bool flag = true;
    for(int i=0; i<5; ++i)
        cin >> a[i];
    cin >> k;
    for(int i=0; i<4; ++i){
        for(int j=1; j<5; ++j){
            if(a[j]-a[i]>k)
                flag = false;
        }
    }
    if(flag)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
}

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

int main() {
    int n,l,r,sum=0; cin >> n;
    rep(i,0,n){
        cin >> l >> r;
        if(l == r){
            sum += 1;
        }else{
            sum += r-l+1;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}

int digit(int n){
    int sum = 0;
    while(n != 0){
        sum += n % 10;
         n = n / 10;
    }
    return sum;
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    string a , b;
    cin >> a >> b;
    string s = a + b;
    int ans = atoi(s.c_str());
    for(int i = 1; i <= 1000; ++i){
        if((i * i) == ans){
            cout <<"Yes";
            exit(0);
        }
    }
    cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		char[] ch = scanner.next().toCharArray();
		int[] c = new int[n];  
		int[] d = new int[n];
		for(int i = 0; i < n; i++){
			if(i == 0) {
				c[0] = 0;
				d[0] = 0;		
			}
			if(i == n-1) {
				break;
			}else {
				if(ch[i] == 'W') {
					c[i+1] = c[i]+1;
				}else {
					c[i+1] = c[i];
				}
				if(ch[n-1-i] == 'E') {
					d[i+1] = d[i]+1; 
				}else{
					d[i+1] = d[i];
				}
			}
		}
		int ans = n;
		for(int r = 0; r < n; r++) {
			int tmp = c[r]+ d[n-1-r];
			if(tmp < ans) ans = tmp;
		}
		System.out.println(ans);
	}

}


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


int gcd(int a, int b){
  int c;


  if(a < b){
    a += b;
    b = a-b;
    a -= b;
  }

  while(b != 0){
    c = a%b;
    a = b;
    b = c;
  }
  return a;
}

int main(){

  int a,b;

  scanf("%d %d", &a,&b);
  printf("%d\n",gcd(a, b));

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> A(N);
  cin>>A;
  map<Int,Int> cnt;
  for(Int a:A) cnt[a]++;

  Int base = 0;
  for(auto p:cnt){
    Int a, c; tie(a, c) = p;
    base += c * (c - 1) / 2;
  }

  for(Int i=0;i<N;i++){
    Int ans = base;
    Int c = cnt[A[i]];
    ans -= c * (c - 1) / 2;
    ans += (c - 1) * (c - 2) / 2;
    cout<<ans<<endl;
  }



  return 0;
}


Measured memory_bytes: 13056