akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	int m,n,a[1001],s[1001],i,j,b[101][101];		
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&b[i][j]);
		}
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			if(a[i]==b[i][j]){
				s[j]++;
			}
			else{
				s[a[i]]++;
			}
		}
	}
	for(j=1;j<=n;j++){
		printf("%d\n",s[j]);
	}
	return 0;
}

Measured memory_bytes: 1072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
int k, n;
int arr[105];
set<int> s;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> k >> n;
	REP(i, 0, n){
		cin >> arr[i];
		s.insert(arr[i]);
	}
	pi cur = MP(1000000000, -1);
	REP(i, 0, n+2){
		if (s.find(k - i) != s.end()) continue;
		cur = min(cur, MP((ll)i, (ll)k - i));
		break;
	}
	
	REP(i, 0, n+2){
		if (s.find(k + i) != s.end()) continue;
		cur = min(cur, MP((ll)i, (ll)k + i));
		break;
	}
	cout << cur.second << endl;
}

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

#ifdef LOCAL
#include "../../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int N;
  cin >> N;
  vector<int> s(N);
  rep(i, N) cin >> s[i];
  ll ans = 0;
  for (int c = 1; c <= N; c++) {
    ll score = 0;
    set<int> used;
    for (int x = 0; x < N; x++) {
      if (N < c * x) break;
      int A = (N - 1) - c * x;
      int B = A - c;
      if (B <= 0) break;
      if (used.find(c * x) != used.end()) break;
      used.insert(c * x);
      score += s[c * x];
      if (used.find((N - 1) - c * x) != used.end()) break;
      used.insert((N - 1) - c * x);
      score += s[(N - 1) - c * x];
      ans = max(ans, score);
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 5376
#import"cstdio"
int n,m;void d(long a,int f){if(a<=n)m+=f==7,a*=10,d(a+3,f|1),d(a+5,f|2),d(a+7,f|4);}main(){scanf("%d",&n);d(0,0);printf("%d",m);}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 using namespace std;
 
 int main() 
 {
 	string s;
 	cin>>s;
 	int len = s.size()-1;
 	for(int i=0;i<len;i++)
 	{
 		if(s[i]==s[i+1])
 		{
 			cout<<i+1<<" "<<i+2<<endl;
 			return 0;
		 }
		 if(i+2<len+1)
		 {
		 	if(s[i]==s[i+2])
		 	{
		 		cout<<i+1<<" "<<i+3<<endl;
		 		return 0;
			 }
		 }
	}
	cout<<-1<<" "<<-1<<endl;
 }


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

int main () {
  int a,b,add,sub,mul,ret;
  cin >> a >> b;
  add = a + b; sub = a - b; mul = a * b;
  ret = add;
  if (b < 0)
    ret = sub;
  if (ret < mul)
    ret = mul;
  cout << ret;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
int main(void){
	int i,count[26]={0};
	char c;
	while((c=getchar()) != EOF){
		c = tolower(c);
		count[c - 'a']++;
	}
	for(i=0;i<26;i++){
		printf("%c : %d\n",'a'+i,count[i]);
	}
	return 0;
}

Measured memory_bytes: 524
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

void insert(int *,int);
void maxHeapify(int *,int);
int extractMax(int *);
void buildMaxHeap(int *,int);
void increasekey(int *,int,int);

int H=0;

int main()
{
  char c[10];
  int k,S[2000000];
 
  while(1)
    {
      scanf(" %s",c);
  
	  if(c[0] == 'i')
	    {
	      scanf("%d",&k);
	      insert(S,k);
	    }
	  else if(c[1] == 'x')
	    {
	      printf("%d\n",extractMax(S));
	    }
	  else break;
    }
  return 0;
}

void insert(int *A,int k)
{
  H++;
  A[H] = -300;
  
  increasekey(A,H,k);
  
  return;
}

void increasekey(int *A,int i,int k)
{
  int change;
  if(k < A[i]) exit(2);

  A[i] = k;

  while(i > 1 && A[i/2] < A[i])
    {
      change = A[i];
      A[i] = A[i/2];
      A[i/2] = change;

      i = i/2;
    }
  
  return;
}

void maxHeapify(int *A,int i)
{
  int l,r,largest,change;

  l = 2*i; //left
  r = 2*i+1; //right

  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;

  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i)
    {
      change = A[i];
      A[i] = A[largest];
      A[largest] = change;
      
      maxHeapify(A,largest);
    }
  
  return;
}

int extractMax(int *S)
{
  int max;
  
  if(H < 1) exit(1);

  max = S[1];
  S[1] = S[H];
  H--;
  maxHeapify(S,1);

  return max;
}



Measured memory_bytes: 5612
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define PRIME_MAX 1500000
vector<bool> prime(PRIME_MAX+1,true);
 
void init_prime(){
	prime[0] = prime[1] = false;
	for(int i=2;i*i<=PRIME_MAX;i++)
		if(prime[i]) for(int j=i*i;j<=PRIME_MAX;j+=i)prime[j] = false;
}

int main(){
	init_prime();
	
	int n;
	while(cin >> n ,n ){
		int h = 0,l = 0;
		for(int i=n;i<prime.size();i++)
			if(prime[i]){h = i;break;}	
		for(int i=n;i>=0;i--)
			if(prime[i]){l = i;break;}
		cout << h - l << endl;
	}
}	

Measured memory_bytes: 0
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = [a, b, c, d, e]
l.sort()

if l[4] - l[0] > k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
def main():
	H, W = map(int, input().split())
	S = ["-"*(W+2) for _ in range(H+2)]
	offset = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
	for i in range(1, H+1):
		S[i] = "-"+input()+"-"
	ans = [""]*H

	for i in range(1, H+1):
		for j in range(1, W+1):
			if S[i][j] != ".":
				ans[i-1] += S[i][j]
				continue
			count = 0
			for o in offset:
				if S[i+o[0]][j+o[1]] == "#":
					count += 1
			ans[i-1] += str(count)

	for i in range(H):
		print(ans[i])


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k<=a)
    {
        ans = k;
    }
    else
    {
        ans = a;
        k = k-a;
        if(k<=b)
        {
            ans = ans;
        }
        else
        {
            k = k-b;
            ans -= k;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  vchar a(4);
  for(int i=0;i<4;i++){cin>>a[i];}
  vsort(a);
  if((a[0]==a[1])&&(a[2]==a[3])&&(a[2]!=a[1])){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  //caricurate
  //output
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,a,b; cin>>n>>a>>b;
    vector<ll> h(n,0);
    rep(i,n) cin>>h[i];
    ll l=1,r=1e9,c,cnt;
    while(l!=r){
        c=(l+r)/2;
        cnt=0;
        rep(i,n){
            if(h[i]-c*b>0) cnt+=(h[i]-c*b+a-b-1)/(a-b);
        }
        if(cnt<=c) r=c;
        else l=c+1;
    }
    cout<<l<<endl;
}

Measured memory_bytes: 4052
#include<iostream>
#include<vector>

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;
    
    vector<pair<int, int>> table(N);

    int p;
    char c[2];
    for(int i=0;i<M;++i){
        cin >> p >> c;
        if(table[p-1].first == 0){
            if(c[0]=='A'){
                table[p-1].first = 1;                
            }else if(c[0]=='W'){
                ++table[p-1].second;                
            }
        }
    }

    int ac = 0 , wa = 0;
    for( const auto& p : table){
        ac += p.first;
        if(p.first == 1){
            wa += p.second;
        }
    }

    cout << ac << " " << wa << endl; 
        
    return 0;
}


Measured memory_bytes: 1024
import math

def mk(n):
    if (n == 1):
        return [[1], [1]]
    else:
        y = (n*(n-1)) // 2 + 1
        p = mk(n-1)
        for i in range(0,n):
            p[i].append(y+i)
        p.append([a+y for a in range(n)])
        return p


m = int(input())
x = math.floor(math.sqrt(2*m))
if (not x*(x+1) == 2*m):
    print("No")
else:
    print("Yes")
    print(x+1)
    p = mk(x)
    for i in range(x + 1):
        print(x," ", end="")
        for e in p[i]:
            print(e," ", end="")
        print()


Measured memory_bytes: 13160
#include <iostream>
#include <stdio.h>

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

  int h[n];
  for(int i = 0; i < n; i++) scanf("%d", &h[i]);

  bool can = true;
  for(int i = n-1; 0 < i; i--){
    if(h[i-1] <= h[i]) continue;
    else{
      h[i-1]--;
      if(h[i-1] <= h[i]) continue;
      else {
        can = false;
        break;
      }
    }
  }

  if(can == true) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int a[200010];
int cnt;
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		int t;
		scanf("%d",&t);
		if(t==0){
			int x;
			scanf("%d",&x);
			a[cnt++]=x;
		}else if(t==1){
			int x;
			scanf("%d",&x);
			printf("%d\n",a[x]);
		}else{
			cnt--;
		}
	}
}


