akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

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

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  int n,m;
  cin>>n>>m;
  vector<priority_queue<pii, vector<pii>, greater<pii>>> v(n);
  for(int i=0;i<m;i++){
    int p,y; cin>>p>>y;
    p--;
    v[p].emplace(y,i);
  }
  vector<string> ans(m);
  for(int i=0;i<n;i++){
    
    string ppre="";
    if(99999<i+1) {}
    else if(9999 <i+1) ppre="0";
    else if(999  <i+1) ppre="00";
    else if(99   <i+1) ppre="000";
    else if(9    <i+1) ppre="0000";
    else ppre="00000";
    ppre += to_string(i+1);
    
    auto que = v[i];
    int cnt=1;
    while(!que.empty()){
      auto e = que.top();
      que.pop();
      string ypre="";
      if(99999<cnt) {}
      else if(9999 <cnt) ypre="0";
      else if(999  <cnt) ypre="00";
      else if(99   <cnt) ypre="000";
      else if(9    <cnt) ypre="0000";
      else ypre="00000";
      string res = ppre+ypre+to_string(cnt);
      ans[e.second] = res;
      cnt++;
    }
  }
  rep(i,m){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 13184
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int b, f, r, v, n, x[][][], i, j = 0, k;
		Scanner sc = new Scanner(System.in);
		x = new int[5][4][11];
		
		for(j = 0; j < 4; j++){
			for(i = 0; i < 3; i++){
				for(k = 0; k < 10; k++){
					x[j][j][k] = 0;
				}
			}
		}
				
		n = sc.nextInt();
		
		for(i = 0; n > i; i++){
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
			x[b - 1][f - 1][r - 1] += v;
			}
		
		for(j = 0; j < 4; j++){
			for(i = 0; i < 3; i++){
				for(k = 0; k < 10; k++){
					System.out.print(" " + x[j][i][k]);
				}
				System.out.print("\n");
			}
			if(j != 3)
				System.out.println("####################");
		}
	}	
}

Measured memory_bytes: 29816
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
	
	int n;
	
	while(cin>>n){
		int s[11]={0};
		int j=0;
	for(int i=9;i>=0;i--){
		if(n-pow(2,i)>=0){
		n=n-pow(2,i);
		s[j++]=pow(2,i);
	}
	}
		if(j>0){
		cout<<s[--j];
	for(int i=j-1;i>=0;i--)
		cout<<" "<<s[i];
		cout<<endl;
	}
	}
}

