akhauriyash/Code-Regression huggingface dataset:
// Comment
// complement

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e3 + 10;

int N, M, Ed[MAX_N][MAX_N];
int Vis[MAX_N];
bool IsCan = true;
vector<int> Temp;

void dfs(int v) {
	Temp.push_back(v);
	for(int w=1; w<=N; w++) if(Ed[v][w]) {
		if(Vis[w] >= 1) {
			if(Vis[w] == Vis[v]) {
				puts("-1");
				exit(0);
			}
		}else{
			Vis[w] = 3 - Vis[v];
			dfs(w);
		}
	}
}

int Dy[MAX_N];
int main() {
	cin >> N >> M;
	for(int i=0; i<M; i++) {
		int x, y; scanf("%d%d", &x, &y);
		Ed[x][y] = Ed[y][x] = 1;
	}
	for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) if(i != j) {
		Ed[i][j] = 1 - Ed[i][j];
	}

	Dy[0] = Dy[N] = 1;
	int ix = 1;
	for(int i=1; i<=N; i++) if(Vis[i] == 0) {
		Vis[i] = 1;
		dfs(i);
		vector<int> cnt(2, 0);
		for(int x: Temp) {
			cnt[Vis[x]-1]++;
		}
		Temp.clear();

		ix++;
		for(int k=N; k>=0; k--) {
			for(int x: cnt) if(k+x <= N && Dy[k] >= ix-1) {
				Dy[k+x] = ix;
			}
		}
	}

	int ans = INF;
	for(int i=1; i<N; i++) if(Dy[i] == ix) {
		ans = min(ans, i * (i-1) / 2 + (N-i) * (N-i-1) / 2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6532
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;

int main(void)
{
    cout << std::fixed << std::setprecision(10);
    std::string s;
    std::string t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        s.insert(s.begin(),s[s.size()-1]);
        s.pop_back();
        if(s==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

vector<int> v;
ll fact[100001];

ll power(ll a, ll b)
{
  if (b == 1)
    return a;
  
  else if(b%2 == 0)
  {
    ll temp = power(a, b/2);
    return (temp*temp)%mod;
  }
  else
  {
    return (power(a,b-1) * a) % mod;
  }
}

ll inv(int a)
{
  return power(a, mod-2);
}

ll comb(int n, int k)
{
  return (fact[n] * inv((fact[k] * fact[n-k])%mod) % mod);
}

int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  
  fact[0] = 1;
  for(int i = 1; i <= 100000; i++)
  {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
  }
 
  
  for(int i = 0; i < n; i++)
  {
    int num;
    scanf("%d", &num);
    v.push_back(num);
  }
  
  sort(v.begin(), v.end());
  
  ll res = 0;
  
  for(int i = 0; i < n-k+1; i++)
  {
    ll dif = v[n-1-i]-v[i];
    //printf("%daa\n", dif%mod);
    ll temp;
    res += ((v[n-1-i] - v[i]) * comb(n-1-i, k-1)) % mod;
    res %= mod;
  }
  
  //printf("%lldcomb\n", comb(1,1));
  
  if(res < 0)
    res += mod;

  printf("%lld\n", res);
  
  return 0;
}


Measured memory_bytes: 1788
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X = [int(x) for x in input().split()]

    for i, v in enumerate(X):
        if i + 1 != v:
            print(i + 1)

    
    

if __name__ == '__main__':
    main()



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


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

    int ans = 0;
    rep(i,N) for (int j = i + 1; j < N; ++j) for (int k = j + 1; k < N; ++k) {
        if (L[i] < L[j] + L[k] && L[j] < L[k] + L[i] && L[k] < L[i] + L[j]
        && L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int a, b; cin >> a >> b;
    int ans = 0;
    if (a >= 13) ans = b;
    else if (a >= 6 && a <= 12) ans = b / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,t,ans;cin>>a>>b>>t;
  if(a==t){
    ans=b;
  }else if(a>t){
    ans=0;
  }else{
    ans=(t/a)*b;
  }
  cout<<ans;
}

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
  ll a,b,v,w,t;cin>>a>>v>>b>>w>>t; 
  if(v>w)
   {
      if(((v-w)*t)>=abs(b-a)){cout<<"YES\n";return;}
   }
  cout<<"NO\n";
  
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


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

int N, cnt;

void dfs(int depth, int val, bool has7, bool has5, bool has3) {
  if (val > 0 && has7 && has5 && has3 && val <= N) cnt++;
  if (depth < 9) {
    dfs(depth+1, val*10+7, true, has5, has3);
    dfs(depth+1, val*10+5, has7, true, has3);
    dfs(depth+1, val*10+3, has7, has5, true);
  }
}

int main() {
  cin >> N;
  cnt = 0;
  dfs(0, 0, false, false, false);
  cout<<cnt<<endl;
}

Measured memory_bytes: 3608
n = int(input())

import math

ans = float('inf')
def calc(x,cnt):
    if x<6:
        global ans
        ans = min(ans,x+cnt)
    else:
        c = 6**int(math.log(x,6))
        if c*6==x:c*=6
        calc(x-c,cnt+1)
        c = 9**int(math.log(x,9))
        if c*9==x:c*=9
        calc(x-c,cnt+1)

calc(n,0)

print(ans)


Measured memory_bytes: 48856
#include <iostream>
#include <vector>
using namespace std;
 
int main(void) {
  
  int N, M;
  cin >> N >> M;    //スヌケ君:N, お菓子の種類：M
  
  int sum[N];
  for(int i=0; i<N; i++){
      sum[i] = 0;
  }
  
  for(int i=0; i<M; i++){
    int d;
    cin >> d;
    
    for(int j=0; j<d; j++){
      int x;
      cin >> x;
      sum[x-1] ++;
    }  
  }
  
  int count = 0;
  
  for (int i=0; i<N; i++) {
    if (sum[i] == 0){
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3140
gets.chomp.to_i
array = gets.chomp.split(' ').map(&:to_i)

count = 0

def array_is_even?(array)
  detect = array.map(&:even?)
  detect.include?(false) ? false : true
end

def array_divide(array)
  array.map! { |n| n / 2 }
end

while array_is_even?(array)
  array_divide(array)
  count += 1
end

puts count

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

int main(){
	double w, h, x, y;

	cin >> w >> h >> x >> y;
	
	cout << setprecision(99)<< w * h / 2.0 << " ";
	cout << ((x == w / 2 && y == h / 2) ? "1" : "0") << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
#include <iomanip>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}


ll modpow(ll a,ll p){
    if(p==0) return 1;
    if(p%2==0){
        ll halfp = p/2;
        ll half = modpow(a,halfp);
        return half * half % MOD;
    }else{
        return a * modpow(a,p-1) % MOD;
    }
}

ll calcComb(ll a,ll b){
    if (b > a-b){
        return calcComb(a,a-b);
    }
    ll ansMul = 1;
    ll ansDiv = 1;
    REP(i,b){
        ansMul *= (a - i);
        ansDiv *= (i + 1);
        ansMul %= MOD;
        ansDiv %= MOD;
    }
    ll ans = ansMul * modpow(ansDiv,MOD-2) ;
    ans %= MOD;
    return ans;
}

int main ()
{
    int A,B;cin>>A>>B;
    vector<int> a(3);
    a[0] = A + B;
    a[1] = A - B;
    a[2] = A * B;
    cout<<*max_element(ALL(a))<<endl;
  return 0;
}

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

int main() {
  int A, B, total = 0;

  cin >> A >> B;
  
  for (int i = A ; i <= B; i++) {
    int d1, d2, d3, d4, d5;
    d1 = i / 10000;
    d2 = (i / 1000) % 10;
    d3 = (i / 100) % 10;
    d4 = (i / 10) % 10;
    d5 = i % 10;
    
    if (d1 == d5 && d2 == d4) total++;
  }
  
  cout << total << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = []
count = 0; pro = 1

n=int(input())
if n==0:
    print(0)
    exit()
while n!=1:
    # count+=1
    # if count>=10:
    #     exit()
    # print(n,count)
    if n<0:
        if n%2==1:
            n=-(n-1)//2
            ans.append(1)
        else:
            n=-(n//2)
            ans.append(0)
    else:
        ans.append(n%2)
        n=-(n//2)
ans.append(1)
ans.reverse()
print(*ans,sep="")
        


Measured memory_bytes: 38588
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> H >> W >> N;
	vector<pair<int,int>>p(N + 1);
	vector<long long int>by(H + W + 1, 1);
	vector<long long int>rev(H + W + 1, 1);
	for (int i = 2; i <= H + W; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
		rev[i] = power(by[i], MOD - 2, MOD);
	}
	vector<vector<long long int>>dp(N + 2, vector<long long int>(2));
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		cin >> p[i].first >> p[i].second;
		p[i].first--;
		p[i].second--;
	}
	sort(p.begin(), p.end());
	p.push_back({ H - 1,W - 1 });
	for (int i = 1; i <= N + 1; i++) {
		for (int j = 0; j < i; j++) {
			if (p[i].first >= p[j].first&&p[i].second >= p[j].second) {
				long long int add = by[p[i].first - p[j].first + p[i].second - p[j].second];
				add *= rev[p[i].first - p[j].first];
				add %= MOD;
				add *= rev[p[i].second - p[j].second];
				add %= MOD;
				dp[i][0] += dp[j][1] * add;
				dp[i][0] %= MOD;
				dp[i][1] += dp[j][0] * add;
				dp[i][1] %= MOD;
			}
		}
	}
	cout << (dp.back()[1] + MOD - dp.back()[0]) % MOD << endl;
}

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

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

	vector<int> L;
	int total = 0;
	int max_l = 0;
	for (int i = 0; i < N; i++) {
		int l;
		cin >> l;
		total += l;
		max_l = max(max_l, l);
		L.push_back(l);
	}

	if (max_l < total - max_l) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}





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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===



template <typename T>
class UnionFind
{
private:
	vector<T> par;
	vector<T> rank;

public:
	UnionFind(T N) : par(N), rank(N)
	{
		for (T i = 0; i < N; ++i) par[i] = i;
	}

	T root(T x)
	{
		return par[x] == x ? x : par[x] = root(par[x]);
	}

	bool same(T x, T y)
	{
		return root(x) == root(y);
	}

	void unite(T x, T y)
	{
		x = root(x);
		y = root(y);
		if (x == y) return;

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





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

	UnionFind<int> uf(N + M);

	for (int i = 0; i < N; ++i) {
		int K;
		cin >> K;
		for (int j = 0; j < K; ++j) {
			int L;
			cin >> L;
			--L;
			uf.unite(i, L + N);
		}
	}

	int root = uf.root(0);
	bool is_ok = true;
	for (int i = 1; i < N; ++i) {
		if (root != uf.root(i)) {
			is_ok = false;
			break;
		}
	}

	cout << (is_ok == true ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 1792
class HeapQ {
  constructor( comp = (a,b)=>a>b ) {
    this.a = [];
    this.comp = comp;
  }
  get size(){ return this.a.length; }
  push( v ) {
    const {a,comp} = this;
    let i = a.push(v)-1, j = i;
    while ( i = j ) {
      j = (i-1)>>1;
      if ( comp( a[i], a[j]) ) [a[i],a[j]] = [a[j],a[i]];
      else break;
    }
  }
  pop(){
    const {a,comp} = this, N = a.length-1;
    const out = a[0];
    if ( N === 0 ) return a.pop();
    a[0] = a.pop();
    let i = 0, j;
    while ( (j=i+i+1) < N ) {
      if ( j+1 < N && comp(a[j+1], a[j]) ) j++;
      if ( comp(a[j], a[i]) ) [a[i],a[j]] = [a[j],a[i]];
      i = j;
    }
    return out;
  }
}

console.log((args=>{
  const [[N,M],A] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  const q = new HeapQ();
  for ( let i = 0; i < N; i++ ) q.push(A[i]);
  for ( let i = 0; i < M; i++ ) {
    let c = Math.floor( q.pop() / 2 );
    q.push(c);
  }
  return q.a.reduce((a,b)=>a+b,0);
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 57776
from math import sqrt
from collections import defaultdict
from itertools import product
import sys

n = int(input())
h = defaultdict(int)
def factorization(arg):
    while arg % 2 == 0:
        h[2] += 1
        arg //= 2
    for i in range(3, int(sqrt(arg)) + 1, 2):
        while arg % i == 0:
            h[i] += 1
            arg //= i
    if arg > 1:
        h[arg] += 1
if n == 1:
    print(1)
else:
    m = 10 ** 9 + 7
    for i in range(1, n + 1):
        factorization(i)
    cnt = 1
    for key, v in h.items():
        cnt *= (v + 1)
        cnt %= m
    print(cnt)

Measured memory_bytes: 3316
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);

void solve() {
    int n;cin>>n;
    string s;cin>>s;
    int r[n];int g[n];int b[n];
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            r[i]=s[i]=='R';
            g[i]=s[i]=='G';
            b[i]=s[i]=='B';
        } else{
            r[i]=r[i+1]+(s[i]=='R');
            g[i]=g[i+1]+(s[i]=='G');
            b[i]=b[i+1]+(s[i]=='B');
        }
    }
    int ans=0;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]!=s[j]){
                char diff=('R'+'G'+'B'-s[i]-s[j]);
                if(diff=='R'){
                    ans+=r[j];
                    int length=j-i;
                    int temp=j+length;
                    if(temp<n && s[temp]==diff){
                        ans--;
                    }
                }
                if(diff=='G'){
                    ans+=g[j];
                    int length=j-i;
                    int temp=j+length;
                    if(temp<n && s[temp]==diff){
                        ans--;
                    }
                }
                if(diff=='B'){
                    ans+=b[j];
                    int length=j-i;
                    int temp=j+length;
                    if(temp<n && s[temp]==diff){
                        ans--;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;

}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for (int i = 1; i <= test; i++) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

Measured memory_bytes: 3716
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,i,u,v,M[MAX][MAX];

void dij(void);

int main(){
  int j,k,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dij();
  return 0;
}

void dij(void){
  int minv;
  int d[MAX],color[MAX];
for(i=0;i<n;i++){
  d[i]=INFTY;
  color[i]=WHITE;
  }
d[0]=0;
color[0]=GRAY;
while(1){
  minv=INFTY;
  u=-1;
  for(i=0;i<n;i++){
    if(minv>d[i]&&color[i]!=BLACK){
      u=i;
      minv=d[i];
    }
  }
  if(u==-1)break;
  color[u]=BLACK;
  for(v=0;v<n;v++){
    if(color[v]!=BLACK&&M[u][v]!=INFTY){
      if(d[v]>d[u]+M[u][v]){
        d[v]=d[u]+M[u][v];
        color[v]=GRAY;
      }
    }
  }
}
for(i=0;i<n;i++){
  printf("%d %d\n",i,d[i]==INFTY?-1:d[i]);
}
}

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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> mat;

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

int n;
vi w;

void solve() {
  cin >> n;
  w.resize(n);
  int sum = 0;
  rep(i, 0, n) {
    cin >> w[i];
    sum += w[i];
  }

  int ans = INF, s1 = 0;
  rep(i, 0, n) {
    s1 += w[i];
    int s2 = sum - s1;
    chmin(ans, abs(s1 - s2));
  }
  cout << ans << endl;
}

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

  // cout << fixed << setprecision(10);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

vvi v;
vb used;
int check(){
    int ret=1;
    for(auto x:used){
        if(!x)ret=0;
    }
    return ret;
}
int ans=0;
void dfs(int now,int par){
    used[now]=true;
    bool last=true;
    for(auto x:v[now]){
        if(x==par)continue;
        if(used[x])continue;
        last=false;
        dfs(x,now);
    }
    if(last)ans+=check();
    used[now]=false;
}

int main(){
    int n,m;
    cin>>n>>m;
    v.resize(n);
    used.resize(n,false);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0,-1);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string s, t;

int main() {
    cin >> s;
    t = "CODEFESTIVAL2016";
    int ans = 0;
    forn(i, t.length()) {
         ans += s[i] != t[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define F first
        #define S second
        using ll = long long;
        const ll mod = 1000000007;
        const ll infi = 1000000000000000;
        const ll md = 998244353;
        using namespace std;
        using vl = vector<ll>;
        using pll =  pair<ll,ll>;
        
       
        void solve(int n,int k,string s){
           
        }
        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            int n,k,n1,k1;cin>>n>>k>>n1>>k1;
            //for(int i=0;i<n;i++) solve();
            if(k1==1) cout<<1;
            else cout<<0;
            return 0;
        } 

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		Main instance = new Main();
		sc = instance.new Scanner();
		instance.solve();
	}

	private void solve() {
		try {
            int a,b,c;
            a = sc.nextInt();
            b = sc.nextInt();
			c = sc.nextInt();
			if(c > a + b){
				System.out.println("No");
			}else{
				System.out.println("Yes");
			}
        } catch (Exception e) {
            e.printStackTrace();
        }
	}

	private class Scanner {
		String[] s;
		int i;
		BufferedReader br;
		String regex = " ";

		public Scanner() {
			s = new String[0];
			i = 0;
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		@Override
		protected void finalize() throws Throwable {
			try {
				super.finalize();
			} finally {
				destruction();
			}
		}

		private void destruction() throws IOException {
			if (br != null)
				br.close();
		}

		public String next() throws IOException {
			if (i < s.length)
				return s[i++];
			String st = br.readLine();
			while (st == "")
				st = br.readLine();
			s = st.split(regex, 0);
			i = 0;
			return s[i++];
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public Long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public Double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 21076
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	int c = 0;

	for (int i = 0; ; i++)
	{
		c += 1;
		if (c >= b)
		{
			cout << i << endl;
			break;
		}
		c += a - 2;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int tmp = n % 10;
	if(tmp==2||tmp==4||tmp==5||tmp==7||tmp==9) puts("hon");
	if(tmp==0||tmp==1||tmp==6||tmp==8) puts("pon");
	if(tmp==3) puts("bon");
	return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**18
 
n = int(input())
a = [int(item) for item in input().split()]
 
 
# dp[i-th][wait num][used / not used]
dp = [[[-INF] * 2 for _ in range(3)] for _ in range(n+1)]
dp[0][0][0] = 0
 
for i in range(n):
    # use in i
    for j in range(3):
        dp[i+1][j][1] = max(dp[i+1][j][1] ,dp[i][j][0] + a[i])
    # rest in i
    for j in range(2):
        dp[i+1][j+1][0] = max(dp[i+1][j+1][0] ,dp[i][j][0])
    # not use in i
    for j in range(3):
        dp[i+1][j][0] = max(dp[i][j][1], dp[i+1][j][0])
 
ans = -INF
if n % 2 == 0:
    ans = max(dp[-1][1][1], ans)
    ans = max(dp[-1][0][0], ans)
else:
    ans = max(dp[-1][2][1], ans)
    ans = max(dp[-1][1][0], ans)
print(ans)

Measured memory_bytes: 162548
import sys

def sieve(n):
    is_prime = [True] * (n + 1)
    prime_list = []
    
    is_prime[0] = is_prime[1] = False
    prime_list.append(2)
    
    for i in range(3, n + 1, 2):
        if is_prime[i]: prime_list.append(i)
        for j in range(i * i, n + 1, i):
            is_prime[j] = False
    return prime_list
    
primes = sieve(40000)

def factoriaztion(n):
    ret = []
    for prime in primes:
        cc = 0
        while n % prime == 0:
            cc += 1
            n /= prime
        if cc != 0: ret.append((prime, cc))
        if n == 1: break
    if n > 1: ret.append((n, 1))
    return ret
    
    
if __name__ == '__main__':
    n = sys.stdin.readline()
    n = int(n)
    factors = factoriaztion(n)
    
    ans = reduce(lambda acc, (x, m) : acc * (x ** m - x ** (m - 1)), factors, 1)
    
    sys.stdout.write(str(ans) + '\n')
    
        

Measured memory_bytes: 5556
n = int(input())
a = list(map(int ,input().split()))
b = list(map(int ,input().split()))
c = list(map(int ,input().split()))
ans = b[a[0]-1]
for i in range(1,n) :
    ans += b[a[i]-1]
    #print(ans)
    if a[i] - a[i-1] == 1 :
        ans += c[a[i-1]-1]
        #print(ans)
print(ans)


Measured memory_bytes: 3064
#coding=utf-8

def solve(N, K):
    count = 0
    if K == 0:
        return N * N
    for b in range(K + 1, N + 1):
        p = N // b
        r = N % b
        count += p * (b - K)
        if r >= K:
            count += r - K + 1
    return count

def main():
    A, B = input().split(' ')
    print(solve(int(A), int(B)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
import sys
import itertools
n, m, x = map(int, input().split())
C = [0] * n
A = [[0] * m for i in range(n)]

mlist = [0] * m
for i in range(n):
    books = list(map(int, input().split()))
    C[i] = books[0]
    for j in range(m):
        A[i][j] = books[j + 1]

mincost = sys.maxsize
for i in range(2**n):
    sumlist = [0] * m
    currentcost = 0
    for j in range(n):
        if ((i >> j) % 2) == 1:
            for k in range(m):
                sumlist[k] += A[j][k]
            currentcost += C[j]
    if min(sumlist) >= x:
        if currentcost < mincost:
            mincost = currentcost

if mincost == sys.maxsize:
    print("-1")
else:
    print(mincost)


Measured memory_bytes: 9188
#!/usr/bin/env python3
import sys, os
range = xrange

def main():
    inp = [int(x) for x in os.read(0, os.fstat(0).st_size).split()]
    n, m = inp[0],inp[1]

    w, v = inp[2::2], inp[3::2]

    dp = [0] * (m + 1)
    for j in range(w[0], m + 1):
        dp[j] = v[0]

    for i in range(n - 1):
        vi = v[i + 1]
        wi = w[i + 1]
        for j in reversed(range(wi, m + 1)):
            dp[j] = max(vi + dp[j - wi], dp[j])

    print(dp[-1])
main()

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

const int NMAX = 100000;

struct edge{  
  int cost;
  int to;
  int from;
};

bool operator> (const edge &e1, const edge &e2) {  
  return e1.cost > e2.cost; 
}
bool operator< (const edge &e1, const edge &e2) {  
  return e1.cost < e2.cost; 
}

int N;
vector<pair<int, int>> px, py;
priority_queue<edge, vector<edge>, greater<edge>> pq;
long long ans = 0;

class UnionFind {  
public:
  vector<long long> par;
  vector<long long> rank;
 
  UnionFind(long long N) : par(N + 1), rank(N + 1){
    for(int i = 0; i < N; i++){  
      par[i] = i;
      rank[i] = 1;
    }
  }
 
  long long root(long long x){  
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
 
  long long size(long long x){  
    return rank[root(x)]; 
  }
 
  void unite(long long x, long long y){  
    long long rx = root(x); 
    long long ry = root(y);
    if (rx == ry) return;
 
    if(rank[rx] < rank[ry]){  
      par[rx] = ry; 
    } else{  
      par[ry] = rx;
      if(rank[rx] == rank[ry]) rank[rx]++; 
    }
  }
 
  bool same(long long x, long long y){  
    return root(x) == root(y); 
  }
};


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  cin >> N;
  UnionFind uf(N);
  for(int i = 0; i < N; i++){  
    int x, y;
    cin >> x >> y;
    px.push_back(make_pair(x, i));
    py.push_back(make_pair(y, i));
  }
  sort(px.begin(), px.end());
  sort(py.begin(), py.end());
  for(int i = 0; i < N-1; i++){  
    edge x = {px[i+1].first - px[i].first, px[i].second, px[i+1].second};
    edge y = {py[i+1].first - py[i].first, py[i].second, py[i+1].second};
    pq.push(x);
    pq.push(y);
  }
  for(int i = 0; i < 2 * (N - 1); i++){  
    edge e = pq.top(); 
    pq.pop();
    if(!uf.same(e.to, e.from)){  
      ans += e.cost;
      uf.unite(e.to, e.from);
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 10124
# abc145_a.py
# https://atcoder.jp/contests/abc145/tasks/abc145_a

# A - Circle /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 整数 rが与えられます。
# 半径 rの円の面積が半径 1の円の面積の何倍になるかを求めてください。
# なお答えは制約の下では必ず整数になることが示せます。

# 制約
#     1≤r≤100
#     入力中のすべての値は整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# r

# 出力

# 半径 rの円の面積が半径 1の円の面積の何倍になるかを整数で出力せよ。

# 入力例 1
# 2

# 出力例 1
# 4

# 半径 2の円の面積は半径 1 の円の面積の 4倍です。
# 4.0 などの形式で出力すると不正解になることに注意してください。

# 入力例 2
# 100

# 出力例 2
# 10000


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    r = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = r**2

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2']
        lines_export = [4]
    if pattern == 2:
        lines_input = ['100']
        lines_export = [10000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

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

    bool ok = true;

    if(A[0] != 0){
    	ok = false;
    }

    REP(i, N-1){
    	if(A[i+1]-A[i]>1) ok = false;
    }

    if(ok){
	    ll res = 0;
	    for(int i=N-1;i>=0;i--){
	    	int j=i;
	    	while(j>=0 && A[j] == A[i] - (i-j)){
	    		j--;
	    	}
	    	res += A[i];
	    	//dump(i)
	    	//dump(i-j)
	    	i=j+1;
	    }
	    cout << res << endl;
	}else{
		cout << -1 << endl;
	}
    return 0;
}

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

int main()
{
    int n, m;

    cin >> n >> m;

    int target[m], game[m][n], point[n];
    for( int i = 0; i < m; i++ )
        cin >> target[i];
    
    for( int i = 0; i < n; i++ )
        point[i] = 0;

    for( int i = 0; i < m; i++ )
        for( int j = 0; j < n; j++ )
        {
            cin >> game[i][j];
            if( target[i] == game[i][j] )
                point[j]++;
            else
                point[target[i]-1]++;
        }

    for( int i = 0; i < n; i++ )
        cout << point[i] << endl;

    return 0;
}


Measured memory_bytes: 3120
n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]

h_sorted = sorted(h,reverse=True)
min_diff = 10**10

for i in range(len(h)-k+1):
  diff = h_sorted[i] - h_sorted[i+k-1]
  if min_diff > diff:
    min_diff = diff  

print(min_diff)    

Measured memory_bytes: 8280
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i,j,H,W;cin>>H>>W;
	vector<string>sts(H);
	vector<bool>kie(W,true);
	for(i=0;i<H;i++){
		cin>>sts[i];
		for(j=0;j<W;j++){
			if(sts[i][j]=='#'){kie[j]=0;}
		}
	}
	for(i=0;i<H;i++){
		if(sts[i]==string(W,'.')){continue;}
		for(j=0;j<W;j++){
			if(!kie[j]){cout<<sts[i][j];}
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, b, r;
  cin >> n >> b >> r;
  ll ans = n / (b + r) * b + min(b, n % (b + r));
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
    int x;
    cin >> x;
    int result = x / 500;             // Amounnt of coins to * 1000 rewards
    int remaining = x % 500;          // Number remaining
    int littleCoins = remaining / 5;  // Get the amount we can with 5 rewards
    cout << result * 1000 + (littleCoins * 5);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[[0 for i in range(10)]for s in range(10)]
for  i in range(n+1):
  if i%10:
    l[int(str(i)[0])-1][int(str(i)[-1])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    ans+=l[i][j]*l[j][i]
print(ans)


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int cnt[MAXN];

void solve(){
	int n, a;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%d", &cnt[i]);
	}
	ll ans = 0;
	REP(i, 0, n){
		int d = cnt[i] / 2;
		ans += d;
		cnt[i] -= d * 2;
		d = min(cnt[i], cnt[i + 1]);
		cnt[i] -= d;
		cnt[i + 1] -= d;
		ans += d;
	}
	printf("%lld\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

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

left = 0
right = 0
right_max = N                                           # 右端の上限値 (配列の index の上限は N-1 だが、半開区間なので右端の上限は N)
total = 0
xtotal = 0
res = 0
for left in range(right_max):
    while right < right_max and total + A[right] == total ^ A[right]:
        total += A[right]
        xtotal ^= A[right]
        right += 1
    res += right - left
    if right == left:
        right += 1
    else:
        total -= A[left]
        xtotal = A[left]^xtotal
print(res)

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

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

int main() { 
    long long X, K, D;
    cin >> X >> K >> D;

    if (abs(X) / D != 0) {
        if ((abs(X) / D) <= K) {
            K = K - (abs(X) / D); // 一番絶対値に近いところにまず行く
            X = abs(X) - D * (abs(X) / D);
        } else {
            X = abs(abs(X) - D * K);
            K = 0;
        }
    }
    // cout << X << ":" << K << ":" << D << endl;

    
    
    if (K % 2 == 0){
        cout << abs(X) << endl;
        return 0;
    } else {
        cout << abs(X - D) << endl;
        return 0;
    }
    

    // if (D == abs(X)) {
    //     if (K % 2 == 0){
    //         // Kが偶数
    //         cout << abs(X) << endl;
    //         return 0;
    //     } else {
    //         // Kが奇数
    //         cout << 0 << endl;
    //         return 0;
    //     } 
    // } else if (D < abs(X)) {
    //     if (K % 2 == 0){
    //         // Kが偶数
    //         cout << abs(abs(X) - D*2) << endl;
    //         return 0;
    //     } else {
    //         // Kが奇数
    //         cout << abs(abs(X) - D) << endl;
    //         return 0;
    //     } 
    // } else if (D > abs(X) and D < abs(X)*2) {
    //     if (K % 2 == 0){
    //         // Kが偶数
    //         cout << abs(X) << endl;
    //         return 0;
    //     } else {
    //         // Kが奇数
    //         cout << abs(abs(X) - abs(D)) << endl;
    //         return 0;
    //     }
    // } else if (D == abs(X)*2){
    //     cout << abs(X) << endl;
    //     return 0;
    // }else {
    //     // D が　abs(X)の２倍以上の時
    //     if (K % 2 == 0){
    //         // Kが偶数
    //         cout << abs(X) << endl;
    //         return 0;
    //     } else {
    //         // Kが奇数
    //         cout << D << endl;
    //         return 0;
    //     }
    // }
    

    

    return 0;
}


Measured memory_bytes: 3532
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")


int n,now;
vvi G;
vi in,out;
void dfs(int a,int p){
  rep(i,G[a].size())if(G[a][i]-p)
    dfs(G[a][i],a);
  out[a]=in[now++];
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

  cin>>n;
  G=vvi(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  in=out=vi(n);
  rep(i,n)cin>>in[i];
  sort(all(in));
  
  dfs(0,-1);
  int sum=0;
  rep(i,n-1)sum+=in[i];
  cout<<sum<<endl;
  rep(i,n)cout<<out[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 1536