Measured memory_bytes: 2636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
struct fenwick_tree{
  //0-indexed
  //1-indexed用のコードを0-indexedに落とし込む処理をしているため、可読性がちょっと低い

  // nは元の配列且つBITのサイズ。
  // BITでは、元の配列と同じサイズの配列で管理できる。
  ll n;
  
  // bitを格納する配列
  vector<ll> bit;
  fenwick_tree(int sz){
    n = sz;
    
    // bitをサイズn, 値を0で初期化。
    bit.assign(sz,0);
  }
  //add a-th factor w;
  void add(ll a,ll w){
    //0-indexedで入ってきたaをa+1にして、1-indexedに
    //そして各値にアクセスするときだけindexを1減らす
    for(ll i=a+1;i<=n;i+=i&-i) bit[i-1] += w;
  }
  //return sum [0,a)
  ll sum(ll a){
    ll res = 0;
    //0-indexedで入ってきたaをa+1にするが、半開区間なのでa+1-1=aになる
    for(ll i=a;i>0;i-=i&-i) res += bit[i-1];
    return res;
  }
  //return sum [a,b)
  ll sum(ll a,ll b){
    return sum(b)-sum(a);
  }
};



int main() {
            ll N,q;cin>>N>>q;
            ll A,B,C;
            fenwick_tree rsq(N+1);
            rep(i,q){
                     cin>>A>>B>>C;
                     if(A==0){
                              rsq.add(B,C);
                              }
                     else if(A==1){
                                   cout<<rsq.sum(B,C+1)<<endl;
                                   }
                     }
                     

    


}




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