Measured memory_bytes: 1200
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,tot,ans,head[100010],to[100010],nxt[100010],d[100010];
void add_edge(int u,int v){
	nxt[++tot]=head[u];
	to[tot]=v;
	head[u]=tot;
	return;
}
void dfs(int u,int f){
	d[u]=1;
	for(int i=head[u];~i;i=nxt[i]){
		int v=to[i];
		dfs(v,u);
		d[u]=max(d[u],d[v]+1);
	}
	if(d[u]>=k){
		d[u]=0;
		if(f!=1)
			ans++;
	}
	return;
}
int main(){
	memset(head,-1,sizeof(head));
	scanf("%d%d%d",&n,&k,&ans);
	ans=ans!=1;
	for(int i=2;i<=n;i++){
		int v;
		scanf("%d",&v);
		add_edge(v,i);
	}
	for(int i=head[1];~i;i=nxt[i])
		dfs(to[i],1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>

using namespace std;

void print_tree(int *xs, int n){
    for(int i = 0; i < n; ++i){
        printf("node %d: ", (i+1));
        printf("key = %d, ", xs[i]);
        if(i){
            int p = (i-1)/2;
            printf("parent key = %d, ", xs[p]);
        }
        int left = i*2 + 1;
        int right = i*2 + 2;
        if(left < n){
            printf("left key = %d, ", xs[left]);
        }
        if(right < n){
            printf("right key = %d, ", xs[right]);
        }
        printf("\n");
    }
}

int main(){
    int n;
    cin >> n;
    int xs[n];
    for(int i = 0; i < n; ++i){
        cin >> xs[i];
    }
    print_tree(xs, n);
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int x, y;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> x >> y;

    int ans = (x + 1) + (y + 1) - (gcd(x,y) + 1);
    cout << ans << endl;
}


Measured memory_bytes: 3208
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;

typedef long long int lli;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)

//FILE *in = freopen("A", "r", stdin);

int n;

void process() {
	int data[210][2];
	memset(data, 0, sizeof(data));

	int minx=0, maxx=0, miny=0, maxy=0;

	for(int i = 1; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		switch (y)
		{
		case 0:
			data[i][0] = data[x][0] + 1;
			data[i][1] = data[x][1];

			if(maxx < data[i][0]) maxx = data[i][0];
			break;
		case 1:
			data[i][0] = data[x][0];
			data[i][1] = data[x][1] + 1;
			if(maxy < data[i][1])maxy = data[i][1];
			break;
		case 2:
			data[i][0] = data[x][0] - 1;
			data[i][1] = data[x][1];
			if(minx > data[i][0])minx = data[i][0];
			break;
		case 3:
			data[i][0] = data[x][0];
			data[i][1] = data[x][1] - 1;
			if(miny > data[i][1])miny = data[i][1];
			break;
		}
	}

	printf("%d %d\n", maxx - minx + 1, maxy - miny + 1);
}

int main() {
	while(true){
		scanf("%d", &n);
		if(n == 0) break;
		process();
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define f first
#define s second

using namespace std;

typedef long long ll;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector <int> lis(n+1,0);
    int ans = 0;
    for(int i=0; i<n; i++){
        int cur; cin >> cur;
        lis[cur] = lis[cur-1] + 1;
        ans = max(ans, lis[cur]);
    }
    cout << n - ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
require 'pp'

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end

def min(a, b)
  return a < b ? a : b
end

n, hlist = gets_n_and_i_list
INF = Float::INFINITY

# DP 配列全体を「DP の種類に応じた初期値」で初期化
dp = Array.new(n, INF)

# 初期条件を入力
dp[0] = 0
dp[1] = (hlist[1] - hlist[0]).abs

def rec(i, dp, hlist)
  # DP の値が更新されていたらそのままリターン
  return dp[i] if dp[i] < INF

  # 足場 0 のコストは 0
  return 0 if i==0

  diff1 = rec(i-1, dp, hlist) + (hlist[i] - hlist[i-1]).abs if i > 0
  diff2 = rec(i-2, dp, hlist) + (hlist[i] - hlist[i-2]).abs if i > 1
  dp[i] = min(diff1, diff2)
  return dp[i]
end

rec(n-1, dp, hlist)

puts dp.last

Measured memory_bytes: 34504
#include<bits/stdc++.h>
using namespace std;
const long long maxn=305;
const long long inf=0x3f3f3f3f;
long long n,e[maxn][maxn],ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(long long i=1;i<=n;i++)
		for(long long j=1;j<=n;j++)
			cin>>e[i][j];
	for(long long i=1;i<=n;i++)
	{
		for(long long j=i+1;j<=n;j++)
		{
			bool flag=0;
			for(long long k=1;k<=n;k++)
			{
				if(i!=k&&j!=k)
				{
					if(e[i][j]>e[i][k]+e[k][j])
					{
						cout<<"-1"<<endl;
						return 0;
					}
					else if(e[i][j]==e[i][k]+e[k][j])
					{
						flag=1;
						break;
					}
				}
			}
			if(flag==0)
				ans+=e[i][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}




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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int a, b;
	cin >> a >> b;
	int ans = 0;
	while (1) {
		if (b <= (a - 1)*ans + 1)break;
		else ans++;
	}
	c(ans);
	ed;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

long long gcd(long long m, long long n) {
    long long r;
    while (0 != n) {
        r = m % n;
        m = n;
        n = r;
    }
    return m;
}

int main() {
    int N;
    long long ans = 1;
    cin >> N;
    for (int i = 0; i < N; i++) {
        long long T;
        cin >> T;
        ans = ans / gcd(ans, T)*T;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int count = 0;
    for (int i = 0; i < s.size(); i++){
        if (s.at(i) != t.at(i)){
            count++;

        }
    }

    cout << count << endl;

}

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

int main(){
    string S;
    const char *s = NULL;
    cin >> S;
    s = S.c_str();
    vector<char> A1, A2, A3;
    vector<char> A1c, A2c, A3c;
    A1.assign(s, s + S.length());
    A2.assign(s, s + (S.length()-1)/2);
    A3.assign(s + (S.length()+3)/2-1, s + S.length());
    A1c = A1;
    A2c = A2;
    A3c = A3;
    reverse(A1c.begin(), A1c.end());
    reverse(A2c.begin(), A2c.end());
    reverse(A3c.begin(), A3c.end());
    long long yes = 1;
    if(A1 != A1c) yes = 0;
    if(A2 != A2c) yes = 0;
    if(A3 != A3c) yes = 0;
    if(yes == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    system("pause");
    return 0;
}

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


int main(){
	
	int r,c;
	cin >> r >> c;
	int a[r+1][c+1];
	for(int i = 0;i < r;i++){
		int sum = 0;
		for(int j = 0;j < c;j++){
			cin >> a[i][j];
			sum += a[i][j];
		}
		a[i][c] = sum;
	}
	for(int i = 0;i < c+1;i++){
		int sum = 0;
		for(int j = 0;j < r;j++){
			sum += a[j][i];
		}
		a[r][i] = sum;
	}
	
	
	for(int i = 0;i < r+1;i++){
		for(int j = 0;j < c+1;j++){
			cout << a[i][j];
			if(j == c)break;
			cout << " ";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 110
#define INF 1e9
typedef pair<int,int> pii;
  
bool a[MAX];
int N,G[MAX];
  
int dijkstra(){
    int res = INF;
    int dist[MAX];
    fill(dist,dist+MAX,INF);
    dist[0] = 0;
    priority_queue<pii,vector<pii>,greater<pii> > Q;
    Q.push(pii(0,0));
    while(!Q.empty()){
	pii now = Q.top(); Q.pop();
	int v = now.second;
	if(dist[v] < now.first) continue;
	if(v == N-1){
	    if(a[N-1]){
		res = min(res,dist[N-1]);
	    }else{
		res = min(res,dist[N-1]+1);
	    }
	    continue;
	}
	if(a[v]){
	    if(dist[v] < dist[v+1]){
		dist[v+1] = dist[v];
		Q.push(pii(dist[v+1],v+1));
	    }
	}else{
	    if(dist[v] + 1 < dist[v+1]){
		dist[v+1] = dist[v] + 1;
		Q.push(pii(dist[v+1],v+1));
	    }
	    if(dist[v] < dist[G[v]]){
		dist[G[v]] = dist[v];
		Q.push(pii(dist[G[v]],G[v]));
	    }
	}
    }
    return res;
}
  
int main(){
    string in,s[MAX];
    cin >> N;
    for(int i = 0 ; i < N ; i++){
	cin >> in;
	if(in == "goto"){
	    a[i] = false;
	    cin >> in;
	    s[i] = in;
	}else{
	    a[i] = true;
	    s[i] = in;
	}
	s[i].resize(s[i].size()-1);
    }
  
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < N ; j++){
	    if(i == j) continue;
	    if(s[i] == s[j]){
		if(!a[i] && a[j]){
		    G[i] = j;
		}else if(a[i] && !a[j]){
		    G[j] = i;
		}
	    }
	}
    }
    cout << dijkstra() << endl;
    return 0;
}

Measured memory_bytes: 3160
from collections import deque
N = int(input())
graph = [[] * N for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])
    
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

# BFSのためのデータ構造
dist = [-1 for _ in range(N)]   # 全頂点を未訪問に
que = deque()

# 初期条件(頂点 K-1 を初期ノードとする)
dist[K-1] = 0
que.append(K-1)

# BFS 開始(キューが空になるまで探索を行う)
while que:
    v = que[0]
    que.popleft()
    for new_v_list in graph[v]:
        new_v = new_v_list[0]
        if dist[new_v] != -1:   # すでに探索済みの頂点は探索しない
            continue
        # 新たな頂点 new_vについて距離情報を更新してキューに追加する
        dist[new_v] = dist[v] + new_v_list[1]
        que.append(new_v)


for i in range(Q):
    print(dist[xy[i][0] - 1] + dist[xy[i][1] - 1])


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

  int n,m,a[100][100],b[100],c[100],add[100][100],sum[100]={0},i,j;

  scanf("%d %d",&n,&m);

  for(i = 0; i < n; i++){

    for(j = 0; j < m; j++){

      scanf("%d",&a[i][j]);

    }

  }

  for(i = 0; i < m; i++){

    scanf("%d",&b[i]);

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

    for(j = 0; j < m; j++){
      
      add[i][j]=a[i][j]*b[j];
  
    }

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

    for(j = 0; j < m; j++){
      
      sum[i]=sum[i]+add[i][j];
  
    }

  }

  for(i = 0; i < n; i++){
    
    printf("%d\n",sum[i]);

      }

  return 0;

}

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

int main(void) {
    int N, M;
    std::cin >> N >> M;
    vector< int > H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    vector< int > A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        --A[i];
        --B[i];
    }
    vector< vector< int > > d(N);
    for (int i = 0; i < M; i++) {
        d[A[i]].push_back(B[i]);
        d[B[i]].push_back(A[i]);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int size = d[i].size();
        bool flag = true;
        for (int j = 0; j < size; j++) {
            if (H[d[i][j]] >= H[i]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ++ans;
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 9592
// Devarshi

/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was

Only through dedication will I destroy all preconception

No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past

Only through dedication will I destroy all preconception

Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration

Join me,
Walk with me

Shatter the bonds that tie us
To what we strive to never be

Join me,
Walk with me
*/
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn=1000001;

int main(){

int n;
cin>>n;

int i=0;
while(i<=n/4){
    int a=i*4;
    int b=n-a;
    if(b%7==0&&b>=0){
        cout<<"Yes";
        return 0;
    }
    i++;
}
cout<<"No";
return 0;
}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace{
    std::chrono::system_clock::time_point t;
    void tic(){t=TIME;}
    void toc(){fprintf(stderr,"TIME : %lldms\n",MILLISEC(TIME-t));}
}

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int width,height;
int m,n;

ll aaa[100010];
ll bbb[100010];

int main(){
    int i,j,k;
    ll x,y,a,b;
    
    cin >> n;
    
    for (i=0;i<n;i++){
        scanf("%lld%lld",aaa+i,bbb+i);
    }
    ll plus = 0;
    for (i=n-1;0<=i;i--){
        x = (aaa[i]+plus)%bbb[i];
        if (0<x)
            plus += bbb[i]-x;
    }
    
    cout << plus << endl;

    return 0;
}


Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))

if 0 in A:
    print('0')
else:
    ans = 1
    for i in range(n):
        ans *= A[i]
        if ans > 10 ** 18:
            print('-1')
            break
    if ans <= 10 ** 18:
        print(ans)


Measured memory_bytes: 21780
x_list = input().split()
a = 100*int(x_list[0])
b = 100*int(x_list[1])
c = int(x_list[2])
d = int(x_list[3])
e = int(x_list[4])
f = int(x_list[5])

max_sato = e*f/100//1
max_mizu = f

def all_pattern(a,b,c):
    max_a = int(c//a)
    all_list = []
    for i in range(max_a+1):
        goukei = 0
        goukei += a*i
        j = 0
        while goukei <= c:
            if not goukei in all_list:
                all_list.append(goukei)
            goukei += b
    return all_list

mizu_pattern = all_pattern(a,b,max_mizu)
sato_pattern = all_pattern(c,d,max_sato)

satosui_situryo = 0
sato_situryo = 0
max_noudo = 0

for mizu in mizu_pattern:
    for sato in sato_pattern:
#         print(sato,mizu)
        if sato + mizu > 0:
            tmp_noudo = sato/(sato+mizu)*100
#             print(tmp_noudo)
            if max_noudo < tmp_noudo and tmp_noudo <= e/(100+e)*100 and mizu+sato <= f:
                max_noudo = tmp_noudo
                satosui_situryo = mizu + sato
                sato_situryo = sato
#                 print("a:",max_noudo,satosui_situryo,sato_situryo)

if satosui_situryo == 0:
    satosui_situryo += a

print(satosui_situryo,sato_situryo)
        
            
        

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

template <typename T>
T BinarySearch(T lo, T hi, std::function<bool(T)> pred) {
  while (lo + 1 < hi) {
    T mid = (hi - lo) / 2 + lo;
    if (pred(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  return lo;
}

int main() {
  in(ll, n, m, k);
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  vector<ll> sa(n + 1), sb(m + 1);
  rep(i, n) sa[i + 1] = sa[i] + a[i];
  rep(i, m) sb[i + 1] = sb[i] + b[i];

  ll ans = 0;
  rep(i, n + 1) {
    ll j = BinarySearch<ll>(0, m + 1, [&](ll x) { return k >= sa[i] + sb[x]; });
    if (k < sa[i] + sb[j]) break;
    ans = max(ans, i + j);
  }
  out(ans);
}


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

int main(){
    int H, W;
    cin >> H >> W;
    char s[H][W];
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            cin >> s[i][j];
        }
    }
    int dp[H][W];
    if (s[0][0] == '#'){
        dp[0][0] = 1;
    } else{
        dp[0][0] = 0;
    }
    for (int i=1; i<H; i++){
        if ((s[i][0] == '#') && (s[i-1][0] == '.')){
            dp[i][0] = dp[i-1][0] + 1;
        } else{
            dp[i][0] = dp[i-1][0];
        }
    }
    for (int i=1; i<W; i++){
        if ((s[0][i] == '#') && (s[0][i-1] == '.')){
            dp[0][i] = dp[0][i-1] + 1;
        } else{
            dp[0][i] = dp[0][i-1];
        }
    }
    for (int i=1; i<H; i++){
        for (int j=1; j<W; j++){
            int dp_h, dp_w;
            if ((s[i][j] == '#') && (s[i-1][j] == '.')){
                dp_h = dp[i-1][j] + 1;
            } else{
                dp_h = dp[i-1][j];
            }
            if ((s[i][j] == '#') && (s[i][j-1] == '.')){
                dp_w = dp[i][j-1] + 1;
            } else{
                dp_w = dp[i][j-1];
            }
            dp[i][j] = min(dp_h, dp_w);
        }
    }

    cout << dp[H-1][W-1] << endl;
    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s;
  cin >> s;
  ll n = s.size();
  
  ll ans = 0, res = 0;
  for(ll i=0; i<n; ++i){
    if(s[i]=='W'){
      ans += res;
    }
    else res++;
  }

  cout << ans;
  return 0;
}

Measured memory_bytes: 640
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
c=list(Counter(A).most_common())
c.sort(key=lambda x:x[0],reverse=True)
w=0
h=0
for a,b in c:
    if(b>=4):
        if(w==0):
            w=a
            h=a
            break
        else:
            h=a
            break
    if(b>1):
        if(w==0):
            w=a
        else:
            h=a
            break
print(w*h)


Measured memory_bytes: 21540
n,T=map(int,input().split())
clist,tlist=[],[]
for i in range(n):
  c,t=map(int,input().split())
  clist.append(c)
  tlist.append(t)

ans=10100
flag=False
for d,e in zip(clist,tlist):
  if e<=T:
    ans=min(ans,d)
    flag=True
if flag == False:
  print("TLE")
else:
  print(ans)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            String[] x=line.split(" ");
            int a=Integer.parseInt(x[0]);
            int b=Integer.parseInt(x[1]);
            int store=0;
            for(int i=1;i<Integer.min(a, b)+1;i++){
            	if(a%i==0&&b%i==0){
            		store=i;
            	}
            }
            System.out.println(store);
        }
	}

}

Measured memory_bytes: 24896
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int x, y, z, k; cin >> x >> y >> z >> k;
    vector<ll> a(x, 0), b(y, 0), c(z, 0);
    for(int i = 0; i < x; i++) cin >> a[i];
    for(int i = 0; i < y; i++) cin >> b[i];
    for(int i = 0; i < z; i++) cin >> c[i];
    vector<ll> ab, ret;
    
    for(int i = 0; i < x; i++)
    {
        for(int j = 0; j < y; j++)
        {
            ab.push_back(a[i] + b[j]);
        }
    }
    
    sort(ab.begin(), ab.end(), greater<ll>());
    
    while(ab.size() > k)
    {
        ab.pop_back();
    }
    
    for(int i = 0; i < ab.size(); i++)
    {
        for(int j = 0; j < z; j++)
        {
            ret.push_back(ab[i] + c[j]);
        }
    }
    
    sort(ret.begin(), ret.end());
    
    while(k--)
    {
        cout << ret.back() << endl;
        ret.pop_back();
    }
   
    return 0;
}


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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = [ord(c) - 97 for c in S()]
    t = [ord(c) - 97 for c in S()]
    sl = len(s)
    tl = len(t)
    rr = [[0] * (tl) for _ in range(sl)]
    t0 = t[0]
    for i in range(sl):
        if s[i] == t0:
            for k in range(i,sl):
                rr[k][0] = 1
            break

    rr0 = rr[0]
    s0 = s[0]
    for j in range(tl):
        if s0 == t[j]:
            for k in range(j,tl):
                rr0[k] = 1
            break

    ta = [(i,t[i]) for i in range(1, tl)]
    for i in range(1, sl):
        rri = rr[i]
        rri1 = rr[i-1]
        si = s[i]
        for j, tj in ta:
            if si == tj:
                rri[j] = rri1[j-1] + 1
            else:
                rri[j] = rri1[j]
                if rri[j] < rri[j-1]:
                    rri[j] = rri[j-1]

    i = sl-1
    j = tl-1
    r = []
    while i >= 0 and j >= 0:
        if s[i] == t[j]:
            r.append(s[i] + 97)
            i -= 1
            j -= 1
            continue
        if rr[i][j] == 0:
            break
        if i > 0 and rr[i-1][j] == rr[i][j]:
            i -= 1
        else:
            j -= 1

    return ''.join(map(chr,r[::-1]))


print(main())


Measured memory_bytes: 315692
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int x1,y1,x2,y2,x3,x4,y3,y4;

void judg(int x1, int y1, int x2, int y2){
    
    if(y1==y2){
        x4=x1;
        x3=x2;
    }
    else{
        x3 = x2 - ( y2-y1 );
        x4 = x1 - ( y2-y1 );
    }
    
    if(x1==x2){
        y4=y1;
        y3=y2;
    }
    else{
        y3 = y2 + (x2-x1);
        y4 = y1 + (x2-x1);
        
    }
    
}

int main(){
    
    cin >> x1 >> y1 >> x2 >> y2;
    
    judg(x1,y1,x2,y2);
    
    
    cout << x3 << " " << y3 << " " << x4 << " " << y4;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            var a = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToDecimal).Select(x=>1/x).ToList();
            Console.WriteLine("{0:0.00000}",1 / a.Sum());


        }


    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int insertionSort(int A[],int n,int G,int cnt){
	int i,v;
	for(i=G;i<=n-1;i++){
		v=A[i];
		int j=i-G;
		
		while(j>=0 && A[j]>v){
			A[j+G]=A[j];
			j=j-G;
			cnt++;
		}
		A[j+G]=v;
		
	}
	return cnt;
}

void shellSort(int A[], int n){
	int m,i,cnt;
	int G[n];
	m=0;
	cnt=0;
	
	for(int h=1;;){
		if(h>n){
			break;
		}
		G[m]=h;
		h = 3*h+1;
		m++;
	}
	
	printf("%d\n",m);
	for(i=m-1;i>=0;i--){
		if(i!=m-1){
			printf(" ");
		}
		printf("%d",G[i]);
	}
	
	printf("\n");
	
	for(i=m-1;i>=0;i--){
		cnt=insertionSort(A,n,G[i],cnt);
	}
	printf("%d\n",cnt);
	for(i=0;i<n;i++){
		printf("%d\n",A[i]);
	}
}

int main(void){
	int n,i;
	int A[1000000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	shellSort(A,n);
	return 0;
}


Measured memory_bytes: 5692
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof i);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) (x&-x)
#define siz(v) (long long)v.size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

string toInt(int a) {
    string s, c;
    while(a>0) {
        s.pb(a%10+'0');
        a/=10;
    }
    for(int i = s.size()-1; i>=0; i--) c.pb(s[i]);
    return c;
}

int main() {
    EmiliaMyWife

    int n, a, b;
    cin >> n >> a >> b;
    if(a>b) swap(a, b);
    ll ans =0;
    for(int i = 1; i <= n; i++) {
        string s = toInt(i);
        //cout << s << endl;
        int cur=0;
        for(auto x: s) {
            cur+=(x-'0');
        }
        if(a<=cur && cur<=b) ans+=i;
    }
    cout << ans;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B  = sc.nextInt();
        String ans = "";
        if(A>B){
            ans = "Alice";
            if(B-A==-12) ans = "Bob";
        }
        else if(A<B){
            ans = "Bob";
            if(B-A==12) ans = "Alice";
        }
        else{
            ans = "Draw";
        }

        System.out.println(ans);

        sc.close();
    }

}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<string> res;
void dfs(string s ,int mx,int n){
    if(n==0){
        //res.push_back(s);
        cout<<s<<'\n';
        return ;
    }
    for(int i=0;i<26;i++){
        //cout<<i<<'\n';
        if(mx +1 < i)break;
        string neww = s;
        neww.push_back('a'+i);
        dfs(neww,max(mx,i),n-1);
    }
}
int main(){
    int n;
    cin>>n;
    dfs("",-1,n);
    /*
    3
    aaa
    aab
    aba
    abb
    abc*/
}


Measured memory_bytes: 1536
// Aggressive Play

#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 2; i <= n; i++){
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; i++)
        cout << a[i] << "\n";
return 0;
}


