akhauriyash/Code-Regression huggingface dataset:
# Code for B - 0 or 1 Swap
# Use input() to fetch data from STDIN
n = input()
a = [int(x) for x in input().split()]

b = sorted(a)

total = 0
for x, y in zip(a, b):
    if x != y:
        total += 1

if total >= 3:
    print("NO")
else:
    print("YES")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

// i枚目まで見た　j枚使って sum K である場合の数
ll dp[60][60][2600];

void solve(){
  ini(N,A);
  vi x(N); in(x);
  dp[0][0][0] = 1;
  rep(i, N){
    rep(j , N){
      rep(k , 2501){
        if(dp[i][j][k]) trc(i,j,k,dp[i][j][k]);
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  rep1(i , 50){
    ans += dp[N][i][i * A];
  }
  out(ans);
}



Measured memory_bytes: 62464
import numpy
n = int(input())
s = input()
Ws = [0] + [1 if i == "W" else 0 for i in s]
Ws_sum = list(numpy.cumsum(Ws))
cnt_l = []
for i in range(n):
    cnt_l.append(Ws_sum[i]+n-i-1-Ws_sum[-1]+Ws_sum[i+1])
print(min(cnt_l))

Measured memory_bytes: 41408
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const double pi=acos(-1);
const ll P = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll n)
{
    ll r=1%P;
    for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
    return r;
}
const double eps=1e-5;
const ll maxn=2e3+10;
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int n,k,q;
ll a[maxn];
ll solve(int  x)
{
    vector<ll> ans;
    ll t=a[x];
    vector<ll> anss;
    for(int i=1; i<=n; i++)
    {
        if(a[i]<t)
        {
            sort(ans.begin(),ans.end());
            int len=ans.size()-k+1;
            for(int j=0; j<len; j++)
            {
                anss.push_back(ans[j]);
            }
            ans.clear();
        }
        else
            ans.push_back(a[i]);
    }
    sort(ans.begin(),ans.end());
    int len=ans.size()-k+1;
    for(int j=0; j<len; j++)
    {
        anss.push_back(ans[j]);
    }
    sort(anss.begin(),anss.end());
    if(anss.size()<q)
    return -1;
    return  anss[q-1]-t;
}
int main()
{
    cin>>n>>k>>q;
    ll ans=1e18;
    for(int i=1; i<=n; i++) cin>>a[i];
    for(int i=1; i<=n; i++)
    {
        ll t=solve(i);
        if(t==-1)continue;
        ans=min(t,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3708
#include<stdio.h>
int main(void)
{
	int i,c,w[12];
	int n,x;
	while(1){
	c=0;
		scanf("%d",&n);
		if(n==-1) break;
			while(1){
				x=n/4;
			if(x<1) break;  
				w[c]=n%4;
				n=x;
				c++;
			}
		printf("%d",n);	
	for(i=c-1;i>=0;i--){
		printf("%d",w[i]);
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
N = int(input())
X = list(map(int, input().split()))

Y = sorted(X[:])
b_median = Y[N // 2 - 1]
a_median = Y[N // 2]

for i in range(N):
  if X[i] >= a_median:
    print(b_median)
  elif X[i] <= b_median:
    print(a_median)

Measured memory_bytes: 30840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

ll n,k;
ll ans = 1;
ll mod = 1000000007;
vvll e;
vector<bool> v;

void dfs(ll par){
    v[par] = true;
    ll counter = 2;
    rep(i, e[par].size()){
        if(!v[e[par][i]]){
            ans = ans*(k-counter)%mod;
            dfs(e[par][i]);
            counter++;
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    //int n,m;
    cin>>n>>k;
    e = vector<vll>(n);
    v = vector<bool>(n, false);
    rep(i, n-1){
        ll a,b;cin>>a>>b;
        e[a-1].push_back(b-1);
        e[b-1].push_back(a-1);
    }
    
    ans *= k;
    v[0] = true;
    rep(i, e[0].size()){
        //v[i] = true;
        ans = (k-1-i)*ans%mod;
        dfs(e[0][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main()
{
  ll a,b;
  cin>>a>>b;
  ll arr[b];
  set<int> s;
  
  for(int i = 0;i<b;i++){
  cin>>arr[i];
  s.insert(arr[i]);
  }
  if(s.find(a)==s.end())
  cout<<a<<"\n";
  else
  {
      // element is present in the sequence..
      ll diff = 102;
      ll value = 0;
      for(ll i = 0;i<=101;i++)
      {
          if(s.find(i)==s.end())
          {
              if(diff > abs(i - a))
              {
                  diff = abs(i - a);
                  value = i;
              }
          }
      }
      cout<<value<<"\n";
  }
  
  
  
 
  return 0;
}

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

using LL = long long;

int main() {
  string A;
  cin >> A;

  map<char, LL> cnt;
  for(auto& i: A) ++cnt[i];

  LL N = A.size();
  auto res = 1 + N * (N - 1) / 2;
  for(auto i: cnt) res -= i.second * (i.second - 1) / 2;
  cout << res << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>

int main() {
  char buf[16];
  scanf("%s", buf);
  std::string s = buf;

  std::string t;
  for (size_t i = 0; i < 10; ++i) {
    if (s == t) return puts("Yes"), 0;
    t += "hi";
  }

  puts("No");
}


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

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  unordered_map<ll,P> mp;
  rep(i,0,n){
    int a;
    cin >> a;
    mp[i+a].first++;
    if(i-a > 0) mp[i-a].second++;
  }
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    ans += (itr->second.first)*(itr->second.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 15448
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	 int n;
	 cin >> n;
	 string s;
	 cin >> s;
	 
	 if(n % 2){
		cout << "No";
		return 0;
	 }
	 
	 for(int i = 0; i < n/2; i++){
		if(s[i] != s[i+n/2]){
			cout << "No";
			return 0;
		}
	 }
	 cout << "Yes";
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int a,b,c;
int x,y,z;

int main(){
  cin>>a>>b>>c;

  while(a%2==0){
    x++;
    a/=2;
  }
  while(b%2==0){
    y++;
    b/=2;
  }
  while(c%2==0){
    z++;
    c/=2;
  }

  if(x==y&&y==z){
    if(a==b&&b==c&&x!=0){
      cout<<-1<<endl;
      return 0;
    }
    if(a!=1||b!=1||c!=1){
      cout<<x+1<<endl;
      return 0;
    }
  }

  cout<<min(x,min(y,z))<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

vector<vector<int>> G;
vector<ll> sum(202020);

void dfs(int v, int p, ll s){
    sum[v] += s;
    for(auto nv : G[v]){
        if(nv == p) continue;
        dfs(nv,v,sum[v]);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    G.resize(N);
    REP(i,N-1){
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    REP(i,Q){
        int p,x;
        cin >> p >> x;
        --p;
        sum[p] += x;
    }
    
    dfs(0,-1,0);
    REP(i,N) cout << sum[i] << " ";
    cout << endl;
}


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

using namespace std;

int main(){
  string s; cin >> s;
  bool flag=true;
  int tmp=s.size();
  for(int i=0;i<tmp;){
    if(tmp-i>=7 && s.substr(tmp-(7+i),7)=="dreamer") i+=7;
    else if(tmp-i>=6 && s.substr(tmp-(6+i),6)=="eraser") i+=6;
    else if(tmp-i>=5 && s.substr(tmp-(5+i),5)=="dream" || s.substr(tmp-(5+i),5)=="erase") i+=5;
    else { flag=false; break; }
  }
  if(flag) cout << "YES";
  else cout << "NO";
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
import itertools

N, A, B, C = map(int, input().split())
l = []

for i in range(N):
    l.append(int(input()))
    
prod = list(itertools.product(['A','B','C','X'], repeat=N))

mps = []

for prod_e in prod:
    if prod_e.count('A') * prod_e.count('B') * prod_e.count('C') != 0:
        mp = 0
        length = {'A':0, 'B':0, 'C':0, 'X':0}
        for index, prod_e_e in enumerate(prod_e):
            length[prod_e_e] += l[index]
        mp += abs(length['A'] - A) + abs(length['B'] - B) + abs(length['C'] - C)
        mp += (prod_e.count('A')-1) * 10 + (prod_e.count('B')-1) * 10 + (prod_e.count('C')-1) * 10
        mps.append(mp)

print(min(mps))

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

#define pb push_back
#define ll long long

ll M= 1000000007;

vector<ll> adj[2*100005+1];
ll vis[2*100005+1];
vector<ll> cc;
ll ccnt=0;

void explore(ll v) {
    vis[v]=1;
    ccnt++;

    for(ll i=0;i<adj[v].size();i++) {
        if(vis[adj[v][i]]!=1) {
            explore(adj[v][i]);
        }
    }
}

void dfs(ll n) {
    
    for(ll i=0;i<n;i++) {
        if(vis[i]!=1) {
            ccnt=0;
            explore(i);
            cc.pb(ccnt);
        }
    }
}

int main() {

    ll n,m;
    cin>>n>>m;
    ll ans=1;
    if(m==0) {
        ans=1;
    } else {
        memset(vis,0,sizeof(vis));
        for(ll i=0;i<m;i++) {
            ll x,y;
            cin>>x>>y;
            x=x-1;
            y=y-1;
            auto it=find(adj[x].begin(),adj[x].end(),y);
            if(it==adj[x].end()) {
            adj[x].pb(y);
            adj[y].pb(x);
            }
        }

        dfs(n);

        for(ll i=0;i<cc.size();i++) {
            ans=max(ans,cc[i]);
        }
    }
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 22372
#include <iostream>
#include <string>


using namespace std;


int main()
{
    string S;
    cin >> S;
    
    
    int ans = 0;
    int len = S.length();
    for( int i = 0; i < len-1; ++i ){
        if( S.c_str()[i] != S.c_str()[i+1] ){
            ++ans;
        }
    }
    
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 512
n = int(input())
h = list(map(int, input().split()))[::-1]

result = True
for i in range(n-1):
    if h[i] < h[i+1]:
        if h[i+1] - 1 <= h[i]:
            h[i+1] = h[i+1] -1
        else:
            result = False
            break

if result == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63856
a = int(input())
b_list =[]
for i in range(a):
    b = input()
    b_list.append(b)
def again(p,q):
    #p=a int
    #q= b_list list
    count = 0
    for i in range(p):
        if  q.count(q[i]) == 2:
            return False
            break
        else:
            count += 1
    if count == p:
        return True

def tail_head(p,q):
    count = 0
    for i in range(p-1):
        if q[i][len(q[i])-1]== q[i+1][0]:
            count += 1
        else:
            return False
            break
        if count == p-1:
                return True
                
if again(a,b_list) and tail_head(a,b_list):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll h, w, n; cin >> h >> w >> n;
  ll sr, sc; cin >> sr >> sc;
  string s, t; cin >> s >> t;

  ll d=0, u=h+1;
  bool is_fall = false;
  for (ll i=n-1; i>=0; i--) {
    if (t.at(i) == 'U' && u<=h) u++;
    else if (t.at(i) == 'D' && d>=1) d--;
    if (s.at(i) == 'U') d++;
    else if (s.at(i) == 'D') u--;
    if (d >= u-1) is_fall = true;
  }
  if (d >= sr || u <= sr) is_fall = true;

  ll l=0, r=w+1;
  for (ll i=n-1; i>=0; i--) {
    if (t.at(i) == 'L' && r<=w) r++;
    else if (t.at(i) == 'R' && l>=1) l--;
    if (s.at(i) == 'L') l++;
    else if (s.at(i) == 'R') r--;
    if (l >= r-1) is_fall = true;
  }
  if (l >= sc || r <= sc) is_fall = true;

  if (is_fall) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
#define MAX 10000000
int cc=1;
int A,B,C,N;
set< PP > s;
vector< PP > t;
 
map< P , set< P > > xy,yz,zx;
 
int par[MAX],rak[MAX];
 
void init(){
  for(int i=0;i<MAX;i++)
    par[i]=i,rak[i]=1;
}
 
int find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
}
 
void unite(int x,int y){
  x=find(x),y=find(y);
  if(x==y)return;
  if(rak[x]<rak[y])swap(x,y);
  par[y]=x;
  rak[x]+=rak[y];
}
 
void calc(map< P , set<P> > &mp){
  map< P , set<P> > :: iterator it;
  for(it=mp.begin();it!=mp.end();it++){
    set<P> :: iterator si=it->second.begin();
    set<P> :: iterator ti=it->second.end();
    set<P> :: iterator A=si,B;
    while(1){
      B=A;
      B++;
      if(B==ti)break;
      if(A->second>0&&B->second>0){
        unite(A->second,B->second);
      }
      A=B;
    }
  }
}
 
void add(int nx,int ny,int nz){
  if(nx<0||A<=nx||ny<0||B<=ny||nz<0||C<=nz)return;
  if(s.count(PP(nx,P(ny,nz))))return;
  s.insert( PP(nx,P(ny,nz)) );
  xy[ P(nx,ny) ].insert( P(nz,cc) );
  yz[ P(ny,nz) ].insert( P(nx,cc) );
  zx[ P(nz,nx) ].insert( P(ny,cc) );     
  cc++;
}
 
int main(){
  init();
  scanf("%d %d %d %d",&A,&B,&C,&N);
  t.resize(N);

  for(int i=0;i<N;i++){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    s.insert( PP(x,P(y,z)) );
    t[i]=PP(x,P(y,z));

    xy[ P(x,y) ].insert( P(z,0) );
    yz[ P(y,z) ].insert( P(x,0) );
    zx[ P(z,x) ].insert( P(y,0) );     
  }


  add(0,0,0);

 
  for(int i=0;i<(int)t.size();i++){
    int x=t[i].first;
    int y=t[i].second.first;
    int z=t[i].second.second;
     
    for(int dx=-1;dx<=1;dx++){
      for(int dy=-1;dy<=1;dy++){
        for(int dz=-1;dz<=1;dz++){
          add(x+dx,y+dy,z+dz);
 
          add(x+dx,0,0);
          add(0,y+dy,0);
          add(0,0,z+dz);
 
          //          add(x+dx,B-1,C-1);
          //          add(A-1,y+dy,C-1);
          //          add(A-1,B-1,z+dz);
 
          //          add(x+dx,B-1,0);
          //          add(A-1,y+dy,0);
          //          add(A-1,0,z+dz);
 
          //          add(x+dx,0,C-1);
          //          add(0,y+dy,C-1);
          //          add(0,B-1,z+dz);
 
          add(x+dx,y+dy,0);
          add(0,y+dy,z+dz);
          add(x+dx,0,z+dz);
 
          //          add(x+dx,y+dy,C-1);
          //          add(A-1,y+dy,z+dz);
          //          add(x+dx,B-1,z+dz);
        }
      }
    }
  }
   
 
  calc(xy);
  calc(yz);
  calc(zx);
 
  int ans=0;
  for(int i=1;i<cc;i++)
    if(find(i)==i)ans++;
 
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 416592
# -*- coding: utf-8 -*-
import numpy

n,d = [int(c) for c in input().split(' ')]

points = []
for i in range(n):
    p = [int(c) for c in input().split(' ')]
    points.append(p)

num_int = 0

for i in range(n):
    for j in range(n):
        if i != j:
            y = numpy.array(points[i])
            z = numpy.array(points[j])
            
            u = y - z
            
            dist = numpy.linalg.norm(u)

            if dist.is_integer():
                num_int += 1

print(num_int // 2)
                


Measured memory_bytes: 12436
// 任意の場合においてこれでいいのか、頭がないのでわからない
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  cout << x2 - dy << ' ' << y2 + dx << ' ' << x1 - dy << ' ' << y1 + dx << endl;;
}

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n;

int main() {
  cin >> n;
  vector<vector<int>> g(n);
  range(i, 0, n) {
    string s;
    cin >> s;
    range(j, 0, n) {
      if(s[j] == '1') g[i].push_back(j);
    }
  }
  vector<int> was(n, -1);
  function<void(int, int)> dfs = [&](int v, int t) {
    was[v] = t;
    for(int u : g[v]) {
      if(was[u] == -1) dfs(u, t ^ 1);
    }
  };
  dfs(0, 0);
  range(i, 0, n) {
    for(int u : g[i]) if(was[u] == was[i]) {
      cout << -1;
      return 0;
    }
  }
  auto bfs = [&](int v) {
    vector<int> dep(n, -1);
    vector<int> que;
    que.push_back(v);
    dep[v] = 0;
    for(int b = 0; b < (int) que.size(); b++) {
      for(int u : g[que[b]]) {
        if(dep[u] != -1) continue;
        dep[u] = dep[que[b]] + 1;
        que.push_back(u);
      }
    }
    return *max_element(dep.begin(), dep.end());
  };
  int res = 0;
  range(i, 0, n) res = max(res, bfs(i));
  cout << res + 1;
  return 0;
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
     ifstream in("input.txt");
     cin.rdbuf(in.rdbuf());
  //*/
  long double A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = 0;
  if((A + B) / 2 >= C){
    int d = min(X, Y);
    ans += C * d * 2;
    X -= d;
    Y -= d;
  }
  if(A >= C * 2){
    ans += C * 2 * X;
  } else{
    ans += A * X;
  }
  if(B >= C * 2){
    ans += C * 2 * Y;
  } else{
    ans += B * Y;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int x; cin >> x;
    OUT(abs(x-1))

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


int ball[200200];

int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }

  bool finish = false;

  FORD(i,N-1,0){
    int ref = i+1;
    int dbnum = 1;
    int sum_ball = 0;
    while(ref<=N){
      sum_ball += ball[ref];
      ++dbnum;
      ref = (i+1)*dbnum;
    }
    if(a[i]==sum_ball%2) continue;
    else ball[i+1]++;
  }

  // if(finish == true) cout << -1 << endl;
  // else{
    int sum_ball = 0;
    FOR(i,1,N) sum_ball += ball[i];
    cout << sum_ball << endl;
    int ref = 1;

    while(sum_ball>0){
      if(ball[ref]==1) cout << ref << " ";
      sum_ball -= ball[ref];
      ref++;
    }
  // }

}



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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll r;
	cin>>r;
	cout<<pow(r,2)*3<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3768
s = input()
 
for i in range(int(input())):
    cmd = input().split()
    a,b = [int(x) for x in cmd[1:3]]
 
    if cmd[0] == 'print':
        print(s[a:b+1])
    elif cmd[0] == 'reverse':
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif cmd[0] == 'replace':
        s = s[:a] + cmd[3] + s[b+1:]

Measured memory_bytes: 7704
s = list(input())
ans = 0
if len(s)%2==0:
    for i in range(len(s)//2):
        if s[2*i]=="L" or s[2*i+1]=="R":
            ans += 1
elif len(s)%2!=0:
    for i in range(len(s)//2):
        if s[2*i]=="L":
            ans += 1
        elif s[2*i+1]=="R":
            ans += 1
    if s[-1]=="L":
        ans += 1

if ans==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int n;
	cin >> n;
	long max = 0, min = 0, total = 0;
	for (int i = 0; i < n;++i) {
		int num;
		cin >> num;
		if (num > max || max == 0) max = num;
		if (num < min || min == 0) min = num;
		total += num;
	}
	cout << min << " " << max << " " << total << endl;
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#define Maxn 100005
using namespace std;
const int N=1e9+7;
bool Cmp(int a,int b){
    return a>b;
}
int main(){
    long long x[Maxn],y[Maxn],n,m,sumx=0,sumy=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>x[i];
    for(int i=0;i<m;i++)
        cin>>y[i];
    sort(x,x+n,Cmp);
    sort(y,y+m,Cmp);
    for(int i=0;i<=n-1;i++){
        sumx=(sumx+(x[i]-x[i+1])*(n-1-i)*(i+1))%N;

    }
    for(int i=0;i<=m-1;i++){
        sumy=(sumy+(y[i]-y[i+1])*(m-1-i)*(i+1))%N;
    }
    cout<<sumx*sumy%N<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
//define
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define elif else if
//vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
//queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
//mapdefine
#define mint map<int>
#define mc map<char>
//pairdefine
#define pint pair<int,int>
#define pis pair<int,str>
#define pic pair<int,char>
#define pci pair<char,int>
#define mod 100000007

string syugei(int N){
  string ST="b";
  for(int i=0;i<N;i++){
    if(i%3==0||i==0)ST="a"+ST+"c";
    else if(i%3==1||i==1)ST="c"+ST+"a";
    else if(i%3==2||i==2)ST="b"+ST+"b";
  }
  return ST;
}
// int hantei(string S){
//   for(int i=0;i<S.size(),i++){
//     for(int j=0;j<)
//   }
// }
//main
signed main(){
  int N,M,O,P,X,count=0,count2=0;
  double D=0;
  int c='A'-'a';
  //char C;
  str S,T;
  cin>>N;
  int A[N]={},B[N]={};
  rep(0,N){
    cin>>A[i];
    B[i]=i+1;
    if(A[i]!=B[i])count+=1;
  }
  if(count==2||count==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
/* ***********************************************
Author        :yang12138
Created Time  :2018年07月01日 星期日 19时30分52秒
File Name     :A.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=2e5+10;

ll a[N];

void solve(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",a+i),a[i]-=i;
	sort(a+1,a+n+1);
	ll ans=0;
	int id=(n+1)/2;
	for(int i=1;i<=n;i++){
		ans+=abs(a[i]-a[id]);
	}
	printf("%lld\n",ans);

}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


Measured memory_bytes: 1792
x=int(input())
a=[]
n=input().split(" ")
for i in range(0,x):
    a.append(int(n[i]))
s=1
for j in range(0,len(a)):
    s = s * a[j]
t=1
sum=0
for k in range(0,len(a)):
    t=s/a[k]
    sum=sum+t
print(s/sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = (int)1e9 + 7;
int INF = (int)2e18;


signed main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];
    sort(d.begin(), d.end());
    if (d[N / 2 - 1] == d[N / 2]) {
        cout << 0 << endl;
    } else {
        cout << d[N / 2] - d[N / 2 - 1] << endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int> 
#define vll vector<ll> 
#define vpll vector<pair<ll ,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define map map<ll ,ll>
#define umap unordered_map<ll , ll>
#define endl "\n"
#define set set<ll> 
#define setC set<char>
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define fastcout ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcases int tt = 1 ; cin >> tt ; for(int i = 1 ; i <= tt ; ++i)
#define codejam cout << "Case #"<<i <<": "; 
#define FOR(i,a,n) for(int i = a ; i <= n ; ++i)
#define FORback(i,a,n) for(int i = n ; i >= a ; --i)

typedef long long int ll;

void solv(){
    ll n;
    cin >> n ;

    vvi arr(n , vi(3 ));

    FOR(i , 0 , n-1){
        FOR(j , 0 , 2){
            cin >> arr[i][j];
        }
    }

    vvi dp(n+1 , vi(3 , 0));

    FOR(i , 1 , n){
        dp[i][0] = max(dp[i-1][1] , dp[i-1][2]) + arr[i-1][0];
        dp[i][1] = max(dp[i-1][0] , dp[i-1][2]) + arr[i-1][1];
        dp[i][2] = max(dp[i-1][0] , dp[i-1][1]) + arr[i-1][2];
    }

    cout << max({dp[n][0] , dp[n][1] , dp[n][2]})<< endl;
}

int main(){
    fast ;    
    // testcases{
        // codejam ;
        solv();
    // } 
}




Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define f first
#define s second
const int limB = 1<<22;
const int mt = 20;
const ll inf = 9223372036854775807;

int W = 1;
pll ords[limB];

void precalca(int N, ll* vals, ll* wts) {
    if(N<=0) return;
    for(int msk=(1<<N)-1; msk>=0; msk--) {
        ll a = 0, b = 0;
        for(int i=0; i<N; i++) {
            if((1<<i) & msk) continue;
            a += vals[i];
            b += wts[i];
        }
        ords[W++] = {b, a};
    }
    sort(ords, ords+W);
    for(int i=1; i<W; i++) {
        ords[i].s = max(ords[i].s, ords[i-1].s);
    }
}

ll maxVal(ll k) {
    if(k<0) return 0;
    int pos = upper_bound(ords, ords+W, pll(k, inf)) - ords;
    pos --;
    // printf("buscando %lld encontre %lld %lld\n", k, ords[pos-1].f, ords[pos-1].s);
    return ords[pos].s;
}

int main() {
    int N ;
    ll maxW ;
    ll vals[50], wts[50];
    ll ans = 0;
    scanf("%d%lld", &N, &maxW);
    for(int i=0; i<N; i++)
        scanf("%lld%lld", &vals[i], &wts[i]);
    precalca(N-mt, vals + mt, wts + mt);
    N = min(N, mt);
    for(int msk=(1<<N)-1; msk>=0; msk--) {
        ll a = 0, b = 0;
        for(int i=0; i<N; i++) {
            if((1<<i) & msk) continue;
            a += vals[i];
            b += wts[i];
        }
        if(b > maxW)
            continue;
        ans = max(ans, a + maxVal(maxW - b));
    }
    printf("%lld\n", ans);
}



Measured memory_bytes: 19612
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n%2==0){
		cout<<n*(n-1)/2-n/2<<endl;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(i+j==n+1){
					continue;
				}else{
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}else{
		cout<<n*(n-1)/2-(n-1)/2<<endl;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(i+j==n){
					continue;
				}else{
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(void) {
  using namespace std;
  string x;
  cin >> x;
  int n = 0;
  for(auto c : x) {
    if(c == '+') {
      n++;
    } else if(c == '-') {
      n--;
    }
  }
  cout << n << endl;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b, k;
  cin >> a >> b >> k;

  FOR (i, a, b + 1) {
    if ((a <= i && i <= a + k - 1) || (b - k + 1 <= i && i <= b)) cout << i << endl;
  }
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int C[20], V[20];
    for(int i=0;i<n;i++){
        cin >> V[i];
    }
    for(int i=0;i<n;i++){
        cin >> C[i];
    }
    int ans = 0;
    for(int i = 0; i<n;i++){
        if(V[i] > C[i]){
            ans += V[i] - C[i];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI M_PI
#define EPS 1e-14
using namespace std;
typedef complex<double> point;
namespace std {
  bool operator < (const point& a, const point& b){
    return fabs(real(a)-real(b)) <EPS  ? imag(a) < imag(b) : real(a) < real(b);
  }
  bool operator == (const point& a,const point& b){
    return abs(real(a)-real(b))<EPS&&abs(imag(a)-imag(b))<EPS;
  }
  bool operator != (const point& a,const point& b){
    return !(abs(real(a)-real(b))<EPS&&abs(imag(a)-imag(b))<EPS);
  }
  
}
int n;
double cross(point a,point b){return a.real()*b.imag()-a.imag()*b.real();}

point rot(point a,double rad){
  return a*conj(point(cos(rad),sin(rad)));
}

point crosspoint(point a,point b,point c,point d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
double getArea3(point a,point b,point c){return abs(cross(b-a,c-a)/2);}

double solve(){
  vector <point> a;
  double base=2*PI/3;
  point A=point(0,1/sqrt(3));
  a.push_back(A);
  a.push_back(rot(A,base));  
  a.push_back(rot(A,base*2));

  double rad=2*PI/n;
  for(int i=1;i<=n;i++)
    for(int j=0;j<3;j++)a.push_back(rot(a[j],rad*i));
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  
  double dis=1e9;
  point B;
  for(int i=0;i<a.size();i++)
    if(A!=a[i]&&real(a[i])>0&&abs(A-a[i])<dis)dis=abs(A-a[i]),B=a[i];
  point C=crosspoint(A,rot(A,base),B,rot(B,base*2));
  double s=getArea3(A,B,C);
  double S=(dis/2)*(dis/2)/tan(PI/a.size());
  return (S-s)*a.size();
}


int main(){
  while(cin>>n,n)printf("%.15f\n",solve());
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		ll k;
		cin>>k;
		int a[n];
		int che[n];
		FOR(i,0,n)
		{
			cin>>a[i];
			che[i]=-1;
		}
		int i=0,c=0;
		while(che[i]==-1 && k>0)
		{
//			cout<<i<<' ';
			che[i]=c;
			k--;
			c++;
			i=a[i]-1;
		}
//		cout<<k<<' ';
		k=k%(c-che[i]);
		while(k>0)
		{
			i=a[i]-1;
			k--;
		}
		cout<<i+1;
	}
	return 0;
}


Measured memory_bytes: 5216
#include <stdio.h>

int main(void) {
    int n, count = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        int j = i, keta = 0;
        while (j != 0) {
            j /= 10;
            keta++;
        }
        if(keta % 2 == 1) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()
    _ = int(input())
    K = [int(i) for i in input().split()]

    def solve(k):
        cd = 0
        cm = 0
        cdm = 0
        ans = 0
        for i in range(N):
            if S[i] == 'D':
                cd += 1
            elif S[i] == 'M':
                cm += 1
                cdm += cd
            elif S[i] == 'C':
                ans += cdm
            if k - 1 <= i:
                if S[i-k+1] == 'D':
                    cdm -= cm
                    cd -= 1
                if S[i-k+1] == 'M':
                    cm -= 1
        return ans

    for k in K:
        print(solve(k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 60652
#include <iostream>

using namespace std;

int main() {
    int x1, x2, y1, y2;
    int x3, x4, y3, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int delta_x, delta_y;
    delta_x = x2 - x1;
    delta_y = y2 - y1;
    x3 = x2 - delta_y;
    y3 = y2 + delta_x;
    x4 = x3 - delta_x;
    y4 = y3 - delta_y;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;
  string ans;
  
  if(a>=b) rep(i,a) ans+=to_string(b);
  else rep(i,b) ans+=to_string(a);

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3672
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<iostream>
#include<algorithm>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
int read()
{
	int s=0;int c=getchar(),f=1;
	while(c<48||c>57)
	{
		if(c==45) f=-1;
		c=getchar();
	}
	while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s*f;
}
void write(int x)
{
	if(x>=10) write(x/10);
	putchar(x%10+48);
}
void W(int x)
{
	if(x<0) x=-x,putchar(45);
	write(x);
}
const int maxn=111;
int A[maxn],B[maxn],C[maxn];
int main()
{
	int N=read();
	A[0]=-3;
	for(int i=1;i<=N;++i) A[i]=read();
	for(int i=1;i<=N;++i) B[i]=read();
	for(int i=2;i<=N;++i) C[i]=read();
	int ans=0;
	for(int i=1;i<=N;++i)
	{
		ans+=B[A[i]];
		if(A[i]==A[i-1]+1) ans+=C[A[i]];
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long a = scanner.nextLong();
			long b = scanner.nextLong();
			long c = scanner.nextLong();
			long d = scanner.nextLong();
			System.out.println(
					b - a - b / c - b / d + b / lcm(c, d) + (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d) + 1);
		}
	}

	/**
	 * @param n
	 * @param m
	 * @return nとmの最小公倍数
	 */
	private static long lcm(long n, long m) {
		return n / gcd(n, m) * m;
	}

	/**
	 * @param n
	 * @param m
	 * @return nとmの最大公約数
	 */
	private static long gcd(long n, long m) {
		if (n > m) {
			return gcd(m, n);
		}
		if (0 == n) {
			return m;
		}
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 25172
module Main where

import Control.Applicative
import Control.Monad
import Data.List

check :: (Int, Int, Int) -> (Int, Int, Int) -> Bool
check (t1, x1, y1) (t2, x2, y2)
    | t >= d && oddEven t d = True
    | otherwise             = False
  where
    t = t2 - t1
    d = abs (x2 - x1) + abs (y2 - y1)
    oddEven s t
        | all odd [s, t] || all even [s, t] = True
        | otherwise                         = False

main :: IO ()
main = do
    n <- readLn
    ts <- replicateM n $ do
        [t, x, y] <- fmap read . words <$> getLine :: IO [Int]
        return (t, x, y)
    let ts' = (0, 0, 0) : ts
    if and $ zipWith check ts' (tail ts')
        then putStrLn "Yes"
        else putStrLn "No"

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

using namespace std;
using ll = long long;

int n;
map<pair<int, int>, int> mp;

vector<ll> tovec(int x){
    vector<ll> res;
    while(x){
        res.push_back(x%10);
        x /= 10;
    }
    return res;
}

int main(){
    cin>>n;
    for(int i = 1; i <= n; i++){
        auto vec = tovec(i);
        mp[{vec.back(), vec.front()}]++;
    }
    ll res = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            res += (ll) mp[{i, j}] * mp[{j, i}];
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int a,b;cin >> a >> b;
    string ans = a%3 == 0 || b%3 == 0 || (a + b)%3 == 0 ? "Possible" : "Impossible";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long int lli;

void prime(vector<bool>& is_prime, vector<int>& divid){
  int n = is_prime.size();
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++) {
    if(is_prime[i] == false)continue;
    divid[i] = i;
    for (int j = 2*i; j < n; j+=i) is_prime[j] = false, divid[j] = i;
  }
}

lli num_factor(lli val, vector<int>& divid){
  lli res = 1;
  while(val > 1)val /= divid[val], res++;
  return res;
}

int main(){
  lli n, mod = 1e9 + 7;
  std::cin >> n;
  vector<int> divid(3000, -1),fact(3000, 0);
  vector<bool> is_prime(3000, true);
  prime(is_prime, divid);
  lli ans = 1, val;
  for (int i = 2; i <= n; i++) {
    val = i;
    while(val > 1)fact[divid[val]]++, val /= divid[val];
  }
  for (int i = 0; i < 3000; i++) {
    ans *= fact[i] + 1;
    ans %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,k;
int main(){
	n=read(),k=read();
	if(k>(n+1)/2){
		return !printf("-1\n");
	}
	int mid=(n+1)/2;
	for(int i=1;i<=mid;++i){
		printf("%d %d %d\n",k+(i-1)*2,k+n+mid-i,k+2*n+i-1);
	}
	for(int i=mid+1;i<=n;++i){
		printf("%d %d %d\n",k+(i-mid-1)*2+1,k+2*n-(i-mid),k+2*n+i-1);
	}
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

int a[3][3];

int main() {
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    int b[n];
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    // yoko
    for (int i = 0; i < 3; ++i) {
        int cnt = 0;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < n; ++k) {
                if(a[i][j] == b[k]) cnt++;
            }
        }
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    // tate
    for (int i = 0; i < 3; ++i) {
        int cnt = 0;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < n; ++k) {
                if(a[j][i] == b[k]) cnt++;
            }
        }
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    // naname
    int cnt_n = 0;
    for (int i = 0; i < n; ++i) {
        if(b[i] == a[0][0]) cnt_n++;
    }
    for (int i = 0; i < n; ++i) {
        if(b[i] == a[1][1]) cnt_n++;
    }
    for (int i = 0; i < n; ++i) {
        if(b[i] == a[2][2]) cnt_n++;
    }
    if(cnt_n == 3){
        cout << "Yes" << endl;
        return 0;
    }
    cnt_n = 0;
    for (int i = 0; i < n; ++i) {
        if(b[i] == a[0][2]) cnt_n++;
    }
    for (int i = 0; i < n; ++i) {
        if(b[i] == a[1][1]) cnt_n++;
    }
    for (int i = 0; i < n; ++i) {
        if(b[i] == a[2][0]) cnt_n++;
    }
    if(cnt_n == 3){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main()
{
  int min = 1<<30;
  int ans = -1;
  int N, T, A;
  std::cin >> N >> T >> A;
  A*=1000, T*=1000;
  for(int i= 0; i < N; i++){
  	int h;
    std::cin >> h;
    const int v = std::abs(A-(T-6*h));
    if(min>v){min=v,ans=i+1;}
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#coding: utf-8

alpb = [0 for i in range(26)]
while True:
    try:
        x = input().lower()
    except EOFError:
        break
    for i in x:
        y = ord(i)
        if y < 97 or 122 < y:
            continue
        alpb[y - 97] += 1
for i in range(26):
    print('{0} : {1}'.format(chr(i + 97), alpb[i]))


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

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;
 int main(){
    int N;
    bool flag = false;
    int count = 0;
    cin >> N;
    for (int i = 0; i < N; i++){
        int num1, num2;
        cin >> num1 >> num2;
        if (num1 == num2) {
            count++;
        }
        else count = 0;
        if (count >= 3) {
            flag = true;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
 }

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;

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

  int aji = 0;
  for(int i = 0; i < n; i++) {
    aji += l+i;
  }

  int m = 10000;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(abs(l+i) < m) {
      ans = aji - (l+i);
      m = abs(l+i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
  
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        if (S.compareTo("2019/04/30") > 0) {
            System.out.println("TBD");
        }
        else {
            System.out.println("Heisei");
        }
    }
}


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

int ans=0;

inline int read()
{
	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 writ(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x){writ(x);putchar('\n');}

int main()
{
	int n=read();
	for (int i=1;i<=n;++i) 
	{
		int x=read();
		while (x%2==0)
			++ans,x/=2;
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 256