int main()
{
    int temp = 0, sum = 0;
    int a[100] = {};
    int r, c;
    cin >> r >> c;
    for (int i = 0; i < r; ++i)
    {
        sum = 0;
        for (int j = 0; j < c; ++j)
        {
            cin >> temp;
            cout << (j != 0 ? " " : "") << temp;
            sum += temp;
            a[j] += temp;
        }
        cout << " " << sum << endl;
        ;
    }
    sum = 0;
    for (int j = 0; j < c; ++j)
    {
        sum += a[j];
        cout << (j != 0 ? " " : "") << a[j];
    }
    cout << " " << sum << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

struct Connection {
	vector<int>friends;
	vector<int>block;
	vector<int>friendable;
	Connection() {};
};

Connection connection[100005];
int target;

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int main() {
	
	int x[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	
	int K; 
	std::cin >> K; K--;
	int ans = x[K];
	std::cout << ans << endl;
}



Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
int p[MAXN];
int cnt[MAXN];
int get(int v) {
    return (v == p[v] ? v : p[v] = get(p[v]));
}

void un(int v, int u) {
    v = get(v), u = get(u);
    if(v == u) return;
    if(cnt[v] < cnt[u]) swap(v, u);
    cnt[v] += cnt[u];
    p[u] = v;
}

void solve() {
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) p[i] = i, cnt[i] = 1;
    while(m--) {
        int u, v;
        cin >> u >> v;
        un(u, v);
    }
    cout << *max_element(cnt + 1, cnt + n + 1);
}


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  for (int i = 0; i < 3 * N; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  long long ans = 0;
  for (int i = 0; i < N; i++) ans += a[2 * i + 1];
  cout << ans << endl;
}

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void print(T a) { cout<<a<<"\n"; }
template <typename T>
inline void print(T a, T b) { cout<<a<<" "<<b<<"\n"; }
template <typename T>
inline void print(T a, T b, T c) { cout<<a<<" "<<b<<" "<<c<<"\n"; }
template <typename T>
inline void print(T a, T b, T c, T d) { cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; }
template <typename T>
inline void printpii(pair<T, T> p) { cout<<p.first<<" "<<p.second<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

template <typename T>
inline void readV(vector<T>& a) { rep(i, 0, sz(a)) cin>>a[i]; }
template <typename T>
inline void read(T& a) { cin>>a; }
template <typename T>
inline void read(T& a, T& b) { cin>>a>>b; }
template <typename T>
inline void read(T& a, T& b, T& c) { cin>>a>>b>>c; }
template <typename T>
inline void read(T& a, T& b, T& c, T& d) { cin>>a>>b>>c>>d; }
template <typename T>
inline void readpii(pair<T, T>& p) { cin>>p.first>>p.second; }
template <typename T>
inline void readVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		readV(a[i]);
	}
}


// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

vector<ll> h;
vector<ll> dp;

ll solve(int n)
{
	if(n==1) return 0;
	if(n==2) return abs(h[2]-h[1]);
	if(dp[n]!=-1) return dp[n];
	
	ll ans=min(solve(n-2)+abs(h[n]-h[n-2]), solve(n-1)+abs(h[n]-h[n-1]));
	return dp[n]=ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n;
	cin>>n;
	h.resize(n+1);
	dp.resize(n+1);
	fill(all(dp), -1);
	for(int i=1; i<=n; i++) {
		cin>>h[i];
	}
	cout<<solve(n)<<"\n";
    return 0;
}



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

using namespace std;

int main() {
    int n;
    long long ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0)
            continue;
        if (i % 5 == 0)
            continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  INT(x); INT(y); INT(a); INT(b); INT(c); VI(ps, a); VI(qs, b); VI(rs, c);
  sort(ps.rbegin(), ps.rend());
  sort(qs.rbegin(), qs.rend());
  sort(rs.rbegin(), rs.rend());
  vector<ll> vp(a + 1, 0), vq(b + 1, 0), vr(c + 1, 0);
  vp[0] = 0; REP(i, 1, a + 1){vp[i] = vp[i - 1] + ps[i - 1];}
  vq[0] = 0; REP(i, 1, b + 1){vq[i] = vq[i - 1] + qs[i - 1];}
  vr[0] = 0; REP(i, 1, c + 1){vr[i] = vr[i - 1] + rs[i - 1];}
  ll ans = 0;
  REP(i, c + 1){
    auto score = [&](int j) -> ll{
      if (x < j || y < i - j){
        return -1;
      } else {
        return vp[x - j] + vq[y - i + j] + vr[i];
      }
    };
    int l = 0, r = i, m, n;
    ll tmp = max(score(l), score(r)), sm, sn;
    while (l + 2 < r){
      m = (2 * l + r) / 3;
      n = (l + 2 * r) / 3;
      sm = score(m); sn = score(n);
      tmp = max(tmp, max(sm, sn));
      if (sm < sn) {
        l = m;
      } else if (sm > sn) {
        r = n;
      } else {
        l = m; r = n;
      }
    }
    ans = max(ans, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3712
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)
#define cio ios::sync_with_stdio(false);

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


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


Measured memory_bytes: 256
# coding: utf-8
# Here your code !
import sys
f = sys.stdin

def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
      
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
      
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d
  
def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d
  
def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d
  
def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d
  
  
  
while True:
    n = int(f.readline())
    if n == 0:
        break
      
    dice = [1,2,3]
    result = 1
      
    for _ in range(n):
        direction = f.readline().rstrip()
        #print(direction)
        if direction == 'North':
            dice = North(dice)
        if direction == 'East':
            dice = East(dice)
        if direction == 'South':
            dice = South(dice)
        if direction == 'West':
            dice = West(dice)
        if direction == 'Right':
            dice = Right(dice)
        if direction == 'Left':
            dice = Left(dice)
        #dice = eval(direction+"(dice)")
        #print(dice)
          
        result += dice[0]
      
    print(result)

Measured memory_bytes: 7860
import heapq

n = int(input())
A = list(map(int,input().split()))

sa = 0
sb = 0
hf = []
hb = []
la = [[0]*2 for i in range(n+1)]
for i in range(n):
    sa += A[i]
    heapq.heappush(hf,A[i])
for i in range(2*n,3*n):
    sb += A[i]
    heapq.heappush(hb,-A[i])
la[0][0] = sa
la[-1][-1] = sb
for i in range(n,2*n):
    now = A[i]
    now2 = A[-1-i]
    heapq.heappush(hf,now)
    heapq.heappush(hb,-now2)
    h1 = heapq.heappop(hf)
    h2 = -heapq.heappop(hb)
    sa += now-h1
    sb += now2 -h2
    la[i-n+1][0] = sa
    la[-i+n-2][1] = sb

ans = -float("INF")
for i,j in la:
    ans = max(ans,i-j)
print(ans)


Measured memory_bytes: 38364
<?php
$n = intval(trim(fgets(STDIN)));
for($a = 1; $a <= 3500; $a++){
  for($b = 1; $b <= 3500; $b++){
    $c1 = $n * $a * $b;
    $c2 = 4*$a*$b - $n*($a+$b);
    if($c2 > 0 && $c1 % $c2 == 0){
      printf("%d %d %d\n", $a,$b,$c1/$c2);
      exit;
    }
  }
}

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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            if (n == 1) {
                out.println(1);
                return;
            }

            int mode = 0;
            int ans = 1;
            for (int i = 1; i < n; i++) {
                if (a[i] > a[i - 1]) {
                    if (mode == 2) {
                        mode = 0;
                        ans++;
                    } else {
                        mode = 1;
                    }
                } else if (a[i] < a[i - 1]) {
                    if (mode == 1) {
                        mode = 0;
                        ans++;
                    } else {
                        mode = 2;
                    }
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 34016
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int a;

void solve(){
    cin >> a;
    cout << a+a*a+a*a*a << endl;
}

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

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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

typedef long long int ll;

int main(){
	int k;
	cin >> k;
	int rm = 0;
	if(k%7==0) k/=7;
	for(int i = 1; i < 1000000; i++){
		rm = rm * 10 + 1;
		rm%=k;
		if(rm == 0){
			cout << i;
			return 0;
		}
	}
	cout << "-1";
	return 0;
}


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

#define ll long long;

pair<pair<string,int>,int> p[100];

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

  for(int i=0; i<n; ++i) {
    int t;
    cin >> s >> t;
    p[i] = make_pair(make_pair(s,-t),i);
  }
  sort(p,p+n);
  for(int i=0; i<n; i++) {
    cout << p[i].second+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3556
N = int(input())
S = input()

Wcnt = S.count('W')
Rcnt = S.count("R")

C = "R" * Rcnt + "W" * Wcnt

diff = 0
for i in range(len(S)):
    if C[i] != S[i]:
        diff += 1

ans = diff // 2
print(ans)

Measured memory_bytes: 68068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  vector<ll> a(N), b(N), c(N), d(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < N; i++)
    cin >> b[i];
  for (int i = 0; i < N; i++)
    cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < N; i++)
  {
    int num = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    d[i] = num;
  }
  for (int i = 1; i < N; i++)
    d[i] += d[i - 1];
  ll ans = 0;
  for (int i = 0; i < N; i++)
  {
    int num = lower_bound(b.begin(), b.end(), c[i]) - b.begin() - 1;
    if (num != -1)
      ans += d[num];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
int main(){
  int i,j,minj,N,count=0,v,flag;
  int data[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&data[i]);
  }

  for(i=0;i<N-1;i++){
    minj=i;
    flag=0;
    for(j=i;j<N;j++){
      if(data[j]<data[minj]){
	minj=j;
	flag=1;
      }
    }
    if(flag==1){
    v=data[i];
    data[i]=data[minj];
    data[minj]=v;
     count++;
    }
  }

  for(i=0;i<N;i++){
    printf("%d",data[i]);
    if(i!=N-1)printf(" ");
  }

  printf("\n");
  printf("%d\n",count);
  return 0;

}



Measured memory_bytes: 2072
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

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

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

    int ans = 0;
    rep(i, n) {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1) ans += 1;
    }
    print(ans);

    return 0;
}

/*
 _
| |__   ___ _ __  _ __
| '_ \ / __| '_ \| '_ \
| |_) | (__| |_) | |_) |
|_.__(_)___| .__/| .__/
           |_|   |_|
*/


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    
    int cnt[210000], A[210000];

    for (int i=0; i<210000; i++){
        cnt[i] = 0;
        A[i] = 0;
    }

    int uniq=0;
    for (int i=0; i<N; i++){
        cin >> A[i];
        if (cnt[A[i]] == 0) uniq++;
        cnt[A[i]]++;
    }

    sort(cnt, cnt+210000);

    if(uniq <= K){
        cout << 0 << endl;
    }
    else{
        int res=0, i=0, j=0;
        while(j < uniq-K){
            if (cnt[i] > 0){
                res += cnt[i];
                j++;
            }
            i++;
        }
        cout << res << endl;
    }

}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main
{
    public static void main(String[] args) 
    {
        
        boolean flag=true;
        int n_cnt,output=-1;
        int i;
        int[] n;
        n = new int[200];
        
        Scanner scan = new Scanner(System.in);

        n_cnt=scan.nextInt();
        for(i=0;i<n_cnt;i++)
        {
            n[i]=scan.nextInt();
        }

        while(flag)
        {
            output++;
            for(i=0;i<n_cnt;i++)
            {
                if(n[i]%2==0)
                {
                    n[i]/=2;
                }
                else
                {
                    flag=false;
                    break;
                }
            }
        }
        
        System.out.println(output);

    }
}

