akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type req struct {
	a, b int
}

type reqList []req

func (a reqList) Len() int      { return len(a) }
func (a reqList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a reqList) Less(i, j int) bool {
	if a[i].b == a[j].b {
		return a[i].a < a[j].a
	}
	return a[i].b < a[j].b
}

func main() {
	sc.Split(bufio.ScanWords)

	_, M := scanInt(), scanInt()
	L := make(reqList, M)
	for i := 0; i < M; i++ {
		L[i].a, L[i].b = scanInt(), scanInt()
	}
	sort.Sort(L)

	ans, prev := 0, -1
	for _, l := range L {
		if l.a >= prev {
			prev = l.b
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 4624
//
//  main.cpp
//  ABC173B
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    string s;
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    rep(i,n){
        cin >> s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll yo[105];

ll n;
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++) yo[i]=10000000000;
        for(ll i=1;i<n;i++) {
                ll x;
                cin >> x;
                yo[i] = min(yo[i], x);
                yo[i+1] = min(yo[i+1], x);
        }
        ll ans =0;
        for(ll i=1;i<=n;i++) ans += yo[i];
        cout << ans << endl;
        return 0;
}


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

class Program
{
	static int cnt = 0;

	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());

		int[] a = new int[n];
		for (int i = 0; i < n; i++)
		{
			a[i] = int.Parse(Console.ReadLine());
		}

		ShellSort(a);
	}

	static void ShellSort(int[] a)
	{
		List<int> g = new List<int>();

		int h = 0;

		for (int i = 1; i <= a.Length; i = 3*i+1)
		{
			h = i;
			g.Add(i);
		}

		for(int i = g.Count-1; i >= 0; i--)
		{
			InsertionSort(a, g[i]);
		}

		Output(a, g);
	}

	static void InsertionSort(int[] a, int g)
	{
		for (int i = g; i < a.Length; i++)
		{
			int v = a[i];
			int j = i - g;

			while (j >= 0 && a[j] > v)
			{
				a[j + g] = a[j];
				j -= g;
				cnt ++;
			}

			a[j + g] = v;
		}
	}

	static void Output(int[] a, List<int> g)
	{
		int m = g.Count;
		Console.WriteLine(m);

		for(int i = m-1; i >= 0; i--)
		{ 
			Console.Write((i==m-1 ? "" : " ") + g[i]);
		}

		Console.WriteLine();

		Console.WriteLine(cnt);

		for(int i = 0; i < a.Length; i++)
		{
			Console.WriteLine(a[i]);
		}
	}
}


Measured memory_bytes: 23352
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++){
        cnt = (cnt + (s[i] - '0')) % 9;
    }
    if(cnt == 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}

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

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double x=x2-x1;
    double y=y2-y1;
    std::cout<<std::fixed<<std::setprecision(10) << sqrt(x*x+y*y) << endl;
}


Measured memory_bytes: 3288
//In the name of God

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e5+10 , mod = 1e9+7;

