akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  when (n /= (-1)) $ do
    mapM_ print $ solve n
    main

solve :: Int -> [Double]
solve n = (fromPolar . walk (n - 2)) (1.0, 0.0)

walk :: Int -> (Double,Double) -> (Double,Double)
walk n (r, a)
  | n == 0 = (nr, na)
  | otherwise = walk (n - 1) (nr, na)
  where
    nr = sqrt (r ^ 2 + 1.0)
    na = a + atan (1.0 / r)

fromPolar :: (Double,Double) -> [Double]
fromPolar (r,a) = [r * cos a, r * sin a]

toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4804
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;
const int large = 2e5+1;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k,c; cin >> n >> c >> k;
    bool work[200000];
    int suffix[2*large],prefix[2*large]; m0(suffix); m0(prefix);
    FOR(i,n){
        char a; cin >> a;
        work[i] = !(a-'o');
    }
    FOR(i,n){
        int pos = large +i;
        if(work[i]){
            prefix[pos] = 1+prefix[pos-k-1];
        }else prefix[pos] = prefix[pos-1];
    }
    for(int i = n-1; i>= 0; i--){
        if(work[i]) suffix[i] = 1+suffix[i+k+1];
        else suffix[i] = suffix[i+1];
    }
    bool good[200000]; m0(good);
    int last = -k-5;
    FOR(i,n){
        if(work[i]){
            if(prefix[large+i-k-1]+suffix[i+k+1] == c-1){
                if(i-last <= k){
                    good[last] = 0;
                    last = i;
                }else{
                    good[i] = 1;
                    last = i;
                }
            }
        }
    }
    FOR(i,n){
        if(good[i]) cout << i+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let rec factorize acc i n =
  if n <= 1 then acc
  else if n < i * i then n :: acc
  else if n mod i = 0 then factorize (i :: acc) i (n / i)
  else factorize acc (i + 1) n
let factorize n =
  match factorize [] 2 n with
  | [] -> []
  | p :: ps ->
      let (acc, p, n) = List.fold_left (fun (acc, p, n) q ->
        if p = q
        then (acc, p, n + 1)
        else ((p, n) :: acc, q, 1)) ([], p, 1) ps in
      (p, n) :: acc

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let factors = Array.make 1000000 0 in
  Array.iter (fun a ->
    List.iter (fun (p, n) -> factors.(p) <- max n factors.(p)) @@ factorize a) as_;
  let lcm =
    Array.fold_left ( *^ ) 1 @@
    Array.init 1000000 @@ fun p -> power ( *^ ) 1 p factors.(p) in
  Printf.printf "%d\n" @@
  Array.fold_right (fun a -> ( +^ ) @@ power ( *^ ) lcm a (m - 2)) as_ 0



Measured memory_bytes: 22396
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>

using namespace std;
int main(void){
    // Your code here!
int a,b;
cin >> a >> b;
if(b % a == 0){
    cout << a + b << endl;;
}
else{
    cout << b - a << endl;
}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9	
#define MOD 1000000007
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int n;
VI nums;
void frog1() {
	cin >> n;
	nums.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	VI dp(n+1,0);
	int res = 0;
	dp[n-1] = 0;
	for(int i = n-2; i >= 0; i--) {
		int ans = INT_MAX;
		if(i + 2 <= n-1) {
			ans = abs(nums[i+2]-nums[i]) + dp[i+2];
		}
		ans = min(ans,abs(nums[i+1]-nums[i]) + dp[i+1]);
		dp[i] = ans;
	}
	// for(int i: dp) cout << i << " ";
		// cout << endl;
	cout << dp[0];
}

void solve() {
	frog1();
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3960
import sys
d1 = {
' ':'101'
,'\'':'000000'
,',':'000011'
,'-':'10010001'
,'.':'010001'
,'?':'000001'
,'A':'100101'
,'B':'10011010'
,'C':'0101'
,'D':'0001'
,'E':'110'
,'F':'01001'
,'G':'10011011'
,'H':'010000'
,'I':'0111'
,'J':'10011000'
,'K':'0110'
,'L':'00100'
,'M':'10011001'
,'N':'10011110'
,'O':'00101'
,'P':'111'
,'Q':'10011111'
,'R':'1000'
,'S':'00110'
,'T':'00111'
,'U':'10011100'
,'V':'10011101'
,'W':'000010'
,'X':'10010010'
,'Y':'10010011'
,'Z':'10010000'
}

d2 = {
'00000':'A'
,'00001':'B'
,'00010':'C'
,'00011':'D'
,'00100':'E'
,'00101':'F'
,'00110':'G'
,'00111':'H'
,'01000':'I'
,'01001':'J'
,'01010':'K'
,'01011':'L'
,'01100':'M'
,'01101':'N'
,'01110':'O'
,'01111':'P'
,'10000':'Q'
,'10001':'R'
,'10010':'S'
,'10011':'T'
,'10100':'U'
,'10101':'V'
,'10110':'W'
,'10111':'X'
,'11000':'Y'
,'11001':'Z'
,'11010':' '
,'11011':'.'
,'11100':','
,'11101':'-'
,'11110':'\''
,'11111':'?'
}
for line in sys.stdin:
    s1 = ''
    s2 = ''
    for s in line.rstrip('\n'):
        s1 += d1[s]
    s1 += '0'*(-len(s1)%5)
    
    for i in range(len(s1)//5):
        s2 += d2[s1[i*5:(i+1)*5]]
        
    print(s2)

Measured memory_bytes: 7464
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	while(1){
		g=0;
		scanf("%d %d",&a,&s);
		if(a==0&&s==0)
			break;
		for(i=1;i<=a;i++){
			for(j=i+1;j<=a;j++){
				for(h=j+1;h<=a;h++){
					if(h!=i&&i!=j&&h!=j){
						if(h+j+i==s)
							g++;
					}
				}
			}
		}
		printf("%d\n",g);
	}
	return 0;
}

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

int main(){
    
    int N;
    cin >> N;
    long long A[N],B[N];
    
    for(int i = 0; i < N;i++)cin >> A[i] >> B[i];
    
    
    long long cnt = 0;
    for(int i = N -1 ; i >= 0;i--){
        
        if((A[i]+cnt)%B[i]==0)continue;
        cnt += B[i] * ((A[i]+cnt)/B[i] + 1) - (A[i]+cnt);
        //cout << cnt << endl;
    }
    cout << cnt << endl;

}

    
    



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

int main(void) {
	int N;
	scanf("%d", &N);
	int L[100];
	for (int i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}
	sort(L, L + N);
	int sum = 0;
	for (int i = 0; i < N - 1; i++) {
		sum += L[i];
	}
	printf(L[N - 1] < sum ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3808
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    string S;
    cin >> S;

    string divide[4] = {"remaerd", "maerd", "esare", "resare"};
    reverse(S.begin(), S.end());

    int i = 0;
    while (i < S.size()) {
        int checker = 0;
        for (int j = 0; j < 4; j++) {
            if (S.substr(i, divide[j].size()) == divide[j]) {
                i += divide[j].size();
                checker++;
                if (checker != 0) {
                    break;
                }
            }
        }
        if (checker == 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
def main():
    N = int(input())
    ans = 0
    for i in range(1,N+1,2):
        d_array = []
        for j in range(1, i+1):
            if i % j == 0:
                d_array.append(j)
        if len(d_array) == 8:
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
xy.sort()

one=-float('inf')
two=-float('inf')
ans=0
for i in range(n):
    x,y=xy[i]
    ans=max(ans,x+max(y+one,two-y))
    one=max(one,-(x+y))
    two=max(two,y-x)
print(ans)

Measured memory_bytes: 102584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	#define LOCAL_INPUT_FILE
#else
	//#define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	int n; cin >> n;
	vector<int64_t> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector< pair<int64_t, int64_t> > dp[20][20];
	for (int i = 0; i < n; ++i) {
		dp[i][i].emplace_back(a[i], a[i]);
	}
	for (int i = 1; i < n; ++i) {
		dp[i-1][i].emplace_back(a[i-1], a[i]);
	}
	for (int len = 2; len < n; ++len) {
		for (int i = 0, j = len; j < n; ++i, ++j) {
			vector< pair<int64_t, int64_t> > cand;
			for (int k = i+1; k < j; ++k) {
				auto v1 = dp[i][k], v2 = dp[k][j];
				for (auto x : v1) {
					for (auto y : v2) {
						int64_t l = x.first, m = x.second + y.first - a[k], r = y.second;
						cand.emplace_back(l+m, r+m);
					}
				}
			}
			sort(begin(cand), end(cand));
			for (int k = 0; k < int(cand.size()); ++k) {
				if (k != 0 && dp[i][j].back().second <= cand[k].second) {
					continue;
				}
				dp[i][j].push_back(cand[k]);
			}
			
			/*cout << i << " " << j << " :: ";
			for (auto it : dp[i][j]) {
				cout << "{" << it.first << ", " << it.second << "}" << " ";
			}
			cout << endl;*/
		}
	}
	
	int64_t res = LLONG_MAX;
	for (auto it : dp[0][n-1]) {
		res = min(res, it.first+it.second);
	}
	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
N, K = list(map(int, readline().split()))
h = []
for _ in range(N):
    h.append(int(readline()))

h.sort()

L = 0
resp = 10**9 + 1
while L + K <= N:
    b = h[L + K - 1] - h[L]
    if resp > b:
        resp = b
    # print(h[L + K - 1],h[L],resp)
    L += 1

print(resp)

Measured memory_bytes: 7384
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	if (b-a)%2 == 0 {
		fmt.Println((b - a) / 2)
	} else {
		fmt.Println(min(a-1, n-b) + 1 + (b-a-1)/2)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 1772
/* ****_hela**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int k,j=0;
		cin>>k;
		vector<ll int>q;
		q.pb(1);q.pb(2);q.pb(3);q.pb(4);q.pb(5);q.pb(6);q.pb(7);q.pb(8);q.pb(9);
		while(q.size()<k)
		{	
			ll int d=q[j]%10;
			if(d-1>=0)
			{ll int a=10*q[j]+(d-1);q.pb(a);}
			ll int b=10*q[j]+d;q.pb(b);
			if(d+1<=9)
			{ll int c=10*q[j]+(d+1);
			q.pb(c);}
			j++; 
		}	
		cout<<q[k-1];
	}
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

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

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数

int main()
{
	int n, k;
	vector<int> a,b;

	cin >> n >> k;

	int sum=0;
	REP(i, n) {
		int x;
		cin >> x;
		a.push_back(x);
		sum += x;
	}
	REPS(i, sum) {
		if (sum%i != 0)continue;
		
		b.clear();
		REP(j, n) {
			b.push_back(a[j]%(sum/i));
		}
		sort(All(b));
		vector<int> b1 = { b[0] };
		vector<int> b2 = { sum / i - b[0] };
		REPS(j, n - 1) {
			b1.push_back(b1[j - 1] + b[j]);
			b2.push_back(b2[j - 1] + sum / i - b[j]);
		}
		
		REPS(j, n - 1) {
			ll ac1 = b1[j-1];
			ll ac2 = b2[n-1]-b2[j-1];
			//printf("%d %d|%d : ac1=%lld,ac2=%lld\n", sum / i, j - 1, j, ac1, ac2);
			if (ac1 == ac2 && ac1 <= k) {
				cout << sum / i << endl;
				return 0;
			}
		}
	}

	cout << 1 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ld>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

vector<ld> dijkstra(int s,WeightedGraph  & G){
  using P = pair<ld, int>;
  int n=G.size();
  vector<ld> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      ld c=e.second;
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  return ds;
}

ld dist(ld x1, ld y1, ld x2, ld y2){
  return sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main(){
  ld sx,sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  int n;
  cin >> n;
  vector<ld> x(n), y(n), r(n);
  for(int i = 0; i < n; ++i){
    cin >> x[i] >> y[i] >> r[i];
  }
  ld m = 0.0;
  WeightedGraph G(n+2);
  ld tmp = dist(sx, sy, gx, gy);
  G[0].push_back({n+1, tmp});
  for(int i = 0; i < n; ++i){
    ld d = dist(sx, sy, x[i], y[i]);
    G[0].push_back({i+1, max(m, d-r[i])});
    
    d = dist(gx, gy, x[i], y[i]);
    G[i+1].push_back({n+1, max(m, d-r[i])});
  }
  for(int i = 0; i < n; ++i){
    for(int j = i+1; j < n; ++j){
      ld d = dist(x[i], y[i], x[j], y[j]);
      G[i+1].push_back({j+1, max(m, d-r[i]-r[j])});
      G[j+1].push_back({i+1, max(m, d-r[i]-r[j])});
    }
  }
  auto v = dijkstra(0, G);
  cout <<fixed << setprecision(10)<<  v[n+1] << endl;
}


Measured memory_bytes: 42384
h, w = [int(i) for i in input().split()]
while h or w:
    for i in range(h):
        if not i or i == h - 1:
            print("#" * w)
        else:
            print("#" + "." * (w - 2) + "#")
    print()
    h, w = [int(i) for i in input().split()]



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

int main(){
  int n,k,t,maxi;
  cin >> t;
  while(t--){
    cin >> n >> k;
    vector <int> dis(n);
    vector <int> subt;
    for(int i=0;i<n;i++) cin >> dis[i];
    if(n == 1 || k >= n){
      cout << "0" << endl; continue;
    }
    maxi = dis[n-1] - dis[0];
    for(int i=1;i<n;i++) subt.push_back(dis[i] - dis[i-1]);
    sort(subt.begin(),subt.end(),greater<int>());
    for(int i=0;i<k-1;i++) maxi -= subt[i];
    cout << maxi << endl;
  }
}

Measured memory_bytes: 2392
using System;
using System.Linq;

class PG{
    public static void Main(string[] args){
        int n=int.Parse(Console.ReadLine());
        var point=new int[2]{0,0};
        for(int i=0;i<n;i++){
            string[] strs=Console.ReadLine().Split(' ').ToArray();
            int judge=String.Compare(strs[0],strs[1]);
            if(judge==0){
                point[0]++;
                point[1]++;
            }else if(judge>0){
                point[0]+=3;
            }else{
                point[1]+=3;
            }
        }
        Console.WriteLine(String.Join(" ", point));
    }
}


Measured memory_bytes: 17076
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int n;
cin >> n;
vi a(n+1),b(n);
rep(i,n+1)cin >> a[i];
rep(i,n)cin >> b[i];
ll ans=0;

rep(i,n){
    ll temp;
    temp = min(a[i],b[i]);
    ans += temp;
    a[i]-=temp;
    b[i]-=temp;
    temp = min(a[i+1],b[i]);
    ans += temp;
    a[i+1]-=temp;
    b[i]-=temp; 
}
fin(ans);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 1024
using System;
 
namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      string line = Console.ReadLine();
    　string[] array =line.Split(' ');
    　int h = int.Parse(array[0]);
    　int a = int.Parse(array[1]);
    　int count = 1;
      while (h > a*count){
         count++;
       }
      Console.WriteLine(count);
    }
  }
}

Measured memory_bytes: 13140
n,m = map(int, input().split())
a = [[False for _ in range(m)] for _ in range(n)]
for i in range(n):
  l = list(map(int, input().split()))
  for j in l[1:]:
    a[i-1][j-1] = True

ans = 0
for j in range(m):
  if all([a[i][j] for i in range(n)]): ans+=1
print(ans)

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

const int maxN = 2e5 + 10, INF = 1e9;

int n;
int f[maxN + 1][2], lst[maxN + 1][2];//0: D, 1: P
char s[maxN + 1], ans[maxN + 1];

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	
	for(int i = 1; i <= n; i++) f[i][0] = f[i][1] = -INF;

	f[0][0] = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] != 'P')
		{
			if(f[i - 1][0] + 1 > f[i - 1][1] + 2) lst[i][0] = 0, f[i][0] = f[i - 1][0] + 1;
			else lst[i][0] = 1, f[i][0] = f[i - 1][1] + 2;
		}
		if(s[i] != 'D')
		{
			if(f[i - 1][0] > f[i - 1][1]) lst[i][1] = 0, f[i][1] = f[i - 1][0];
			else lst[i][1] = 1, f[i][1] = f[i - 1][1];
		}	
	}

	int x = f[n][0] > f[n][1] ? 0 : 1;
	ans[n] = x ? 'P' : 'D';
	for(int i = n - 1; i >= 1; i--)
	{
		x = lst[i + 1][x];
		ans[i] = x ? 'P' : 'D';
	}

	printf("%s\n", ans + 1);
	return 0;
}


Measured memory_bytes: 7196
#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(2050);
const int MOD(1000000000 + 7);
typedef long long int LL;

constexpr int Mult(int a, int b)
{
	return (a * 1LL) * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

/*
队列是一个单谷序列：可以以1为分界点，左边是一个下降序列、右边是一个上升序列
存在一个分界线，分界线左边的元素都是从队头取出、分界线右边的元素都是从队尾取出。只考虑分界线在1右边的情况，在1左边可以把队列翻转
设分界线的位置为p，有Q[x <= p] = 1。同时Q[1 ~ p]是一个以1为谷的单谷序列，Q[p + 1 ~ N]是一个上升序列且满足Q[p] < Q[p + 1]
把数取出得到A的过程，本质就是把Q[p + 1 ~ N]翻转得到一个下降序列后插入到Q[1 ~ p]中的过程。考虑最终得到的序列满足哪些性质
(1)A[k] = 1。这是题目要求的条件
(2)A[1 ~ k]可以划分成至多2个下降序列。因为A[1 ~ k]是由Q[1 ~ x]（一个下降序列）插入一个下降序列得到的
(3)对于所有k + 1 <= i <= N，A[i]要么是后缀最大值，要么是后缀最小值。因为取出1之后Q是一个上升序列，每次取头就是后缀最小值、取尾就是后缀最大值
(4)如果A[1 ~ k]不是1个下降序列而是被划分成了2个下降序列，那么存在一个下降序列的最小值 > max{A[k + 1], A[k + 2], ..., A[N]}
   因为该下降序列是Q[N ~ p + 1]的一个前缀，其最小值一定大于Q[N ~ p + 1]剩下的部分和Q[x + 1 ~ p]
*/
/*
首先考虑填入A[1 ~ k]，使得满足条件(1)、(2)和(4)。考虑一个按照N ~ 1的顺序把数填进两个下降子序列的过程
这里称结尾较大的下降子序列为A序列，结尾较小的下降子序列为B序列。显然大于A序列的结尾的数都被填入，否则一定不满足条件(4) 
设F[i][k][0 / 1]表示填到了i，A序列的结尾到i之间有k个数没有被填入，能否走(3)转移的方案数。这里转移分为(3)种：
(1)不填i，F[i][k][0 / 1] -> F[i + 1][k + 1][0]
(2)填i到B序列中，F[i][k][0 / 1] -> F[i + 1][k][1]
(3)填小于A序列结尾最大的没有被填的数到A序列中。F[i][k][1] -> F[i][k - 1][1]
最后再填入A[k + 1 ~ N]，考虑从后往前填数，每次填了的数在剩下的数中是一个区间，方案数显然是2^(区间长度 - 1) 
*/

int N, K, power[Max_N], F[Max_N][Max_N][2];

inline void upd(int &a, int b)
{
	a = Add(a, b);
}

int main()
{
	scanf("%d%d", &N, &K);
	power[0] = 1;
	for (int i = 1;i <= N;++i)
		power[i] = Add(power[i - 1], power[i - 1]);
	F[N][0][1] = 1;
	for (int i = N;i >= 1;--i)
		for (int k = N;k >= 0;--k)
		{
			if (F[i][k][0])
			{
				upd(F[i - 1][k + 1][0], F[i][k][0]);
				upd(F[i - 1][k][1], F[i][k][0]);
			}
			if (F[i][k][1])
			{
				upd(F[i - 1][k + 1][0], F[i][k][1]);
				upd(F[i - 1][k][1], F[i][k][1]);
				if (k >= 1)
					upd(F[i][k - 1][1], F[i][k][1]);
			}
		}
	printf("%d", Mult(F[0][N - (K - 1)][0], power[max(0, N - K - 1)]));
	return 0;
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  ll dp[100][2];
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  rep(i, 0, 50) {
    ll mask = 1LL << (50 - i - 1);
    int cnt = 0;
    rep(j, 0, N) if(A[j] & mask) cnt++;
    ll cost0 = mask * cnt;
    ll cost1 = mask * (N - cnt);
    if(dp[i][1] != -1) chmax(dp[i + 1][1], dp[i][1] + max(cost0, cost1));
    if(dp[i][0] != -1){
      if(K & mask) {
        chmax(dp[i + 1][0], dp[i][0] + cost1);
        chmax(dp[i + 1][1], dp[i][0] + cost0);
      } else {
        chmax(dp[i + 1][0], dp[i][0] + cost0);
      }
    }
  }
  cout << max(dp[50][0], dp[50][1]) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  int i,n,x,y,t,nt,nx,ny,tmp;
  scanf("%d",&n);
  nt=0;nx=0;ny=0;
  for (i=0;i<n;i++)
  {
    scanf("%d%d%d",&t,&x,&y);
    tmp=abs(x-nx)+abs(y-ny);
    if( (t-nt>=tmp)&&((t-nt)%2==tmp%2))
    {
    }
    else
    {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func abs(n int64) int64 {
	if n >= 0 {
		return n
	} else {
		return -n
	}
}

func main() {
	var x, k, d int64
	fmt.Scan(&x)
	fmt.Scan(&k)
	fmt.Scan(&d)
	ans := x

	if abs(x) > abs(k*d) {
		ans = abs(x) - abs(k*d)
	} else {
		if (k-abs(x)/abs(d))%2 == 0 {
			ans = abs(x) % abs(d)
		} else {
			temp := abs(x) % abs(d)
			if abs(temp+d) < abs(temp-d) {
				ans = abs(temp + d)
			} else {
				ans = abs(temp - d)
			}
		}
	}

	fmt.Println(abs(ans))
}


Measured memory_bytes: 1768
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
#include <algorithm>
#include <math.h> 
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
    string s;
    cin >> s;
    for (int i = 1; i <= s.length(); i++) {
        cout << "x";
    }
    cout << endl;
}


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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> x(4);
    for(int i = 0; i < 4; ++i){
        x.at(3 - i) = n % 10;
        n /= 10;
    }

    for(int i = 0; i < 8; ++i){
        ll tmp = x.at(0);
        for(int j = 0; j < 3; ++j){
            if((i >> j) & 1){
                tmp += x.at(j + 1);
            }else{
                tmp -= x.at(j + 1);
            }
        }
        if(tmp == 7){
            cout << x.at(0);
            for(int j = 0; j < 3; ++j){
                if((i >> j) & 1){
                    cout << '+';
                }else{
                    cout << '-';
                }
                cout << x.at(j + 1);
            }
            cout << "=7" << endl;
            break;
        }
    }
    return 0;
}

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

int main(){
	string S; int Q; cin>>S>>Q;
	deque<char> s;
	for(auto c:S) s.push_back(c);
	int odd = 0;
	while(Q--){
		int t; cin>>t; t--;
		if(t){//type2
			int f; char c; cin>>f>>c; f--;
			if(odd ^ f) s.push_back(c);
			else s.push_front(c);
		}
		else odd ^= 1;//type1
	}
	string ans;
	if(odd) reverse(s.begin(), s.end());
	for(auto c:s) ans += c;
	cout<<ans<<endl;
}

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

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, int>mp;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }

    for (int i = 1; i <= N; i++) {
        if (mp[i] % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 4992
n,*a=map(int,open(0).read().split())
sumcount=0
for s in range(n*2-1,-1,-2):
  hidari=a[s-1]+sumcount
  if hidari%a[s]!=0 and hidari//a[s]==0:
    sumcount+=a[s]-hidari
  if hidari%a[s]!=0 and hidari//a[s]!=0:
    sumcount+=(hidari//a[s]+1)*a[s]-hidari
print(sumcount)

Measured memory_bytes: 25124
import java.util.*;
public class Main{


public static void main (String []args)
{
	Scanner scan=new Scanner(System.in);
	//long t=scan.nextLong();
	//long ways[]=new long[1000000000];
	//ways[1]=1;
	//ways[i]=ways[i-1]*2;
	
	//while(t-->0){
         int r=scan.nextInt();
         int c=scan.nextInt();
         char m[][]=new char[r][c];
      //   long v[]=new long[n];
         // int c[]=new int[n];
        // int dp[]=new int[n];
        for(int i=0;i<r;i++)
       {  String str=scan.next();
		   for(int j=0;j<c;j++)
		   m[i][j]=str.charAt(j);
          
            }
       
	long dp[][]=new long[r][c];
		
       
	 for(int i=0;i<r;i++)
	 {for( int j=0;j<c;j++ )
		 { if(m[i][j]!='#')
			{ if(i==0&& j==0)dp[i][j]=1;
			 
			 if(i==0&&j>0)
			 dp[i][j]=dp[i][j-1];
			 if(j==0&&i>0)
			 dp[i][j]=dp[i-1][j];
			 if(i>0&&j>0)
			 dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
			 
		    }
			 }   
		}
	
	
         
         System.out.println(dp[r-1][c-1]);
//}//
}
}


Measured memory_bytes: 41052
//#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;
using namespace std;
typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;
const int N = 2e5 + 123 ;
int n , m , p[N];
vector < int > gr[N] ;
set < int > st1 , st2;
bool was[N];
void dfs(int u){
	was[u] = 1;
	st1.insert(u) , st2.insert(p[u]);
	for(auto to : gr[u])
		if(!was[to])
			dfs(to);
}
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i++)
		cin >> p[i];
	for(int i = 1 ; i <= m ; i++){
		int u , v;
		cin >> u >> v;
		gr[u].pb(v);
		gr[v].pb(u);	
	}
	int ans = 0;
	for(int i = 1 ; i <= n ; i++){
		if(!was[i]){
			dfs(i);
			for(auto it : st1)
				if(st2.find((it)) != st2.end())
					ans++;
			st1.clear() , st2.clear();
		}
	}
	cout << ans;

}

Measured memory_bytes: 20480
#include <iostream>
#include <string>
#define MAX 200005
typedef long long ll;
using namespace std;
string S;
ll a[MAX];

int main() {
  cin >> S;
  ll w = 0;
  ll l = S.size();
  for (ll i = 0; i < l; i++) {
    if(S[i] == 'W') {
      a[w++] = i;
    }
  }
  if(w == l || w == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll counter = 0;
  for (ll i = 0;i < w; i++) {
    counter += (a[i]-i);
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;


    int counter=0;
    for(int i=0;i<N-2;i++){
        bool flag=((S[i]=='A')&&(S[i+1]=='B'))&&(S[i+2]=='C');
        if(flag){
            counter++;
        }
    }

    cout << counter << endl;
}
 

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scanf("%d %d\n", &N, &K)
	var R, S, P int
	fmt.Scanf("%d %d %d\n", &R, &S, &P)
	var TS string
	fmt.Scan(&TS)
	T := []rune(TS)

	p := 0
	m := map[int]bool{}
	for i := 0; i < N; i++ {
		t := string(T[i])
		if i+1 <= K {
			if string(t) == "r" {
				p += P
			} else if string(t) == "s" {
				p += R
			} else if string(t) == "p" {
				p += S
			}
			continue
		}
		tk := string(T[i-K])
		if t == tk && !m[i-K] {
			m[i] = true
			continue
		}
		if string(t) == "r" {
			p += P
		} else if string(t) == "s" {
			p += R
		} else if string(t) == "p" {
			p += S
		}
	}
	fmt.Println(p)
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)
#define PI acos(-1)

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    double _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>a>>b>>x;
    r=a*a*b;
    r-=x;
    if(r<=x)
    {
        r/=a;
        p=(2*r)/a;
        p/=a;
        cout<<fixed<<setprecision(10)<<atan(p)*180/PI<<endl;
    }
    else
    {
        r=x;
        r/=a;
        p=(2*r)/b;
        p/=b;
        cout<<fixed<<setprecision(10)<<90.0-(atan(p)*180/PI)<<endl;
    }


}



Measured memory_bytes: 4060
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
cnt = 0
for i in range(n):
    if i == n-1 and a[i] == i+1:
        cnt += 1
        continue
    if a[i] == i+1:
        a[i], a[i+1] = a[i+1], a[i]
        cnt += 1
print(cnt)

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

int main() {
  int N, K, L, sum;
  cin >> N >> K;
  sum = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    L = K - x;
    
    if (L < x) {
      sum += L;
    }
    
    else {
      sum += x;
    }
    
  }
  
  cout << sum * 2 << endl;

}


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

int main() {
  string s;
  cin >> s;
  
  int l;
  l = s.size();
  
  int i = 0;
  int x = 0;
  
  while( i < l){
    
    if((i % 2 == 0)&&(s.at(i)=='L')){
      break;
    }
    
    if((i % 2 == 1)&&(s.at(i) == 'R')){
      break;
    }
    
    else{
      i++;
      x++;
    }
  }
  
  if( x == l){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
    
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N,K;
	scanf("%d%d",&N,&K);
	if(N%2==0){
	if(N/2>=K)printf("YES\n");
	else printf("NO\n");
	}else{
		if(N/2+1>=K)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n,m;

  int p,y;
  map<int,vector<int> > mp;
  map<pii,pii> mp2;
  map<int,pii> vmp;

  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>p>>y;
    vmp[i]=pii(p,y);
    mp[p].pb(y);
  }
  for(auto x : mp){
    sort(x.second.begin(),x.second.end());
    for(int i=0;i<x.second.size();i++){
      mp2[pii(x.first,x.second[i])]=pii(x.first,i+1);
    }
    //cout<<x.first<<" "<<x.second.size()<<endl;
  }
  for(int i=0;i<m;i++){
    printf("%06d%06d\n",mp2[vmp[i]].first,mp2[vmp[i]].second);
  }
  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll r,d,x;
    cin>>r>>d>>x;
    for (int i = 0; i < 10; i++)
    {
        x=r*x-d;
        cout<<x<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()



int main() {
    ll n, h[505], ans=1;
    cin >> n;
    REP(i,n) cin >> h[i];
    sort(h,h+n);
    reverse(h,h+n);
    REP(i,n){
        ans += max(h[i]-i/4,0LL);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;
typedef long long ll;

template <typename T> void read(T &x) {
  x = 0;
  char c = getchar();
  T sig = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      sig = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  x *= sig;
}

class Solution {
public:
  void solve() {
    int n, k;
    read(n), read(k);
    vector<int> p(n), c(n);
    for (int i = 0; i < n; ++i)
      read(p[i]);
    for (int i = 0; i < n; ++i)
      read(c[i]);
    ll ans = LLONG_MIN;
    for (int i = 0; i < n; ++i) {
      vector<bool> vis(n);
      int idx = i;
      vector<ll> sum = {0}, hi = {LLONG_MIN};
      while (!vis[p[idx] - 1]) {
        idx = p[idx] - 1;
        vis[idx] = true;
        sum.emplace_back(sum.back() + c[idx]);
        hi.emplace_back(max(hi.back(), sum.back()));
      }
      int m = sum.size() - 1;
      int f = k / m, rem = k % m;
      ll result;
      if (f > 0)
        result = max(hi[m], max(sum[m] * f + (rem == 0 ? 0 : hi[rem]),
                                sum[m] * (f - 1) + hi[m]));
      else
        result = hi[rem];
      ans = max(ans, result);
    }
    printf("%lld", ans);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution solution = Solution();
  solution.solve();
}

Measured memory_bytes: 3868
#include <iostream>

using namespace std;


int main()
{
	int X;
	cin >> X;
	int m = 1;
	for (int i = 2; i < 32; i++) {
		int y = i * i;
		for (;y <= X; y *= i) {
			if (m < y) m = y;
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>

using namespace std;

void exchange(char a[], int left, int right) {
	int i = left, j = right;
	char temp;
	while (i < j) {
		temp = a[i];
		a[i] = a[j];
		a[j] = temp;
		i++;
		j--;
	}
}

void reserve(char a[], int n, int i) {
	exchange(a, 0, i - 1);
	exchange(a, i, n - 1);
	exchange(a, 0, n - 1);
	return;
}

int main() {
	char str[110], str1[110];
	int n, round = 0;
	scanf("%s", str);
	scanf("%s", str1);
	if (strlen(str) != strlen(str1)) {
		printf("No");
		return 0;
	}
	n = strlen(str);
	while (round <= n) {
		reserve(str, n, 1);
		if (strcmp(str, str1) == 0) {
			printf("Yes");
			return 0;
		}
		round++;
	}
	printf("No");
	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int main() {
  int x,y;
  cin >> x >> y;
  cout << (int)( x + y / 2 ) << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int il[4] = { 0 };
	int ir[4] = { 0 };
	double r, l;
	while (cin >> l >> r){
		if (l >= 1.1){
			il[0]++;
		}
		else if(l>=0.6){
			il[1]++;
		}
		else if (l >= 0.2){
			il[2]++;
		}
		else{
			il[3]++;
		}
		if (r >= 1.1){
			ir[0]++;
		}
		else if (r >= 0.6){
			ir[1]++;
		}
		else if (r >= 0.2){
			ir[2]++;
		}
		else{
			ir[3]++;
		}
	}
	for (int i = 0; i < 4; i++){
		cout << il[i] << " " << ir[i] << endl;
	}
}

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

int main(void){
    long long N;
    cin >> N;
    cout << N*(N+1)/2-(N/3)*(N/3+1)/2*3-(N/5)*(N/5+1)/2*5+(N/15)*(N/15+1)/2*15 << endl;
    return 0;
}

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

int main() {
	vector<int> rhythm(3);
	cin >> rhythm.at(0) >> rhythm.at(1) >> rhythm.at(2);
	int val5 = count(rhythm.begin(), rhythm.end(), 5);
	if (val5 == 2) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        long tmpA = sc.nextLong();
        long tmpB = sc.nextLong();
        long tmpC = sc.nextLong();
        long tmpD = sc.nextLong();
        long a = Math.max(tmpA * tmpC, tmpA * tmpD);
        long b = Math.max(tmpB * tmpC, tmpB * tmpD);

        System.out.println(Math.max(a, b));

        sc.close();
    }
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> a(n + 1, false);
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    a[t] = true;
  }
  vector<int> step(n + 2, 0);
  step[n] = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i]) continue;
    step[i] = (step[i + 1] + step[i + 2]) % MOD;
  }
  cout << step[0] << endl;
  return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
N=int(input())
table=[[] for i in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    table[a].append((b,c))
    table[b].append((a,c))
Q,K=map(int,input().split())
query=[[int(i)-1 for i in input().split()] for i in range(Q)]
K=K-1
H=[]
visit=[10**18]*(N)
visit[K]=0
heappush(H,(0,K))
while H:
    co,pt=heappop(H)
    if co>visit[pt]:
        continue
    for x,c in table[pt]:
        if visit[x]>visit[pt]+c:
            visit[x]=visit[pt]+c
            heappush(H,(visit[x],x))
for a,b in query:
    print(visit[a]+visit[b])

Measured memory_bytes: 64404
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

bool is_prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)
			return 0;
	}
	return 1;
}

int main()
{      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  while(true){
  	if(is_prime(n))
  		break;
  	else
  		n++;
  }
  cout<<n;
  return 0;
}

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

int main()
{
  string data[10] = {"0111111", "0000110", "1011011", "1001111", "1100110", "1101101", "1111101", "0100111", "1111111", "1101111"};
  int n;

  while( cin >> n, n != -1 ) {
    string now = "0000000";

    while( n-- ) {
      int num;
      string next = "0000000";

      cin >> num;
      for(int i=0; i<7; i++) {
	if( data[num][i] != now[i] ) next[i] = '1';
      }

      cout << next << endl;
      now = data[num];
    }
  }

  return 0;
}

Measured memory_bytes: 1200
s = gets.chomp.chars
ans = []
s.each_with_index do |le, idx|
  if s[idx] == s[idx + 1]
    ans = [idx, idx + 1]
    break
  end 
  if s[idx] == s[idx + 2]
    ans = [idx, idx + 2]
    break
  end
end

if ans.empty?
  puts "-1 -1"
else
  puts "#{ans[0] + 1} #{ans[1] + 1}"
end

Measured memory_bytes: 19132
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	int[][] kin = {
			{0,300,500,600,700,1350,1650},
			{300,0,350,450,600,1150,1500},
			{500,350,0,250,400,1000,1350},
			{600,450,250,0,250,850,1300},
			{700,600,400,250,0,600,1150},
			{1350,1150,1000,850,600,0,500},
			{1650,1500,1350,1300,1150,500,0}};
	int[][]kyori = {
			{0,6,13,18,23,43,58},
			{6,0,7,12,17,37,52},
			{13,7,0,5,10,30,45},
			{18,12,5,0,5,25,40},
			{23,17,10,5,0,20,35},
			{43,37,30,25,20,0,15},
			{58,52,45,40,35,15,0}};
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0163().doIt();
	}
	
	class AOJ0163{
		void doIt(){
			while(true){
				int startID = in.nextInt();
				if(startID == 0)return;
				Calc c = new Calc(startID, in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
				System.out.println(c.getResult());
			}
		}
		
		class Calc{
			int StartID,endID,sh,sm,eh,em;
			int time;
			boolean sw;
			public Calc(int _sID,int _sh,int _sm,int _eID,int _eh,int _em) {
				StartID = _sID;sh = _sh;sm = _sm;
				endID = _eID;eh = _eh;em = _em;
				sw = false;
				getTime();
			}
			
			int getResult(){
				int result = kin[StartID-1][endID-1];
				if(sw&&kyori[StartID-1][endID-1]<=40){
					result = result/2;
					if(result%50!=0){
						result+=(50-result%50);
					}
				}
				return result;
			}
			
			void getTime(){
				int stime = sh*60+sm;
				int etime = eh*60+em;
				time = etime-stime;
				if(stime>=1050&&stime<=1170)sw = true;
				if(etime>=1050&&etime<=1170)sw = true;
			}
		}
		
	}
	
}

Measured memory_bytes: 20492
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int main()
{
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2])printf("No\n");
	else printf("Yes\n");
	return 0;
}

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

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


	
	return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int MOD = 1e9 + 7;
const int MAX = 1e6 + 10;
const int INF = 0x3fffffff;
bool a[MAX];

int C(int a, int b)
{
    if(a < b)
        return 0;
    else return
        a/b+C(a/b, b);
}//求n！的情况下， b的阶数

void init()
{
    memset(a, true, sizeof(a));
    a[0] = a[1] = false;
    for(int i = 2; i <= MAX; i++)
    {
        if(a[i])
        {
            for(int j = i + i; j < MAX; j += i)
            {
                a[j] = false;
            }
        }
    }
}//把质数表打出

int main()
{
    int n;
    init();
    while(scanf("%d", &n) != EOF)
    {
        LL sum = 1;
        int i = 2;
        while(i <= n)
        {
            if(a[i])
            {
                sum = sum*(LL)(C(n,i) + 1) % MOD;
            }
            i++;
        }
        printf("%lld\n", sum);
    }

    return 0;
}


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

#define ll long long
#define vll vector<ll>
#define Map unordered_map<ll, ll>

int main()
{
    int n;
    long long d;
    cin >> n >> d;
    int ans = 0;
    while(n--)
    {
        long long x, y;
        cin >> x >> y;

        if(x * x + y * y <= d * d)
            ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3592
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;

int main() {
  long double L;
  cin >> L;
  L /= 3;
  long double ans = L * L * L;
  printf("%.6f\n", (double)ans);

  return 0;
}

Measured memory_bytes: 256
X = int(input())
a = [True for _ in range((10 ** 5) + 1)]

for i in range(2, int(100000 ** 0.5) + 1):
    j = 2
    while (i * j) <= 100000:
        a[i * j] = False
        j += 1

i = 0
while True:
    if 10 ** 5 < X + i:
        print(100003)
        exit()
    if a[X + i]:
        print(X + i)
        exit()
    i += 1

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

int main() {
  int n;
  cin >> n;
  double out;
  if(n%2 != 0){
    out = (n/2 + 1)/double(n);
  }else{
    out = (n/2)/double(n);
  }
  cout << setprecision(10) << out;
}

Measured memory_bytes: 256