Measured memory_bytes: 5180
#include<stdio.h>
int dp[10]={0};

int main()
{
    char num;
    while(scanf(" %c",&num) != -1)
    {
        dp[0] = num-'0';
        for(int i = 1; i < 10; i++)
        {
            scanf(" %c",&num);
            dp[i] = num-'0';
        }
        for(int i = 9; i >= 1; i--)
        {
            for(int j = 0; j < i; j++)
            {
                dp[j] = (dp[j]+dp[j+1])%10;
            }
        }
        printf("%d\n",dp[0]);
        for(int i = 0; i < 10; i++)
        {
            dp[i] = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 968
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int x = scn.nextInt();
			int y = scn.nextInt();
			boolean isOk = false;
			for(int t=0; t<=x; t++) {
				int k=x-t;
				if((t*2 + k*4) == y) {
					isOk = true;
					break;
				}
			}
			System.out.println(isOk ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35532
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
#pragma warning(disable: 4996)
int a, b, c;
int main() {
	cin >> a >> b >> c;
	if (a == b)cout << c << endl;
	if (a == c)cout << b << endl;
	if (b == c)cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll K;
    in >> K;
    --K;
    ll ans = 0;

    vector<ll> v{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};
    ans = v[K];
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0 , so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll n ;
    ll ans=  0 ;
    vl v;
    cin >> n ;
    forn(i , 1 , n ){
       ll x ;
       cin >> x ;
       v.pb(x);
    }
    for(ll i = 0 ; i < n ; ++ i ){
        ans = ans + v[i]/ 2 ;
        v[i] = v[i] % 2 ;
        if(v[i] == 1 and v[i+1] >=1 ){
            ans++ ;
            v[i+1]--;
        }
    }
    cout << ans << el ;

}

























Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define nl '\n'
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
const ll N=1e3+9;
const ll mod=1e9+7;

ll dp[N][N];
string s[N];

void solve()
{
	ll n,m;
	cin>>n>>m;
	rep(i,0,n-1)
	cin>>s[i];

	dp[1][0]=1;
	rep(i,1,n)
	{
		rep(j,1,m)
		{
			if(s[i-1][j-1]=='.')
			{
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) %mod;
			}
		}
	}
	cout<<dp[n][m];

}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    //if(t^1)exit(0);
    while(t--)
       solve();
}

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

s = raw_input()

arr = []

i = 0
while i < n:
	if i == n-1:
		arr.append('y')
		break

	if s[i] == s[i+1] :
		arr.append('x')
		i += 2

	else :
		arr.append('y')
		i += 1

ans = 3 if arr[0] == 'y' else 6

for i in range(1,len(arr)):
	if arr[i-1] == 'y' and arr[i] == 'y': 
		ans *= 2

	elif arr[i-1] == 'y' and arr[i] == 'x':
		ans *= 2

	elif arr[i-1] == 'x' and arr[i] == 'y':
		ans *= 1

	else :
		ans *= 3
print ans % (10**9 + 7)

Measured memory_bytes: 2824
#include <iostream>

using namespace std;

typedef long long ll;

ll sum(string s, ll r) {
  ll res = 0, n = 0;
  if (s.empty()) return res + r;
  while (!s.empty()) {
    n = n * 10 + (s.front() - '0');
    s.erase(s.begin());
    res += sum(s, r+n);
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  ll r = 0;
  cout << sum(s, r) << endl;
}

Measured memory_bytes: 256
/*
 * FileName:     A
 * CreatedDate:  2020-04-04 20:59:41 +0900
 * LastModified: 2020-04-04 21:02:05 +0900
 */

#include <stdio.h>

int main(void){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    printf("%d %d %d\n",z,x,y);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,m;
    cin >> n >> m;
  	vector<vi> a(n,vi(m));
  	rep(i,n)rep(j,m)cin >> a[i][j];
    vi x,y;
	rep(i,n){
        if(i%2)rep(j,m){
            x.push_back(i);y.push_back(j);
        }
        else for(int j = m-1; j >= 0; j--){
            x.push_back(i);y.push_back(j);
        }
    }
    vi ans;
    rep(i,n*m-1)if(a[x[i]][y[i]]%2){
        a[x[i+1]][y[i+1]]++;
        ans.push_back(i);
    }
    cout << ans.size() << endl;
    rep(i,ans.size()){
        cout << x[ans[i]]+1 << " " << y[ans[i]]+1 << " " << x[ans[i]+1]+1 << " " << y[ans[i]+1]+1 << endl;
    }
}


Measured memory_bytes: 10040
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

long long n,m,mt;
map<int, int> cnt;
vector<long long> v;

void process(map<int, int>::iterator it, long long t){
    if(it == cnt.end()){
        if(t >= n) v.push_back(t);
        return;
    }
    for(int i=0; i <= it->second; i++){
        long long tmp =  t * pow(it->first,i);
        process(next(it), tmp);
    }
    return;
}

bool isPrime(long long m){
    for(int i=2; i*i <= m; i++){
        if(m%i == 0) return false;
    }
    return m != 1;
}

int main()
{
    cin >> n >> m;
    mt = m;
    if(isPrime(m)){
        cout << 1 << endl;
        return 0;
    }
    
    for(int i=2; i<=m && m!=1; i++){
        while(m%i == 0){
            if(cnt.count(i) == 0) 
                cnt[i] = 1;
            else
                cnt[i]++;
            m = m/i;
        }
    }
    process(cnt.begin(), 1);
    sort(v.begin(), v.end());
    cout << mt/v[0] << endl;
    return 0;
}

Measured memory_bytes: 512
import java.lang.System;
import java.lang.Exception;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        for(int i = 0; i < n; i++) {
            double xa = sc.nextDouble();
            double ya = sc.nextDouble();
            double xb = sc.nextDouble();
            double yb = sc.nextDouble();
            double xc = sc.nextDouble();
            double yc = sc.nextDouble();

            double a = 2*(xb - xa);
            double b = 2*(yb - ya);
            double c = xa*xa - xb*xb + ya*ya - yb*yb;
            double d = 2*(xc - xa);
            double e = 2*(yc - ya);
            double f = xa*xa - xc*xc + ya*ya - yc*yc;

            double xp = (b*f - c*e) / (e*a - b*d);
            double yp = (d*c - a*f) / (e*a - b*d);
            double r = Math.sqrt((xa - xp)*(xa - xp) + (ya - yp)*(ya - yp));
            System.out.printf("%.3f %.3f %.3f\n", xp, yp, r);
        }
    }
}

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

int main(){
	int N,x;
	cin>>N>>x;
	int a[N];
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sort(a,a+N);
	int ans=0;
	for(int i=0;i<N;i++){
		if (x-a[i]<0) break; 
		if (i==N-1 && x!=a[i]) break;
		ans+=1;
		x-=a[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,lp[200][200]={};//[x][y]
  int i,j,k,l,c,x,y,ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    lp[x][y]=1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    lp[x][y]=2;
  }
  for(i=0;i<2*n;i++){
    for(j=0;j<2*n;j++){
      if(lp[i][j]==2){
        c=0;
        for(k=j-1;k>=0;k--){
          for(l=i-1;l>=0;l--){
            if(c==0&&lp[l][k]==1){
              ans++;
              lp[l][k]=0;
              c=1;
            }
          }
        }
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256