int dp[N][3] , a[N][3];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   for(int i = 0 ; i < n ; i++){
      cin >> a[i][0] >> a[i][1] >> a[i][2];
   }
   for(int i = 0 ; i < 3 ; i++)
      dp[0][i] = a[0][i];
   for(int i = 1 ; i < n ; i++){
      for(int j = 0 ; j < 3 ; j++){
         for(int k = 0 ; k < 3 ; k++){
            if(j == k)
               continue;
            dp[i][j] = max(dp[i][j] , dp[i - 1][k] + a[i][j]);
         }
      }
   }
   cout << max(dp[n - 1][0] , max(dp[n - 1][1] , dp[n - 1][2]));
   return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  
  int a = 4;
  int b = 7;
  
  for(int i = 0; i * a <= n; i++){
    for(int j = 0; j * b <= n; j++){
      if(i * a + j * b == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
#define mod 2019

vector<ll> cnt(2019);

int main() {
    string s; cin >> s;
    int n = s.length();

    cnt[0] = 1;
    int rem = 0;
    int p = 1;
    for (int i = n - 1; i >= 0; i--) {
        rem = (rem + (p * (s[i] - '0'))) % mod;
        cnt[rem]++;
        p = (10 * p) % mod;
    }
    ll ans = 0;
    for (auto m : cnt) {
        ans += m * (m - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3704
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0352

#include<bits/stdc++.h>
const int N = 1005;
const int inf = 2e9;
using namespace std;

int n, m, a[N][N], dp[N][N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> m >> n;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
    for (int i = n; i >= 0; i--) for (int j = m; j >= 0; j--) a[i][j] += a[i+1][j] + a[i][j+1] - a[i+1][j+1];
    dp[n][m] = 0;
    for (int i = n; i >= 0; i--) for (int j = m; j >= 0; j--){
        if (i == n && j == m) continue;
        if ((i + j) % 2 == 0) {
            dp[i][j] = -inf;
            if (i < n) dp[i][j] = max(dp[i][j], dp[i+1][j] + a[i+1][j+1] - a[i+2][j+1]);
            if (j < m) dp[i][j] = max(dp[i][j], dp[i][j+1] - a[i+1][j+1] + a[i+1][j+2]);
        }
        else {
            dp[i][j] = inf;
            if (i < n) dp[i][j] = min(dp[i][j], dp[i+1][j] + a[i+1][j+1] - a[i+2][j+1]);
            if (j < m) dp[i][j] = min(dp[i][j], dp[i][j+1] - a[i+1][j+1] + a[i+1][j+2]);
        }
    }
    cout << abs(dp[0][0]) << "\n";
}



Measured memory_bytes: 11040
#include <stdio.h>

int binarysearch(int ans, int n, int a[])
{
	int left = 0;
	int right = n;
	int mid;

	while (left < right)
	{
		mid = (left + right) / 2;
		if (a[mid] == ans)
			return 1;
		else if (ans > a[mid])
			left = mid + 1;
		else
			right = mid;
	}
	return 0;
}

int main(void)
{
	int i, n, m, ans;
	int a[100000];
	int count = 0;

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

	scanf("%d", &m);
	for (i = 0; i < m; i++)
	{
		scanf("%d", &ans);
		if (binarysearch(ans, n, a))
			count++;
	}

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

	return 0;
}


Measured memory_bytes: 2108
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int m = sc.nextInt(); 
			int f = sc.nextInt(); 
			int r = sc.nextInt(); 
			if(m == -1 && f== -1 && r == -1) {
				break;
			} else if((m == -1 || f == -1)) {
				System.out.println("F");
			}else if(80 <= m + f ) {
				System.out.println("A");
			}else if(65 <= m + f ) {
				System.out.println("B");
			}else if(50 <= m + f || 50 <= r) {
				System.out.println("C");
			}else if(30 <= m + f ) {
				System.out.println("D");
			}else if(m + f < 30){
				System.out.println("F");
			}
		}
	}
}




Measured memory_bytes: 26188
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    if a >=13:
        print(b)
    elif a<=5:
        print(0)
    else:
        print(b//2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  if( A == 5 && B == 5 && C == 7){
    cout << "YES" << endl;
  }
  else if( A == 5 && B == 7 && C == 5){
    cout << "YES" << endl;
  }
  else if( A == 7 && B == 5 && C == 5){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
use std::io::BufRead;
use std::io::stdin;

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    loop {
        let mut x = String::new();
        stdin.read_line(&mut x).unwrap();
        let x = x.trim();

        if x == "0" {
            break;
        }

        let x_digits_sum = x.chars().fold(0, |sum, c| sum + c.to_digit(10).unwrap());

        println!("{}", x_digits_sum);
    }
}


Measured memory_bytes: 5032
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;
// ||

int main() {
  ll n; cin >> n;
  ll i = 2;
  ll yi = 1;
  while (i*i <= n) {
    if (n%i==0) yi = i;
    i++;
  }
  cout << max(to_string(yi).size(), to_string(n/yi).size()) << endl;
  return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, m; cin >> n >> m;
    int sum = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {cin >> a[i]; sum += a[i];}
    sort(a.begin(), a.end(), greater<int>());
    if (a[m - 1] * 4 * m >= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

string shuffle(int m, string s)
{
  for (int i=0; i<m; i++) {
    int h;
    cin >> h;
    string s1, s2;
    s1 = s.substr(0, h);
    s2 = s.substr(h, s.size()-h);
    s = s2 + s1;
  }
  return s;
}

int main()
{
  while (1) {
    string s;
    cin >> s;
    if (s == "-") break;
    int m;
    cin >> m;
    s = shuffle(m, s);
    cout << s << endl;
  }
  return 0;
}



Measured memory_bytes: 3204
// AOJ 1336: The Last Ant
// 2017.12.16 bal4u@uu

#include <stdio.h>
#include <string.h>

int l[102], r[102];

int main()
{
	int N, L, i, p, t, last;
	char buf[5];

	while (scanf("%d%d", &N, &L) && N > 0) {
		memset(l, 0, sizeof(l)), memset(r, 0, sizeof(r));
		for (i = 1; i <= N; i++) {
			scanf("%s%d", buf, &p);
			if (*buf == 'L') l[p] = i;
			else             r[p] = i;
		}

		for (last = 0, t = -1; N > 0; t++) {
			if (r[L]) last = r[L], r[L] = 0, N--;
			for (i = L-1; i >= 0; i--) r[i+1] = r[i];

			if (l[0]) last = l[0], l[0] = 0, N--;
			for (i = 1; i <= L; i++) {
				if (!l[i]) continue;
				if (r[i-1]) {
					l[i-1] = r[i-1], r[i-1] = l[i];
				} else l[i-1] = l[i];
				l[i] = 0;
			}
		}
		printf("%d %d\n", t, last);
	}
	return 0;
}

Measured memory_bytes: 1752
// Author: 23forever
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 100000;
const int MAXM = 100000;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, m, tot, head[MAXN + 5], d[MAXN + 5], in[MAXN + 5];
queue < int > que;

struct Edge {
  int to, w, nxt;
  Edge() {}
  Edge(int _to, int _w, int _nxt) : to(_to), w(_w), nxt(_nxt) {}
}edge[MAXM + 5];

inline void add(int u, int v, int w) {
  edge[tot] = Edge(v, w, head[u]);
  head[u] = tot++;
  ++in[v];
}

int topsort() {
  for (int i = 1; i <= n; ++i) {
    if (!in[i]) {
      que.push(i);
      d[i] = 0;
    }
  }

  while (!que.empty()) {
    int u = que.front();
    que.pop();

    for (int i = head[u]; ~i; i = edge[i].nxt) {
      int v = edge[i].to, w = edge[i].w;
      if (d[u] + w > d[v]) d[v] = d[u] + w;
      if (!--in[v]) que.push(v);
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = max(ans, d[i]);
  return ans;
}

void init() {
  tot = 0;
  memset(head, -1, sizeof(head));

  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    add(u, v, 1);
  }
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  //freopen("test.out", "w", stdout);
#endif
  init();

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

Measured memory_bytes: 2816
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
string s;
int cnt[555];
int main()
{
	cin>>s;
	for(int i=0;i<s.size();++i)
		++cnt[s[i]];
	int n=s.size();
	int ex[3]={n/3+(n%3>=1),n/3+(n%3>=2),n/3};
	sort(ex,ex+3);
	int*s=cnt+'a';
	sort(s,s+3);
	if(s[0]!=ex[0]||s[1]!=ex[1]||s[2]!=ex[2])
	puts("NO"); else puts("YES");
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==1)
    {
        n=14;
    }
    if(m==1)
    {
        m=14;
    }
    if(n==m)
    {
        cout<<"Draw";
    }
    else if(n<m)
    {
        cout<<"Bob";
    }
    else
    {
        cout<<"Alice";
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
def solve():
    input=sys.stdin.readline
    n,q=map(int, input().split())

    G=[[] for i in range(n)]
    #up_G=[0]*n#up_G[i]=頂点iの親
    for _ in range(n-1):
        a,b=map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    ans=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        ans[p-1]+=x
    #(G,v,p)=(グラフ(木の情報),探索中の頂点,vの親)
    #vの子の頂点を決めて、vをpに移す
    q=deque()
    q.append((0,-1))
    while q:
        V,P=q.popleft()
        for new_v in G[V]:
            #new_vが頂点の時はアウト
            if new_v==P:continue
            ans[new_v]+=ans[V]
            q.append((new_v,V))
    print(*ans)
solve()


Measured memory_bytes: 62132
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a[3],b=0,c=0,d=0,e=0,k=0;
  int q[3];
  for(int i=0;i<3;i++){
    cin>>a[i];
    b=max(a[i],b);
  }
  while(true){
    for(int i=0;i<3;i++){
      q[i]=b-a[i];
      if(q[i]%2==0) d++;
      else c++;
    }
    b++;
    if(d==3||d==1) break;
    if(c==2) break;
  }
  //if(d!=3) e++;
  for(int i=0;i<3;i++){
    if(q[i]%2==1) k++,q[i]--;
    if(k==2) e++,k=0;
    e+=(q[i]/2);
  }
  cout<<e<<"\n";
} 

Measured memory_bytes: 256
k = int(input())

import heapq
INF = 10**9

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        return self.dist

edge = [[] for _ in range(k)]
for i in range(k):
    edge[i].append([(i+1) % k, 1])
    edge[i].append([(i*10) % k, 0])

DIJ = Dijkstra(edge)
DIJ.calc
print(DIJ.calc(1)[0] + 1)

Measured memory_bytes: 45356
#include<bits/stdc++.h>
using namespace std;
long long q,h,s,d,n,k;
int main()
{
    cin>>q>>h>>s>>d>>n;
    k=min(q*4,min(h*2,s));
    if(k*2<=d)
        cout<<k*n<<endl;
    else
        cout<<((n%2)*k)+n/2*d<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int main()
{	
    int w,h,x,y;
	cin >> w >> h >> x >> y;
    
    double ans;
    ans = ((double)w*(double)h)/2.;
    int poly;

    if(w==2*x && h==2*y) poly = 1;
    else poly = 0;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
ll INF = 1000000000000000001; //10^18+1
ll MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)


int main() {
  ll N,M,P,AC=0,WA=0;
  string S;
  cin >> N >> M;
  ll ACC[N+1]={};
  for(int i=0;i<M;i++){
    cin >> P >> S;
    if(S=="AC"&&ACC[P]!=INF){
      WA+=ACC[P];
      ACC[P]=INF;
      AC++;
    }else if(S=="WA"&&ACC[P]!=INF){
      ACC[P]++;
    }
  }
  cout << AC << ' ' << WA << endl;
}

Measured memory_bytes: 1024
/**
  *  Worg
  */
#include <cmath>
#include <vector>
#include <cstdlib>
#include <iostream>

const int INF = 1e9;

int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> h(n);
	for (auto& x : h) {
		std::cin >> x;
	}

	std::vector<int> dp(n, INF);
	dp[0] = 0;

	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k && i - j >= 0; j++) {
			dp[i] = std::min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}

	std::cout << dp.back() << '\n';
	return 0;
}


Measured memory_bytes: 1024
/*
 *
 */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>

#define MAX_N 405
#define MAX_C 1000

using namespace std;
typedef long long ll;

int c[MAX_N][4];

ll calc(ll c0, ll c1, ll c2, ll c3) {
    return c0 * MAX_C * MAX_C * MAX_C + c1  * MAX_C * MAX_C + c2 * MAX_C + c3;
}

ll normalizeC(int* start) {
    ll minimum = calc(start[0], start[1], start[2], start[3]);
    for (int i = 0; i < 4; ++i) {
        ll next = calc(start[(0+i)%4], start[(1+i)%4], start[(2+i)%4], start[(3+i)%4]);
        if (minimum > next) {
            minimum = next;
        }
    }
    return minimum;
}

ll normalizeC(int a, int b, int c, int d) {
    int s[4] = {a, b, c, d};
    return normalizeC(s);
}

ll multi(int a, int b, int c, int d) {
    if (a==b && b==c && c==d) return 4;
    if (a==c && b == d) return 2;
    else return 1;
}

int main(){
    //freopen("e3.in", "r", stdin);
    int n;
    scanf("%d", &n);

    map<ll, int> tileMap;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d %d %d", &c[i][0], &c[i][1], &c[i][2], &c[i][3]);
        ll key = normalizeC(c[i]);
        tileMap[key]++;
        //cout << key << ": " <<tileMap[key] << endl;
    }

    ll total = 0;
    for (int i = 0; i < n; ++i) {        // Determine side '1'
        for (int j = i+1; j < n; ++j) {  // Determine side '5'
            ll key1 = normalizeC(c[i]);
            ll key5 = normalizeC(c[j]);
            tileMap[key1]--;
            tileMap[key5]--;
            for (int k = 0; k < 4; ++k) {// Determine rotation of '5'
                ll key2 = normalizeC(c[i][0], c[j][(1+k)%4], c[j][(0+k)%4], c[i][1]);
                ll multiple2 = multi(c[i][0], c[j][(1+k)%4], c[j][(0+k)%4], c[i][1]);
                ll key3 = normalizeC(c[i][1], c[j][(0+k)%4], c[j][(3+k)%4], c[i][2]);
                ll multiple3 = multi(c[i][1], c[j][(0+k)%4], c[j][(3+k)%4], c[i][2]);
                ll key4 = normalizeC(c[i][2], c[j][(3+k)%4], c[j][(2+k)%4], c[i][3]);
                ll multiple4 = multi(c[i][2], c[j][(3+k)%4], c[j][(2+k)%4], c[i][3]);
                ll key6 = normalizeC(c[j][(1+k)%4], c[i][0], c[i][3], c[j][(2+k)%4]);
                ll multiple6 = multi(c[j][(1+k)%4], c[i][0], c[i][3], c[j][(2+k)%4]);
                //cout << key1 << " " << key5 << ": " << key2 << " " << key3 << " "<< key4 << " " << key6 << endl;
                //cout << tileMap[key2] << " " << tileMap[key3] << " "<< tileMap[key4] << " " << tileMap[key6] << endl;
                ll tmp;
                tmp = tileMap[key2] * multiple2;  tileMap[key2]--;
                tmp *= tileMap[key3] * multiple3;  tileMap[key3]--;
                tmp *= tileMap[key4] * multiple4;  tileMap[key4]--;
                tmp *= tileMap[key6] * multiple6;
                tileMap[key2]++; tileMap[key3]++; tileMap[key4]++;
                total += tmp;
            }
            tileMap[key1]++;
            tileMap[key5]++;
        }
    }
    printf("%lli\n", total/3);

    return 0;
}


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

#define iFOR(idx, from, upto) for (int  idx = from; idx < upto; ++idx)
#define lFOR(idx, from, upto) for (long idx = from; idx < upto; ++idx)

#define ll long long

using namespace std;

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

    if (s == "ARC") {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
n = int(input())
p = [int(i) for i in input().split()]

count = 0
for i in range(n-2):
  a = p[i]
  b = p[i+1]
  c = p[i+2]
  if b > a and b < c:
    count+=1
  elif b > c and b < a:
    count+=1
print(count)

Measured memory_bytes: 3060
// #include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>
#include<functional>
#include <bitset>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
#define INFTY 1<<29
using namespace std;
typedef long long ll;
typedef long long int lli;
// static const int MOD = 10000007;
// static const int MAX = 100005;
static const int NMAX = 51;
static const int KEY = 4096;


// typedef priority_queue<int, greater<int>> RevQ;
int N, M;
// lli A, B;
vector<int> d(NMAX);


// lli gcd(lli a, lli b) {
//   return b ? gcd(b, a%b) : a;
// }

int main(){
  cin >> N;
  rep(i, N) {
    cin >> d[i];
  }
  int sum = 0;
  int ans = 0;
  rep(i, N) {
    if (i == 0) {
      sum += d[i];
      continue;
    }
    ans += sum * d[i];
    sum += d[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
pairs = []
while true
  x, y = $stdin.readline.split(" ").map {|s| s.to_i }

  if x == 0 && y == 0
    break
  end

  pairs.push([x, y])
end

pairs.each {|pair|
  x = pair[0]
  y = pair[1]

  if x < y
    puts "#{x} #{y}"
  else
    puts "#{y} #{x}"
  end
}



Measured memory_bytes: 6876
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		
		int sxl = x - r;
		int sxr = x + r;
		int syu = y + r;
		int syd = y - r;
		
		if(sxl < 0 || sxr > W || syu > H || syd < 0){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 26336
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = in.readLine();
		StringTokenizer tk = new StringTokenizer(line);
		String toReverse = tk.nextToken();
		char[] revArray = new char[toReverse.length()];
		for (int i = 0; i < toReverse.length(); i++) {
			revArray[toReverse.length()-1-i] = toReverse.charAt(i);
		}
		System.out.println(new String(revArray));
	}
}

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

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;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

// π M_PI
// deg = rad*180/M_PI

const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
    char s;
    cin >> s;
    rep(i, ABC.length()) {
        if ( s == ABC[i] ) {
            cout << 'A' << endl;
            return 0;
        }
        if ( s == abc[i] ) {
            cout << 'a' << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int a,b,c,d;
    string s,t,u;

    cin>>a>>s;

    if(s.length()<=a){
        cout<<s<<endl;
    }else{
        string ans=s.substr(0,a)+"...";
        cout<<ans<<endl;
    }

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3624
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

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

	int N, M;
	cin >> N >> M;

	vector<vector<int>> grid(N, vector<int>(M));
	for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) cin >> grid[i][j];
	for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) grid[i][j]--;

	struct dat {
		vector<int> mem;
		int size = 0;
	};

	auto select = [&]() {

		int mx = N - 1;
		bool res = true;
		while (res) {

			vector<dat> D(M);
			vector<int> ind(N);
			queue<int> que;
			for (int i = 0; i < N; i++) que.emplace(i);

			while (!que.empty()) {

				int now = que.front();
				que.pop();
				if (ind[now] == M) {
					res = false;
					break;
				}

				auto &Dnow = D[grid[now][ind[now]]];
				if (Dnow.size != -1) {
					if (Dnow.size < mx) {
						Dnow.size++;
						Dnow.mem.emplace_back(now);
					}
					else {
						Dnow.size = -1;
						for (const auto &e : Dnow.mem) que.emplace(e);
						que.emplace(now);
					}
				}
				else que.emplace(now);
				ind[now]++;
			}
			
			if (res) {
				mx = 0;
				for (int i = 0; i < M; i++) {
					chmax(mx, D[i].size);
				}
				mx--;
			}

		}

		return mx + 1;

	};

	cout << select() << "\n";

	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
using namespace std;
long n, M;
vector<vector<long>> g;
long dp[100010], ans[100010];

void dfs1(int v, int p) {
  dp[v] = 1;
  for(int nv : g[v]) {
    if(nv == p) continue;
    dfs1(nv, v);
    dp[v] = dp[v] * -~dp[nv]%M;
  }
}

void dfs2(int v, int p) {
  ans[v] = 1;
  for(int nv : g[v]) ans[v] = ans[v] * -~dp[nv]%M;

  int N = g[v].size();
  vector<long> L(N+1,1), R(N+1,1);
  for(int i = 0; i < N; ++i) L[i+1] = L[i] * -~dp[g[v][i]]%M;
  for(int i =N-1;i > 0; --i) R[i-1] = R[i] * -~dp[g[v][i]]%M;

  for(int i = 0; i < N; ++i) {
    if(g[v][i] == p) continue;
    dp[v] = L[i] * R[i]%M;
    dfs2(g[v][i], v);
  }
}

int main() {
  cin >> n >> M;
  g.resize(n);
  for(int i = 0; i < n-1; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  dfs1(0, -1);
  dfs2(0, -1);
  for(int i = 0; i < n; ++i) 
    cout << ans[i] << '\n';
  return 0;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
       cout<<(a-b)%c<<endl;
       return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    vector<ll> a(N);
    for (auto &&i : a) {
        cin >> i;
    }

    ll sum = abs(a[0]) + abs(a[a.size() - 1]);
    FOR(i, 1, N) { sum += abs(a[i - 1] - a[i]); }
    a.insert(a.begin(), 0);
    a.emplace_back(0);
    FOR(i, 1, N + 1) {
        ll ans = sum - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) +
                 abs(a[i - 1] - a[i + 1]);
        print(ans);
    }

    return 0;
}

Measured memory_bytes: 2032
from sys import stdin


def main():
    N = input()
    P = [int(x) for x in stdin.readline().rstrip().split()]

    min_now = P[0]
    count = 0

    for p in P:
        if p <= min_now:
            count += 1
            min_now = p
        else:
            pass

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24744
#!/usr/bin/perl
use POSIX qw(floor);

my $s = scalar(<STDIN>);
my $t = scalar(<STDIN>);

my $r = 0;
for(my $i=0;$i<length($s);$i++){
  my $c = substr($s,$i,1);
  my $c2 = substr($t,$i,1);
  if( $c =~ /[a-z]/o and ($c ne $c2) ){ $r++;}
}

print "$r\n";



Measured memory_bytes: 7052
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    double x;
    cin>>x;
    ll dep = 100;
    int ans=0;
    while(1){
        ans++;
        dep += dep/100;
        if(x<=dep)break;
    }
    cout<<ans;

    return 0;
}

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

int main() {
  char s;
  int count = 0;
  int i;
  for (i = 0; i < 3; i++) {
    cin >> s;
    if (s == 'o') {
      count++;
    }
  }
  cout << 700 + 100 * count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;
    vector<pair<int, int>> compressed_S;
    compressed_S.push_back(make_pair(S[0] - '0', 1));
    rep(i, N - 1)
    {
        if (compressed_S.back().first == S[i + 1] - '0')
            compressed_S.back().second++;
        else
            compressed_S.push_back(make_pair(S[i + 1] - '0', 1));
    }
    int compressed_size = compressed_S.size();
    vector<int> imos(compressed_size + 1, 0);
    rep(i, compressed_size)
    {
        imos[i + 1] = imos[i] + compressed_S[i].second;
    }

    int ans = 0;
    int change_count = 2 * K;

    rep(i, compressed_size)
    {
        int l = i, r = i + change_count;
        if (compressed_S[i].first == 0)
            l--;
        else
            r++;
        l = max(l, 0);
        r = min(r, compressed_size);
        ans = max(ans, imos[r] - imos[l]);
    }

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

Measured memory_bytes: 1652
/*input
2 0
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 1000090
#define INF 0x3f3f3f3f

struct djs{
    int x[MAX];
    void init(){ REP(i , 0 , MAX) x[i] = i; }
    int Find(int a){ return a == x[a] ? a : x[a] = Find(x[a]); }
    void Union(int a , int b){ x[Find(a)] = Find(b); }
    int operator[](int a){ return Find(a); }
} ds;

vector<PII> v[MAX];
int dis[MAX];
int dijkstra(int s , int t){
    priority_queue<PII , vector<PII> , greater<PII> > pq;
    MEM(dis , INF) , dis[s] = 0 , pq.push(mp(0 , s));
    while(pq.size()){
        int step = pq.top().A , now = pq.top().B;
        pq.pop();
        if(dis[now] != step) continue;
        for(auto to : v[now]){
            if(dis[to.A] > dis[now] + to.B){
                dis[to.A] = dis[now] + to.B;
                pq.push(mp(dis[to.A] , to.A));
            }
        }
    }
    return dis[t];
}

int n , m , e[MAX][3] , idx[MAX];
vector<int> sol[MAX];
int32_t main(){
    IOS;
    cin >> n >> m;
    REP(i , 1 , m + 1) REP(j , 0 , 3) cin >> e[i][j];
    int pos = n;
    REP(i , 1 , m + 1) sol[e[i][2]].pb(i);
    ds.init();
    REP(i , 1 , MAX){
        for(auto to : sol[i]) ds.Union(e[to][0] , e[to][1]);
        // for(auto to : sol[i]) cout << "here = " << ds[e[to][0]] << endl;
        for(auto to : sol[i]) if(ds[e[to][0]] == e[to][0] && idx[e[to][0]] == 0) idx[e[to][0]] = ++pos;
        for(auto to : sol[i]) if(ds[e[to][1]] == e[to][1] && idx[e[to][1]] == 0) idx[e[to][1]] = ++pos;
        for(auto to : sol[i]) REP(dot , 0 , 2) {
            int now = e[to][dot] , res = ds[now];
            v[now].pb(idx[res] , 1);
            v[idx[res]].pb(now , 0);
            // DB4("add edge = " , now , idx[res] , 1);
            // DB4("add edge = " , idx[res] , now , 0);
        }
        for(auto to : sol[i]) idx[e[to][0]] = idx[e[to][1]] = 0;
        for(auto to : sol[i]) ds.x[e[to][0]] = e[to][0] , ds.x[e[to][1]] = e[to][1];
            // return 0;
    }
    int ans = dijkstra(1 , n);
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B == C+D){
  	cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(a);
        int asum = 0;
        int bsum = 0;
        for(int i=n-1; i>=0; i--) {
            if((n-1) % 2 == 0) {
                if(i % 2 == 0) asum += a[i];
                else bsum += a[i];
            }else {
                if(i % 2 == 1) asum += a[i];
                else bsum += a[i];
            }
        }
        
        System.out.println(asum - bsum);
    }
}


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


int main() {
	int N;
	cin >> N;
	vector<long long> A(N+1), B(N);

	for (int i = 0; i < N+1; i++)	{
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}

	long long ans = 0;

	for (int i = 0; i < N; i++) {
		if (B[i] > A[i])
		{
			ans += A[i];
			long long tmp = min(B[i] - A[i], A[i + 1]);
			ans += tmp;
			A[i + 1] -= tmp;
		}
		else
		{
			ans += B[i];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from collections import deque
from operator import itemgetter

N, D, A = map(int, input().split())
X = []
for _ in range(N):
    x, h = map(int, input().split())
    X.append((x, h))
X = sorted(X, key = itemgetter(0))[::-1]
Q = deque([])

ans = 0
k = 0
while X:
    if len(Q) == 0 or X[-1][0] <= Q[0][0]:
        x, h = X.pop()
        h = max(h - k * A, 0)
        a = (h + A - 1) // A
        ans += a
        k += a
        deque.append(Q, (x + 2 * D, a))
    else:
        x, a = deque.popleft(Q)
        k -= a

print(ans)

Measured memory_bytes: 35312
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, a;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        q.push(a);
    }
    while (m--)
    {
        int x = q.top();
        q.pop();
        q.push(x / 2);
    }
    long long ans = 0;
    while (n--)
    {
        ans += q.top();
        q.pop();
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>

using namespace std;

int main () {
    char c;
    cin >> c;

    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
function Main(input) {
    tmp = input.split(" ");
    var a = parseInt(tmp[0], 10);
    var b = parseInt(tmp[1], 10);
    if (b < a) {
    	result = a - 1;
    } else {
    	result = a;
    }
    //結果
    console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int x,y;
  cin >> x >> y;

  int total=(x+1)+(y+1);

  for(int i=0; i<=x; i++){
    for(int j=0; j<=y; j++){
      if(x*j==y*i){
        total--;
      }
    }
  }

  cout << total << endl;

  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	
	string s; ll K;
	cin >> s;
	cin >> K;

	vll arr;
	rep(i, s.size()) {
		if (s[i] == '1') arr.push_back(1);
		else {
			arr.push_back(s[i] - '0');
			break;
		}
	}

	if (K < arr.size()) cout << arr[K - 1] << endl;
	else cout << arr.back() << endl;
}


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

int N, R;


int main()
{

 //   std::cout << "Hello World!\n";

    cin >> N >> R;
    int K = 0;

    if (N >= 10) {
        K = R;

    }else{
        K = R+(100*(10-N));

    }

    cout << K << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<unordered_map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a; 
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<vector<ll>> grid(3, vector<ll>(3, 0));
	f(i, 0, 3)
	{
		f(j, 0, 3)
			cin >> grid[i][j];
	}
	ll n;
	cin >> n;
	f(i, 0, n)
	{
		ll temp;
		cin >> temp;
		f(j, 0, 3)
		{
			f(k, 0, 3)
			{
				if (grid[j][k] == temp)
				{
					grid[j][k] = 0;
					break;
				}
			}
		}
	}
	string ans = "No";
	f(i, 0, 3)
	{
		ll sum = 0;
		f(j, 0, 3)
		{
			sum += grid[i][j];
		}
		if (sum == 0)
		{
			ans = "Yes";
			break;
		}
	}
	f(i, 0, 3)
	{
		ll sum = 0;
		f(j, 0, 3)
		{
			sum += grid[j][i];
		}
		if (sum == 0)
		{
			ans = "Yes";
			break;
		}
	}
	ll sum = 0;
	f(i, 0, 3)
	{
		sum += grid[i][i];
	}
	if (sum == 0)
		ans = "Yes";
	sum = 0;
	f(i, 0, 3)
	{
		sum += grid[2-i][i];
	}
	if (sum == 0)
		ans = "Yes";
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static PrintWriter out;
    static Scanner sc;

    static void solve() {
        int a = nextInt();
        int b = nextInt();
        int c = nextInt();

        int max = Math.max(Math.max(a, b), c);
        a = max - a;
        b = max - b;
        c = max - c;

        int ans = a / 2 + b / 2 + c / 2;
        int amari = a % 2 + b % 2 + c % 2;
        if (amari == 1) {
            ans += 2;
        } else if (amari == 2) {
            ans += 1;
        } else if (amari == 3) {
            ans += 3;
        }
        System.out.println(ans);
    }

    static int nextInt() {
        return Integer.parseInt(sc.next());
    }

    static long nextLong() {
        return Long.parseLong(sc.next());
    }

    static String nextString() {
        return sc.next();
    }

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

    static List<Integer> nextIntList(int n) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextInt());
        }
        return list;
    }

    static List<Long> nextLongList(int n) {
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextLong());
        }
        return list;
    }

    static <T extends Comparable<? super T>> void sort(List<T> list) {
        Collections.sort(list);
    }

    // greatest common divisor
    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

    // intをlength桁のbit文字列に変換
    static String toBinaryString(int input, int length) {
        return toBinaryString(input).substring(29 - length);
    }

    // intを29桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x10000000;
        for (int i = 0; i < 29; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

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

        solve();

        out.flush();
        sc.close();
    }

}


Measured memory_bytes: 22996
N = int(input())
X = [int(x) for x in input().split()]

Y = [x for x in X if x%2 == 0]

Z = [y for y in Y if y%3 != 0 and y%5 != 0]

if len(Z) == 0:
    print("APPROVED")
else:
    print("DENIED")

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

int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if ((e - a) <= k)cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 256
O = input()
E = input()
ans = ""
for i in range(len(O+E)):
  if i%2==0:
    if i//2 <= len(O)-1:
      ans += O[i//2]
  else:
    if i//2 <= len(E)-1:
      ans += E[i//2]
print(ans)

Measured memory_bytes: 3060