Measured memory_bytes: 21716
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[1100];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	std::sort(p,p+a);
	printf("%d\n",p[a-1]-p[0]);
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    var input = readLine()!!.split(" ")
    val width = input[0].toDouble()
    val height = input[1].toDouble()
    val x = input[2].toDouble()
    val y = input[3].toDouble()

    print((width * height / 2).toString()+ " " + (if (x == width/2 && y == height/2) 1 else 0))
}

Measured memory_bytes: 37840
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	int a[n + 1];
	int s[n + 1];
	s[0] = 0;
	repn(i, 1, n + 1){
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}
	int ans = 1e9;
	repn(i, 1, n + 1){
		ans = min(ans, abs(s[i] - (s[n] - s[i])));
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<bool>dp(101000);
	int x;
	cin>>x;
	for(int i=100;i<=105;i++) dp[i]=true;
	for(int i=100;i<100001;i++){
		if(dp[i]==true){
			dp[i+100]=true;
			dp[i+101]=true;
			dp[i+102]=true;
			dp[i+103]=true;
			dp[i+104]=true;
			dp[i+105]=true;
		}
	}
	cout<<dp[x]<<endl;
	return 0;
}


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

int main()
{
    /* ------- 宣言と入力 ------- */

    int A, B;

    cin >> A >> B;

    /* ------- 計算 ------- */

    int ans_A = ceil((double)A / 0.08);
    int ans_B = ceil((double)B / 0.1);

    int ans_max = max(ans_A, ans_B);

    double tax_max;
    int judge;

    if (ans_A > ans_B)
    {
        tax_max = 0.1;
        judge = B;
    }
    else
    {
        tax_max = 0.08;
        judge = A;
    }

    int tmp = floor((double)ans_max * tax_max);

    if (floor((double)ans_max * tax_max) == judge)
    {
        cout << max(ans_A, ans_B) << endl;
    }
    else
    {
        cout << "-1" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
Author: Vishesh Gupta
E mail: visheshguptavgr@gmail.com
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define newline ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)

#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(1);
    //start coding here

    int n;
    long long ans(0), sum(0);
    cin >> n;
    long long  arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    for (int i = 0; i < n; i++)
    {
        sum = (sum % MOD - arr[i] % MOD + MOD) % MOD;
        ans = ans + ((arr[i] % MOD) * (sum % MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans << newline;

    return 0;
}


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

int main(void){
    ll N;
    cin >> N;
    ll A[N], out[N];
    REP(i,N) out[i] = 0;
    FOR(i,1,N){
        cin >> A[i];
        out[A[i]-1]++;
    }
    REP(i,N){
        cout << out[i] << endl;
    }

}

Measured memory_bytes: 6744
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    long long n, sum=0;
    cin >> n;
    for (int i=1; i<=n; i++){
    	if (i%3==0 || i%5==0) continue;
    	else sum+=i;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;

main(){
    ll t1,t2,a1,a2,b1,b2,n,ans=0;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    ll c1=a1-b1,c2=a2-b2;
    ll d1=c1*t1;
    ll d2=c2*t2;
    if(d1>0&&d2<0){
        d2=labs(d2);
        ll f=d2-d1;
        if(f==0)cout<<"infinity";
        else if(f<0)cout<<"0";
        else if(f>0){
            if(d1%f==0)cout<<2*(d1/f);
            else if(d1%f!=0)cout<<2*(d1/f)+(ll)1;
        }
    }
    else if(d2>0&&d1<0){
        d1=labs(d1);
        ll f=d2-d1;
        if(f==0)cout<<"infinity";
        else if(f<0)cout<<"0";
        else if(f>0){
            if(d1%f==0)cout<<2*(d1/f);
            else if(d1%f!=0)cout<<2*(d1/f)+(ll)1;
        }
    }
    else cout<<"0";
}


Measured memory_bytes: 256
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
int n,k;
int ai[1234][1234];
int a,b;
void init(){
 
}

int ans;


void play(){
   
}
void pri(){
  
}

int main() {
 
    while(scanf("%d",&n)!=EOF){
        if(n<=999)printf("ABC\n");
        else printf("ABD\n");
       // init();
     //   play();
    //    pri();
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Set<Integer> st = new TreeSet<>();
		for(int i = 0; i < n; i++) st.add(in.nextInt());
		if(st.size() == n) System.out.println("YES");
		else System.out.println("NO");
	}
} 


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string S; cin >> S;
	ll cntg{0}, cntp{0};

	for (auto &e : S)
	{
		if (e == 'g') ++cntg;
		else ++cntp;
	}

	ll tmp = S.size()/2;
	if (S.size() & 1) ++tmp;
	std::cout << cntg - tmp << std::endl;
	
	return 0;
}


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

int main(){
  int N;
  cin>>N;
  map<string,int> M;
  for(int i=0;i<N;++i){
    int a;
    cin>>a;
    if(a<=399) ++M["hai"];
    else if(a<=799) ++M["tya"];
    else if(a<=1199) ++M["midori"];
    else if(a<=1599) ++M["mizu"];
    else if(a<=1999) ++M["ao"];
    else if(a<=2399) ++M["ki"];
    else if(a<=2799) ++M["daidai"];
    else if(a<=3199) ++M["aka"];
    else ++M["sugoi"];
  }

  int ans=0;
  for(auto p:M){
    if(p.first!="sugoi"){
      ++ans;
    }
  }

  cout<<max(ans,1)<<" "<<ans+M["sugoi"]<<endl;
}


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

vector<int> x, y, p;
int p3[16];

int main() {
    p3[0] = 1;
    for (int i = 1; i < 16; i++) p3[i] = p3[i - 1] * 3;

    int n;
    while (scanf("%d", &n) == 1) {
        x.assign(n, 0);
        y.assign(n, 0);
        p.assign(n, 0);

        for (int i = 0; i < n; i++) scanf("%d %d %d", &x[i], &y[i], &p[i]);

        vector<int> lr(n), du(n);
        for (int i = 0; i < n; i++) lr[i] = i, du[i] = i;
        sort(lr.begin(), lr.end(), [](const int &i, const int &j) -> bool { return x[i] == x[j] ? y[i] < y[j] : x[i] < x[j]; });
        sort(du.begin(), du.end(), [](const int &i, const int &j) -> bool { return y[i] == y[j] ? x[i] < x[j] : y[i] < y[j]; });

        vector<long long> res(n + 1, 1e18);
        vector<int> vm(n);
        vector<int> _closest(n);
        for (int i = 0; i < n; i++) _closest[i] = min(abs(x[i]), abs(y[i]));
        for (int m = 0; m < p3[n]; m++) {
            int tm = m;
            for (int i = 0; i < n; i++) {
                vm[i] = tm % 3;
                tm /= 3;
            }

            int nonZero = 0;
            for (auto &x : vm) nonZero += x != 0;

            vector<int> closest = _closest;
            int l = -1e9;
            for (int i = 0; i < n; i++)  {
                int id = lr[i];
                if (vm[id] == 1) l = x[id];
                closest[id] = min(x[id] - l, closest[id]);
            }

            int d = -1e9;
            for (int i = 0; i < n; i++)  {
                int id = du[i];
                if (vm[id] == 2) d = y[id];
                closest[id] = min(y[id] - d, closest[id]);
            }

            int r = 1e9;
            for (int i = n - 1; i >= 0; i--)  {
                int id = lr[i];
                if (vm[id] == 1) r = x[id];
                closest[id] = min(r - x[id], closest[id]);
            }

            int u = 1e9;
            for (int i = n - 1; i >= 0; i--)  {
                int id = du[i];
                if (vm[id] == 2) u = y[id];
                closest[id] = min(u - y[id], closest[id]);
            }

            long long tres = 0;
            for (int i = 0; i < n; i++) tres += 1ll * closest[i] * p[i];
            res[nonZero] = min(res[nonZero], tres);
        }

        for (auto &x : res) printf("%lld\n", x);
    }
}



Measured memory_bytes: 3800
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
for i in range(n-1):
    if a[i+1] - a[i] == 1:
        ans += c[a[i]-1]

print(ans)


Measured memory_bytes: 3060