akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<stack>
#define INF 1000000000
#define M 10005
#define LL long long
using namespace std;
struct node{
    int x,y;
    double z;
};
node B[M];
vector<node>A;
int fa[M];
double dis(int x,int y){
    int dx=B[x].x-B[y].x,dy=B[x].y-B[y].y;
    return sqrt(dx*dx+dy*dy);
}
int get(int x){
    if(fa[x]==x) return x;
    else return fa[x]=get(fa[x]);
}
bool cmp(node a,node b){
    return a.z>b.z;
}
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF){
        int j,k;
        A.clear();
        for(j=1;j<=n;j++){
            fa[j]=j;
        }
        for(j=1;j<=n;j++) scanf("%d%d",&B[j].x,&B[j].y);
        double ans=0;
        for(j=1;j<=m;j++){
            int x,y;
            scanf("%d%d",&x,&y);
            double z=dis(x,y);
            //printf("%f\n",z);
            ans+=z;
            A.push_back((node){x,y,z});
        }
        sort(A.begin(),A.end(),cmp);
        for(j=0;j<A.size();j++){
            int a=get(A[j].x),b=get(A[j].y);
            if(a!=b){
                fa[a]=b;
                ans-=A[j].z;
            }
        }
        printf("%.3f\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1872
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int a,b,c,ans;
int main()
{
    fast;
    cin>>a>>b>>c;
    for (int i=1;i<=a;i++)
    {
    	int x;
    	cin>>x;
    	if (x<b || x>=c)
    	   ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

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

int main(void)
{
    ll n; cin>>n;
    ll sum=0;
    while(n>0)
    {
        if(n>499){
            n-=500;
            sum+=1000;
            continue;
        }else if(n>4){
            n-=5;
            sum+=5;
            continue;
        }
        n--;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = [0 for _ in range(N+1)]
for i in range(1,int(N**0.5)+1):
    for j in range(i, int(N ** 0.5)+1):
        for k in range(j, int(N ** 0.5)+1):
            a = i*i + j*j + k*k + i*j + j*k + k*i
            if a > N:
                break
            elif a >= 0:
                if i == j == k:
                    L[a] += 1
                elif i == j or j == k:
                    L[a] += 3
                else:
                    L[a] += 6
for i in range(1,N+1):
    print(L[i])

Measured memory_bytes: 70068
#include <stdio.h>          // printf(), putchar(), scanf()

int
main(int argc, char **argv)
{
	int n;

	scanf("%d", &n);
	for (int u = 0; u < n; ++u)
	{
		short puzzle[9][9];
		char check[9][9];
		enum {none, done, dupli} state[9];

		for (int y = 0; y < 9; ++y)
		{
			for (int x = 0; x < 9; ++x)
				scanf("%hd", &puzzle[y][x]);
		}

		for (int y = 0; y < 9; ++y)
		{
			for (int x = 0; x < 9; ++x)
				check[y][x] = ' ';
		}

		for (int x = 0; x < 9; ++x)
		{
			for (int i = 0; i < 9; ++i)
				state[i] = none;

			for (int y = 0; y < 9; ++y)
			{
				int t = puzzle[y][x] - 1;
				if (state[t] == none)
					state[t] = done;
				else
					state[t] = dupli;
			}

			for (int i = 0; i < 9; ++i)
			{
				if (state[i] == dupli)
				{
					for (int y = 0; y < 9; ++y)
					{
						if (puzzle[y][x] == i + 1)
							check[y][x] = '*';
					}
				}
			}
		}

		for (int y = 0; y < 9; ++y)
		{
			for (int i = 0; i < 9; ++i)
				state[i] = none;

			for (int x = 0; x < 9; ++x)
			{
				int t = puzzle[y][x] - 1;
				if (state[t] == none)
					state[t] = done;
				else
					state[t] = dupli;
			}

			for (int i = 0; i < 9; ++i)
			{
				if (state[i] == dupli)
				{
					for (int x = 0; x < 9; ++x)
					{
						if (puzzle[y][x] == i + 1)
							check[y][x] = '*';
					}
				}
			}
		}

		for (int y = 0; y < 9; y += 3)
		{
			for (int x = 0; x < 9; x += 3)
			{
				for (int i = 0; i < 9; ++i)
					state[i] = none;

				for (int i = 0; i < 9; ++i)
				{
					int tx = x + i % 3, ty = y + i / 3;
					int t = puzzle[ty][tx] - 1;
					if (state[t] == none)
						state[t] = done;
					else
						state[t] = dupli;
				}

				for (int i = 0; i < 9; ++i)
				{
					if (state[i] == dupli)
					{
						for (int j = 0; j < 9; ++j)
						{
							int tx = x + j % 3, ty = y + j / 3;
							if (puzzle[ty][tx] == i + 1)
								check[ty][tx] = '*';
						}
					}
				}
			}
		}

		if (u != 0)
			putchar('\n');

		for (int y = 0; y < 9; ++y)
		{
			for (int x = 0; x < 9; ++x)
				printf("%c%hd", check[y][x], puzzle[y][x]);

			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 1796
def main():
    A, B = map(int, input().split())
    continuous = 0
    a = 0
    b = 0
    c = 0
    if A % 2 == 0:
        continuous += int((B - A + 1) / 2)
    else:
        a = A
        continuous += int((B - (A + 1) + 1) / 2)
    if continuous % 2 != 0:
        c = 1
    if B % 2 != 1:
        b = B
    print(a ^ b ^ c)


if __name__ == "__main__":
    main()


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

int main() {
  int sx,sy,tx,ty,dx,dy;
  cin >> sx >> sy >> tx >> ty;
  dx = tx - sx;
  dy = ty - sy;
  for(int i=0;i<dx;i++) {
    cout << "R";
  }
  for(int i=0;i<dy;i++) {
    cout << "U";
  }
  for(int i=0;i<dx;i++) {
    cout << "L";
  }
  for(int i=0;i<dy;i++) {
    cout << "D";
  }
  cout << "D";
  for(int i=0;i<dx+1;i++) {
    cout << "R";
  }
  for(int i=0;i<dy+1;i++) {
    cout << "U";
  }
  cout << "L" << "U";
  for(int i=0;i<dx+1;i++) {
    cout << "L";
  }
  for(int i=0;i<dy+1;i++) {
    cout << "D";
  }
  cout << "R" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  char c;
  scanf("%c",&c);
  if(c=='A')
  {
    printf("T\n");
  }
  if(c=='T')
  {
    printf("A\n");
  }
  if(c=='C')
  {
    printf("G\n");
  }
  if(c=='G')
  {
    printf("C\n");
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  int ans = 0;
  int max_c = 0;
  for(int i = 1; i <= n; i++) {
    int count = 0;
    int num = i;
    while(num % 2 == 0) {
      num /= 2;
      count++;
    }
    if (max_c < count) {
      ans = i;
      max_c = count;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long K;

        public void Run()
        {
            {
                K = Input.ReadLong();
            }

            long x = 1;
            long inc = 1;
            while (K > 0)
            {
                bool flg = true;
                long s = Calc(x);

                for (long i = 1; i <= 10; i++)
                {
                    long xi = x + i * inc;
                    long si = Calc(xi);
                    if (x * si > s * xi)
                    {
                        flg = false;
                        break;
                    }
                }

                if (flg)
                {
                    Console.WriteLine(x);
                    K--;
                    x += inc;
                }
                else
                {
                    x -= inc;
                    inc *= 10;
                    x += inc;
                }
            }

        }

        public long Calc(long x)
        {
            long ret = 0;
            while (x > 0)
            {
                ret += x % 10;
                x /= 10;
            }

            return ret;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11092
// @ts-check

read(function(err, input) {
  var args = input.split(' ');
  var a = Number(args[0]);
  var b = Number(args[1]);
  harmony(a, b);
});

/**
 * @param {(err: Error | null, input?: string) => void} callback
 */
function read (callback) {
  var input = '';
  process.stdin.setEncoding('utf8');
  process.stdin.on('readable', () => {
    /** @type {string | Buffer} */
    var chunk;
    while ((chunk = process.stdin.read()) !== null) {
      input += chunk;
    }
  });

  process.stdin.on('end', () => {
    callback(null, input);
  });
  process.stdin.on('error', () => {
    var error = new Error('Failed to read from stdin');
    callback(error);
  });
}

/**
 * @param {number} a
 * @param {number} b
 */
function harmony(a, b) {
  var s = (a + b);
  if (s % 2 === 0) {
    var k = s / 2;
    console.log(k);
  } else {
    console.log('IMPOSSIBLE');
  }
}


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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
        return false;
}
ll isprime(ll n)
{
    ll ans=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            ans = i;
    }
    return ans;
}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%m;
    ll temp=power(a,b/2,m);
    if(b%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return ((((temp%m)*(temp%m))%m)*a%m)%m;
}

/*-----------------------------------------------------------------------------*/

ll c(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;

            else
                C[i][j] = (C[i - 1][j - 1]%MOD +
                          C[i - 1][j])%MOD;
        }
    }
    return C[n][k]%MOD;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {

        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;


        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
ll func(ll n)
{
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i/10==0)
                ans+=1+func(i)*func(n/i);
            else
                ans+=func(i)*func(n/i);
        }
    }
    return ans;
}
ll dp[205][205][205];
ll check(ll red[],ll gre[],ll blu[],ll r,ll g,ll b,ll i,ll j,ll k)
{
   if(dp[i][j][k]!=-1)
    return dp[i][j][k]; 
   if(i<r&&j<g&&k<b)
   {
       return dp[i][j][k]=max(red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k),max(gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1),blu[k]*red[i]+check(red,gre,blu,r,g,b,i+1,j,k+1)));
   }
   else if(i<r&&j<g) 
   {
       return dp[i][j][k]=red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k);
   }
   else if(j<g&&k<b)
   {
       return dp[i][j][k]=gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1);
   }
   else if(i<r&&k<b)
   {
       return dp[i][j][k]=red[i]*blu[k]+check(red,gre,blu,r,g,b,i+1,j,k+1);
   }
   else
   {
       return 0;
   }
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        ll a[n+1];
        a[0]=0;
        for(ll i=1;i<=n;i++)
        {
           a[i]=a[i-1]+i;
           //cout<<a[i]<<" ";
        }
        ll ans=0;
        ll m=1000000007;
        for(ll i=k;i<=n+1;i++)
        {
           ll mn=a[i-1];
           ll mx;
           if(i==n+1)
            mx=a[n];
           else 
            mx=a[n]-a[n-i];
            ll p=mx-mn+1;
            ans+=p;
        }
        cout<<ans%m;
    }
}


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

int main() {
    ll N, K; cin >> N >> K;
    int A[N+1]; for (int i = 1; i <= N; i++) cin >> A[i];
    
    int tp[N+1]; tp[0] = 1;
    for (int i = 1; i < N+1; i++) tp[i] = A[tp[i-1]];
    
    vector<int> vis(N+1, -1);
    int fir, cyc;
    for (int i = 0; i <= N; i++) {
        if (vis[tp[i]] == -1) {
            vis[tp[i]] = i;
        } else {
            fir = vis[tp[i]];
            cyc = i - fir;
        }
    }
    if (K < N) cout << tp[K] << endl;
    else cout << tp[(K-fir)%cyc + fir] << endl;
}

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

int main(){
  int n;
  scanf("%d",&n);

  int x[n+1];
  int sum=0;
  for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
    sum+=x[i];}
  

  double temp=sum*1.0/n;
  int ans=sum/n;
  if(temp-ans*1.0 > (ans+1)*1.0-temp) ans++;
  int kai=0;
  for(int i=0;i<n;i++){
    int tmp=ans-x[i];
    kai+=tmp*tmp;}
  printf("%d\n",kai);

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int a,i,d,b=0;
    scanf("%d",&a);
    for(i=a;i>0;i=i/10)
    {
        d=i%10;
        if(d==7)
            b++;
    }
    if(b>0)
    {
        printf("Yes");
    }
    else
        printf("No");
}


Measured memory_bytes: 1688
package main

import (
        "bufio"
        "fmt"
        "os"
)

func solution(s string) string {
        var memo [26]int

        for _, r := range s {
                memo[r-'a']++
        }
        for i := range memo {
                if memo[i] == 0 {
                        return string(rune(i + 'a'))
                }
        }
        return "None"
}

func main() {
        var fp *os.File = os.Stdin
        reader := bufio.NewReaderSize(fp, 1024)
        s := readLine(reader)
        fmt.Println(solution(s))
}

func readLine(reader *bufio.Reader) string {
        buf := make([]byte, 0, 1024)

        for {
                l, p, _ := reader.ReadLine()

                buf = append(buf, l...)

                if !p {
                        break
                }
        }
        return string(buf)
}

Measured memory_bytes: 1280
N = int(input())

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

ans = 1
keta = 0
if 0 in A:
  print(0)
  exit()

for x in A:
  ans *= x
  keta += len(str(x))
  if ans > 1000000000000000000:
    print(-1)
    exit()

print(ans)


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
const ll mod = 1e9 + 7;
#define afdafafafdafaf y1;
int ar[maxn], n, m, k;


int main()
{
    ll n;
    scanf("%lld", &n); 
    ll ans = n;
    for(int i = 1; i <= sqrt(n); i++){
        if(n % i == 0)ans = min(ans, i + n / i - 2);
    }
    printf("%lld\n", ans);
 
    return 0;
}


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


int main(){
    ios_base::sync_with_stdio(false);
    ll health;
    cin>>health;
    int N = 0 ;
    cin>>N;

    ll sum = 0;
    int inp = 0;
    for(int i = 0 ; i < N ; i++){
        cin>>inp;
        sum += inp;
    }

    cout<<(sum >= health ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define ld long double 
#define float long double 
#define ll long long
#define int long long
#define vl vector<ll> 
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define MAXN 100009
#define CASET int ___T; scanf("%lld", &___T); for(int cs=1; cs <= ___T; cs++)
template<class T> bool umin(T& a, T b) { if(a > b){ a = b;return 1;}return 0;}
template<class T> bool umax(T& a, T b) { if(a < b){ a = b;return 1;}return 0;}
const int N = 200 * 1000 + 9;
const int  inf = 1e18;
const int mod=1e9+7;
int i,j,k;
void solve(){
int a, b; cin >> a>> b;
int aa = a * 100;
vl aaa ;
      
      
      int x; 
      if(aa % 8 == 0) x = (aa / 8) ;
      else x = (aa / 8) + 1;
      aaa.pb(x);
      int y = (x * 8 ) / 100;
      x++;
      while((x*8)/100 ==  y){
       aaa.pb(x);
       x++;
      }
vl bbb;
int bb = b * 100;
 bbb.pb(bb / 10);
 x = bb / 10;
 y = (x * 10)/ 100;
 x++;
 while((x*10)/100 == y){
   bbb.pb(x);
   x++;
 }
 
 sort(all(aaa));
 sort(all(bbb));
 for(i = 0;i < (int)aaa.size();i++){
           for(j = 0; j < (int)bbb.size();j++){
             if(aaa[i] == bbb[j]){
              cout << aaa[i]<< endl;
              return;
             }
           }
 }
 cout << -1 << endl;


 return ;
}
    signed main(){
   
    solve();
    
   
    return 0;
  }

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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

struct Solution
{
    Solution() {}
    void solveCase();
};

void Solution::solveCase()
{
    int h, w;
    cin >> h >> w;
    pair<int, int> src, dest;
    cin >> src.f >> src.s;
    cin >> dest.f >> dest.s;
    src.f--;
    src.s--;
    dest.f--;
    dest.s--;
    vector<string> matrix(h);
    for (auto &x : matrix)
        cin >> x;
    using elem = pair<int, pair<int, int>>;
    vector<vector<int>> dist(h, vector<int>(w, MOD));
    vector<vector<int>> vis(h, vector<int>(w, 0));
    using type = pair<int, pair<int, int>>;
    priority_queue<type, vector<type>, greater<type>> Q;
    // queue<pair<int, int>> Q;
    Q.push({0, {src.f, src.s}});
    dist[src.f][src.s] = 0;
    // vis[src.f][src.s] = 1;
    int a[] = {0, 0, 1, -1};
    int b[] = {1, -1, 0, 0};
    while (Q.size())
    {
        auto top = Q.top();
        Q.pop();
        // db(top, dist[top.f][top.s]);
        if (vis[top.s.f][top.s.s])
            continue;
        vis[top.s.f][top.s.s] = true;
        for (size_t i = 0; i < 4; i++)
        {
            int x = top.s.f + a[i];
            int y = top.s.s + b[i];
            // db(x, y);
            if (0 <= x && x < h && 0 <= y && y < w)
            {
                if (!vis[x][y] && matrix[x][y] == '.')
                {
                    if (top.f < dist[x][y])
                    {
                        dist[x][y] = top.f;
                        Q.push({dist[x][y], {x, y}});
                    }
                }
            }
        }

        for (int i = -2; i <= 2; i++)
            for (int j = -2; j <= 2; j++)
            {
                int x = top.s.f + i;
                int y = top.s.s + j;
                // db(x, y);
                if (0 <= x && x < h && 0 <= y && y < w)
                {
                    if (!vis[x][y] && matrix[x][y] == '.')
                    {
                        if (top.f + 1 < dist[x][y])
                        {
                            dist[x][y] = 1 + top.f;
                            Q.push({dist[x][y], {x, y}});
                        }
                    }
                }
            }
    }
    if (dist[dest.f][dest.s] == MOD)
        cout << -1 << '\n';
    else
    {
        cout << dist[dest.f][dest.s] << '\n';
    }
}

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 12516
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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 int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/
template<typename T>
vector<pair<T,int>> RunLengthEncoder(vector<T> &v){
    vector<pair<T,int>> RLE;
    int cnt = 1;
    for(int i = 0; i < (int)v.size(); ++i){
        if(i == (int)v.size()-1){
            RLE.push_back(make_pair(v[i], cnt));
            continue;
        }
        if(v[i] == v[i+1])cnt++;
        else{
            RLE.push_back(make_pair(v[i],cnt));
            cnt = 1;
        }
    }
    return RLE;
}

vector<pair<char,int>> RunLengthEncoder_ForString(string v){
    vector<pair<char,int>> RLE;
    int cnt = 1;
    for(int i = 0; i < (int)v.size(); ++i){
        if(i == (int)v.size()-1){
            RLE.push_back(make_pair(v[i], cnt));
            continue;
        }
        if(v[i] == v[i+1])cnt++;
        else{
            RLE.push_back(make_pair(v[i],cnt));
            cnt = 1;
        }
    }
    return RLE;
}
/*------------------------------------*/

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

    string S;
    cin>>S;
    int N = S.size();
    auto v = RunLengthEncoder_ForString(S);
    int M = v.size();
    //printpair(v);

    vector<int> ans(N,0);
    int start = 0;
    int finish = M-1;
    int idx = 0;
    if(v[0].first == 'L'){
        ans[0] =  v[0].second;
        start = 1;
        idx = v[0].second;
    }
    if(v[M-1].first=='R'){
        ans[N-1] = v[M-1].second;
        finish = M-2;
    }
    for(int i = start; i+1 <= finish; i+=2){
        int sum = v[i].second + v[i+1].second;
        idx += v[i].second-1;
        if(sum % 2 == 0){
            ans[idx] = sum/2;
            ans[idx+1] = sum/2;
        }
        else{
            if(v[i+1].second % 2 ==0){
                ans[idx] = sum-sum/2;
                ans[idx+1] =  sum/2;
            }
            else{
                ans[idx] = sum/2;
                ans[idx+1] =  sum - sum/2;
                
            }
        }
        idx += v[i+1].second+1;
    }
    rep(i,N){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 1732
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin>>a;
    vector<int> aho(a);
    for(int i=0;i<a;i++){
        cin>>aho.at(i);
    }
    reverse(aho.begin(),aho.end());
    for(int i =0;i<a;i++){
        cout<<aho.at(i);
        if(i<a-1)cout<<" ";
    }
    cout<<endl;
    return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int INF = 1<<29;

int dp[256][16][128];
int stones[256][16][2];
int col[256];

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) break;
  
    REP(i, N) {
      cin >> col[i];
      REP(j, col[i]) {
	REP(k, 2) cin >> stones[i][j][k];
      }
    }

    REP(i, N) REP(j, col[i]) REP(k, M+1) dp[i][j][k] = INF;
    REP(j, col[0]) dp[0][j][0] = 0;
    REP(j, col[1]) dp[1][j][1] = 0;
    REP(i, N-1) {
      REP(j, col[i]) {
	int x_now = stones[i][j][0], d_now = stones[i][j][1];
	REP(k, col[i+1]) {
	  int x_next = stones[i+1][k][0], d_next = stones[i+1][k][1];
	  int safe = (d_now + d_next) * abs(x_now - x_next);
	  REP(m, M+1) {
	    dp[i+1][k][m] = min(dp[i+1][k][m], dp[i][j][m] + safe);
	  }
	}
	if (i < N-2) {
	  REP(k, col[i+2]) {
	    int x_next = stones[i+2][k][0], d_next = stones[i+2][k][1];
	    int safe = (d_now + d_next) * abs(x_now - x_next);
	    REP(m, M) {
	      dp[i+2][k][m+1] = min(dp[i+2][k][m+1], dp[i][j][m] + safe);
	    }
	  }
	}
      }
    }

    int ans = INF;
    REP(j, col[N-1]) REP(m, M+1) ans = min(ans, dp[N-1][j][m]);
    REP(j, col[N-2]) REP(m, M) ans = min(ans, dp[N-2][j][m]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2412
#include<iostream>
#include<string>
#include<utility>
#include<queue>
using namespace std;
int main(){
  int n,q,time,cnt_time = 0;
  string name;
  queue<pair<string,int> > que;
  cin >> n >> q;
  for(int i=0;i<n;i++){
    cin >> name >> time;
    que.push(make_pair(name,time));
  }
  while(!que.empty()){
    pair<string,int> top = que.front();
    que.pop();
    if(top.second <= q){
      cnt_time += top.second;
      cout << top.first << " " << cnt_time << endl;
    }else{
      cnt_time += q;
      que.push(make_pair(top.first,top.second-q));
    }
  }
}



Measured memory_bytes: 6236
#include<cstdio>
#include<algorithm>
using namespace std;

const int MAXN=1e5+5;

int n,m;
int cnt[MAXN];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        cnt[u]++,cnt[v]++;
    }
    for(int i=1;i<=n;i++)
        if(cnt[i]&1) return puts("NO"),0;
    puts("YES");
}


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

#define int long long  
#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()
 
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846//20 decimals
#define MOD 1000000007
 

int32_t main(){
 
   
     IOS
        int n,m,ans=0;
        cin>>n>>m;
        priority_queue<int>cost;
        rep(i,0,n)
        {   
            int x;
            cin>>x;
            cost.push(x);
        }
        while(m--)
        {
            if (cost.empty()) break;
            int top;
            top=cost.top();
            cost.pop();
            top/=2;
            cost.push(top);
        }
        while(!cost.empty())
        {
            ans+=cost.top();
            cost.pop();
        }
        cout<<ans;
return 0;
}

Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

PI = 3.141592

N = int(input())
print(2 * PI * N)



# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 9524
program prob3
    implicit none
    integer :: n
    real(8), allocatable :: x(:), y(:)
    real(8) :: ans
    integer :: i, j
    read(*,*) n
    allocate(x(n), y(n))
    do i = 1, n
        read(*,*) x(i), y(i)
    end do
    ans = 0
    do i = 1, n
        do j = 1, n
            if(i == j) then
                cycle
            end if
            ans = ans + sqrt( (x(i) - x(j)) ** 2 + (y(i) - y(j)) ** 2  )
        end do
    end do
    ans = ans / dble(n)
    write(*,*) ans
    deallocate(x, y)
    stop
contains
end program prob3

Measured memory_bytes: 3052
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    ll ans=0;
    for(int i=0;i<n-1;i++){
        ans+=a[n-1-(i+1)/2];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4816
a, b, c, x, y = map(int, input().split())

ans = 0
if a + b >= 2 * c:
    if x >= y:
        ans += y * c * 2
        x -= y
        y = 0
        if a >= c * 2:
            ans += x * c * 2
        else:
            ans += x * a
    else:
        ans += x * c * 2
        y -= x
        x = 0
        if b >= c * 2:
            ans += y * c * 2
        else:
            ans += y * b
else:
    ans += x * a + y * b

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
bool ok[10000009];
long long k,i,X,ans,n,a[1000];
int main()
{
	cin>>X>>n;
	for(int m=1;m<=n;m++)
	{
		cin>>a[m];
		ok[a[m]]=true;
	}
	k=X;
	i=X;
	if(ok[X]==false)
	{
		cout<<X;
		return 0;
	}
	while(true)
	{
		k++;
		i--;
		if(ok[i]==false)
		{
			ans=i;
			break;
		}
		if(ok[k]==false)
		{
			ans=k;
			break;
		}
	}
	cout<<ans;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 59;

struct SegNode
{
  int64 v;

  SegNode(int64 v) : v(v) {}

  SegNode operator*(const SegNode &r) const
  {
    return (v < r.v ? *this : r);
  }
} e(INF);

struct SegmentTree
{
  int sz;
  vector< SegNode > seg;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, e);
  }

  void update(int k, const SegNode &x)
  {
    k += sz - 1;
    seg[k] = x;
    while(k > 0) {
      k = (k - 1) >> 1;
      seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
    }
  }

  SegNode query(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (e);
    if(a <= l && r <= b) return (seg[k]);
    return (query(a, b, 2 * k + 1, l, (l + r) >> 1) * query(a, b, 2 * k + 2, (l + r) >> 1, r));
  }

  SegNode query(int a, int b)
  {
    return (query(a, b, 0, 0, sz));
  }
};

int main()
{
  int N, Q, A, B, X[200001];
  scanf("%d %d %d %d", &N, &Q, &A, &X[0]);
  --A, --X[0];
  for(int i = 1; i <= Q; i++) {
    scanf("%d", &X[i]);
    --X[i];
  }

  /*
   * dp[A] = 0
   * dp[X[i-1]] = min(dp[X[i]-k]+ X[i]-k, dp[l-X[i]]+ l-X[i])  // 直前じゃないやつを動かす
   * dp[*] += abs(X[i]-X[i-1])  // 直前のやつを動かす   ここで (k≦X[i], X[i]≦l)
   */

  /*
   * dp[X[i-1]] = {dp[X[i]-k]+X[i]-k} = {dp[X[i]-k]-k} + X[i]
   * dp[X[i-1]] = {dp[l-X[i]]+l-X[i]} = {dp[l-X[i]]+l} - X[i]
   */

  SegmentTree seg1(N), seg2(N);
  int64 dp[200001];
  fill_n(dp, 200001, INF);

  auto push = [&](int x, int64 y)
  {
    if(y < dp[x]) {
      dp[x] = y;
      seg1.update(x, y - x);
      seg2.update(x, y + x);
    }
  };

  push(A, 0);

  int64 all = 0;
  for(int i = 1; i <= Q; i++) {
    int64 curr = min(seg1.query(0, X[i]).v + X[i], seg2.query(X[i], N).v - X[i]);
    all += abs(X[i] - X[i - 1]);
    curr -= abs(X[i] - X[i - 1]);
    push(X[i - 1], curr);
  }
  int64 ret = INF;
  for(int i = 0; i < N; i++) {
    ret = min(ret, dp[i] + all);
  }
  cout << ret << endl;
}


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dc[4] = {1, -1, 0,  0};
const int dr[4] = {0,  0, 1, -1};
//const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
//const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int k,s;
    cin >> k >> s;
    
    int cnt = 0;
    irep2(x,0,k) {
        irep2(y,0,k) {
            int z = s - x - y;
            if(0 <= z  && z <= k) { 
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}
/*atcoder*/


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol mem[100010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,c,d;
    cin >>n;
    if(n%2==0) cout <<n/2<<'\n';
    else cout <<n/2+1<<'\n';
    return (0);
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(A: Long, B: Long){
    println(if (B % A == 0L) A+B else B -A)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(A, B)
}



Measured memory_bytes: 31388
import java.util.*;

public class Main {

    static int N;
    static int M;
    static int V;
    static int P;
    static Long[] A;

    public static boolean isOK(int index) {
        long max = (long)A[index]+M;
        long tmp = (long)(P-1)+(long)((long)N-index)-(long)V;

        // System.out.println("index, max, tmp: "+index+" "+max+" "+tmp);
        // if (P>=V-1) {
        //     if (max>=(long)A[P-1]) return true;
        // }
        if (max<(long)A[P-1]) return false;

        if (tmp>=0) {
            if (max>=(long)A[P-1]) return true;
            else return false;
        } else {

            long sum = 0L;

            // if (index<=P) return true;

            for (int i=P-1;i<index;i++) {
                sum = sum+(long)A[i];
            }
            // System.out.println("sum "+sum);
            // System.out.println("max_"+(max*(index-(P-1))));
            // System.out.println("tmp_M "+(-tmp*M));
            // System.out.println(max*(index-(P-1))-(sum-tmp*M));
            if ((sum-tmp*M) <= max*(index-(P-1))) return true;
            else return false;

        }
    }

    public static int binary_search() {
        // long right = -1;
        long right = P-1;
        long left = N;

        while (Math.abs(right - left) > 1) {
            long mid = left + (right - left) / 2;

            if (isOK((int)mid)) right = mid;
            else left = mid;
        }
        return (int)right;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        M = Integer.parseInt(sc.next());
        V = Integer.parseInt(sc.next());
        P = Integer.parseInt(sc.next());
        A = new Long[N];
        for (int i=0;i<N;i++) {
            A[i] = Long.parseLong(sc.next());
        }
        Arrays.sort(A, (o1, o2)->Long.compare(o2, o1));
        // System.out.println(Arrays.toString(A));
        System.out.println(binary_search()+1);
    }
}

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


int main(){

vector<string> sample(4);
sample = {"dream","dreamer","erase","eraser"};

string test;
cin >> test;


//文字列の反転
reverse(test.begin(),test.end());

for (int i = 0;i <4;i++) reverse(sample[i].begin(),sample[i].end());

bool can1 = true;
    for (int i =0; i < test.size();){
        bool can2 = false;
        for (int j=0; j < 4;j++){
            if (test.substr(i,sample[j].size()) == sample[j]){
            can2 = true;
            i += sample[j].size();
        }
    }
        if(can2 == false){
        can1=can2;
        break;
        }
    }
    if (can1) cout << "YES" << endl;
        else cout << "NO" <<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin >> n;
    int a = 0, b = 0, ab = 0, ans = 0;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int slen = s.length();
        if(s.at(0) == 'B' && s.at(slen-1) == 'A') ab++;
        else if(s.at(0) == 'B') b++;
        else if(s.at(slen-1) == 'A') a++;
        for(int i = 0; i < slen; ++i) {
            if(s.at(i) == 'A' && i < slen-1) {
                if(s.at(i+1) == 'B') ans++;
            }
        }
    }
    if(ab > 0) {
        ans += ab-1;
        if(a > 0) ans++, a--;
        if(b > 0) ans++, b--;
    }
    ans += min(a, b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int main() {
  int n,k,ans=0;
  cin >> n >> k;
  vector<int> l=input(n);
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  for(int i=0;i<k;i++){
    ans+=l[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
(defun sum-t ()
  (let ((n (read)))
    (cond 
      ((= n 1) (format t "~d" 0))
      ((= n 2) (format t "~d" 1))
      ((= (mod n 2) 0) (format t "~d" (/ (- n 2) 2)))
      (t (format t "~d" (/ (1- n) 2)))  )))

(sum-t)

Measured memory_bytes: 15720
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3624
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    ll A[N+1];REP(i,N+1)cin>>A[i];
    ll B[N];REP(i,N)cin>>B[i];
    ll cnt=0;
    REP(i,N){
        if(A[i]==B[i]){
            cnt+=A[i];
        }
        else if(A[i]<B[i]){
            B[i]-=A[i];
            cnt+=A[i];
            if(A[i+1]<=B[i]){
                cnt+=A[i+1];
                A[i+1]=0;
            }else{
                A[i+1]-=B[i];
                cnt+=B[i];
            }
        }
        else if(A[i]>B[i]){
            cnt+=B[i];
        }
    }
    cout<<cnt<<"\n";
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const ll INF = 1ll<<50;
 
// セグメント木(RMQ 対応)
// update: k 番目の値を a に変更
// query: [l, r) の区間の最大値を求める
template<typename T>
struct ST {
    vector<T> seg;
    int size;
    ST(int n) {
        size = 1;
        while (size < n) size *= 2;
        seg.resize(2*size-1, INF);
    }
    inline T merge(T x, T y) {
        return min(x, y);
    }
    void update(int k, T a) {
        k += size-1;
        seg[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            seg[k] = merge(seg[k*2+1], seg[k*2+2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b){
            return seg[k];
        }
        T vl = query(a, b, k*2+1, l, (l+r)/2);
        T vr = query(a, b, k*2+2, (l+r)/2, r);
        return merge(vl, vr);
    }
    T query(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};
 
const int MAXN = 100100;
ll N, E, T;
ll X[MAXN];
ll dp[MAXN];
 
int main() {
    cin >> N >> E >> T;
    for (int i = 0; i < N; i++)
        cin >> X[i];
    const ll INF = 1ll<<60;
    ST<ll> seg(N+10);
    for (int i = 0; i <= N; i++) {
        dp[i] = INF;
    }
    X[N] = E;
    dp[N] = 0;
    //seg.update(N, dp[N] + X[N] + 2*X[N-1]);
    for (int i = N-1; i >= 0; i--) {
        // まず T が支配的な部分を探索
        int low = i, high = N;
        while (high - low > 1) {
            const int med = (low + high) / 2;
            if (2*(X[med]-X[i]) <= T) {
                low = med;
            } else {
                high = med;
            }
        }
        // cout << low+1 << "a" << N << endl;
        dp[i] = dp[low+1] + X[low+1] - X[i] + T;
        dp[i] = min(dp[i], seg.query(low+1, N) - 3*X[i]);
        if (i) seg.update(i, dp[i+1] + 2*X[i] + X[i+1]);
        //cout << i << " " << dp[i] << endl;
    }
    cout << X[0] + dp[0] << endl;
    return 0;
}


Measured memory_bytes: 3840