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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

llint my_binary_search(llint ary[], llint key, llint left, llint right) {
	llint middle;
	if (right < left) {
		return -(INF64);
	} else {
		middle = left + (right - left) / 2;
		if (ary[middle] > key) {
			return my_binary_search(ary, key, left, middle - 1);
		} else if (ary[middle] < key) {
			return my_binary_search(ary, key, middle + 1, right);
		} else {
			return middle;
		}
	}
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}
	
	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	
	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}
	
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main (void)
{
	//INPUT
	llint A1,A2,A3;
	cin >> A1 >> A2 >> A3;
	
	llint sum = A1+A2+A3;
	
	if (sum <=21) {
		put("win");
	} else {
		put("bust");
	}
	return 0;
}






Measured memory_bytes: 256
# B
x1, y1, x2, y2 = map(int, input().split())

od = [x1+y1-y2, y1-x1+x2]
oc = [x2-y2+y1, -x1+x2+y2]

od = map(str, list(od))
oc = map(str, list(oc))

print(' '.join(list(oc)) +' ' + ' '.join(list(od)))

Measured memory_bytes: 3060
using System;

namespace abc139_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            int tap = 0;
            for(int outlet=1; outlet<b;)
            {
                outlet = outlet + a - 1;
                tap++;
            }
            Console.WriteLine(tap);
            Console.Read();

        }
    }
}


Measured memory_bytes: 13140
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import Data.Function
import Data.List
import Control.Applicative
main = do
    _ <- getLine
    cards <- map fromString . words <$> getLine
    let sSorted = fst $ selectionSort cards
        bSorted = snd $ bubbleSort cards
    putStrLn . unwords . map show $ bSorted
    putStrLn $ if stableSorted cards bSorted then "Stable" else "Not stable"
    putStrLn . unwords . map show $ sSorted
    putStrLn $ if stableSorted cards sSorted then "Stable" else "Not stable"

data Suite = Heart | Club | Spade | Diamond deriving (Show, Eq)
fromChar :: Char -> Suite
fromChar 'H' = Heart
fromChar 'C' = Club
fromChar 'S' = Spade
fromChar 'D' = Diamond

data Card = Card { _suite :: Suite, _num :: Int} deriving (Eq)
fromString :: String -> Card
fromString (s:num) = Card (fromChar s) (read num)

instance Ord Card where
    compare = compare `on` _num

instance Show Card where
    show (Card s n) = (head $ show s) : show n

stableSorted :: [Card] -> [Card] -> Bool
stableSorted orig = all sameOrder . groupBy ((==) `on` _num)
    where
        sameOrder = ascending . map (`elemIndex` orig)
        ascending xs = all (==LT) $ zipWith compare xs (tail xs)

-- |
-- >>> stableSorted 

findMinimum :: Ord a => [a] -> (a,Int)
findMinimum = minimum . flip zip [0..]

selectionSort :: Ord a => [a] -> ([a],Int)
selectionSort = selectionSort' . (,0)

-- |
-- >>> selectionSort ([5,6,4,2,1,3] :: [Int])
-- ([1,2,3,4,5,6],4)
-- >>> selectionSort ([5,2,4,6,1,3] :: [Int])
-- ([1,2,3,4,5,6],3)
 
-- TODO : find a good higer order function>
selectionSort' :: Ord a => ([a],Int) -> ([a],Int)
selectionSort' ([],n) = ([],n)
selectionSort' (x:xs,n) = let (h,i) = findMinimum (x:xs)
                              rs = take (i-1) xs ++ x:drop i xs
                            in
                            h <:> if i /= 0
                                     then selectionSort' (rs, n+1)
                                     else selectionSort' (xs,n)

bubbleSort :: Ord a => [a] -> (Int,[a])
bubbleSort = bubbleSort' . (0,)

bubbleSort' :: Ord a => (Int, [a]) -> (Int,[a])
bubbleSort' (n,xs) =
    let (fl,n',xs') = f False n xs
        f :: Ord a => Bool -> Int -> [a] -> (Bool,Int,[a])
        f b m [] = (b,m,[])
        f b m [x] = (b,m,[x])
        f b m (x:y:rest) = if x > y
                              then y <::> f True (m+1) (x:rest)
                              else x <::> f b m (y:rest)
        in
        if fl then bubbleSort' (n',xs')
              else (n',xs')


(<:>) x (xs,b) = (x:xs,b)
(<::>) :: forall t t1 a. a -> (t, t1, [a]) -> (t, t1, [a])
(<::>) x (a,b,xs) = (a,b,x:xs)
-- }}}
-- vim:fdm=marker

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

int main (){
  //int x, y;
  //cin >> x >> y;
  //if(x > y) swap(x, y);
  //cout << x << " " << y << endl;
  
  int x, y;
  for(int i = 1; i < 10001; i++){
    cin >> x >> y;
    if((x == 0)&&(y == 0)) break;
    else if(x > y) swap(x,y);
    cout << x << " " << y << endl;
    }
}




Measured memory_bytes: 3004
n=int(input())
a=list(map(int, input().split()))

rt=[0]*8
rt8=0
for i in range(n):
    for j in range(0,8):
        if 400*j<=a[i] and a[i]<=399+400*j:
            rt[j]=1
    if a[i]>=3200:
        rt8=rt8+1
        
rtmin=max(1,sum(rt))
#rtmax=min(rtmin+rt8,8)
rtmax=sum(rt)+rt8

print(rtmin,rtmax)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>

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


#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}




int main() {

	int n, m;
	int ans=0;
	cin >> n >> m;
	vector<int> sc(n,-1);
	bool cannot = false;
	rep(i, 0, m) {
		int ts, tc;
		cin >> ts >> tc;
		if (sc[ts - 1] == -1) {
			sc[ts - 1] = tc;
		}
		else if(sc[ts-1] != tc) {
			cannot = true;
		}

		
	}
	if (cannot) {
		cout << "-1" << endl;
		return 0;
	}
	if (n != 1 && sc[0] == 0) {
		cout << -1 << endl;
		return 0;
	}

	rep(i, 0, n-1) {
		if (sc[i] != -1) {
			ans += pow(10, n-1-i)*sc[i];
		}
		else if (sc[0] == -1 && i==0) {
			ans += pow(10, n - 1 - i);
		}
		else {
			ans += 0;
		}
	}
	
	if (sc[n - 1] != -1) {
		ans += sc[n - 1];
	}



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

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
  public static void Main(){
    var n = Int32.Parse(Console.ReadLine());
    var l = new Int32[n];
    for(var i=0; i<n; i++) l[i] = Int32.Parse(Console.ReadLine())-1;
    var j = 0;
    var c = 0;
    while(true){
      if(l[j]==-1){
        c = -1;
        break;
      }
      if(j==1) break;
      var tmp = l[j];
      l[j] = -1;
      j = tmp;
      c++;
    }
    Console.WriteLine(c.ToString());
  }
}


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

const int MAX = 10000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  long long X,Y,ans,A,B;
  cin>>X>>Y;
  if((2*X-Y)%3==0&&(2*Y-X)%3==0){
    A=(2*X-Y)/3;
    B=(2*Y-X)/3;
    COMinit();
    cout<<COM(A+B,A)<<endl;
  }else cout<<"0"<<endl;
}

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


char s[110];
char t[110];
int main()
{
int n;
scanf("%d",&n);
scanf("%s%s",s,t);
for(int i = 0; i < n; i++)
{
	printf("%c%c",s[i], t[i]);
}
return 0;

}


Measured memory_bytes: 256
N=int(input())
for i in range(1,N+1):
   
    if i%3==0:
        print(" ",end="")
        print(i,end="")
    else:
        s=str(i)
        for sent in s:
            if sent=="3":
                print(" ",end="")
                print(s,end="")
                break

print()


Measured memory_bytes: 6160
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int main()
{
    fast_cin();
    int w,h,a,b;
    cin>>h>>w>>a>>b;
    forn(i, b)
    {
    	forn(j,a)
    	{
    		cout<<0;
    	}
    	forn(j,w-a)
    	{
    		cout<<1;
    	}
    	cout<<'\n';
    }
    forn(i, h-b)
    {
    	forn(j,a)
    	{
    		cout<<1;
    	}
    	forn(j,w-a)
    	{
    		cout<<0;
    	}
    	cout<<'\n';
    }

    return 0;
}


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

int main(){
    string s, t;
    cin>>s>>t;
    int check=0;
    rep(i, s.size()){
        check=0;
        rep(j, t.size()){
            if(s.at((i+j)%s.size())!=t.at(j)){
                check=1;
                break;
            }
        }
        if(check==0){
            cout<<"Yes"<<endl;
            check=2;
            break;
        }
    }
    if(check!=2){
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3200
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

a, b, c = I()
j, k, l = I()
x, y, z = I()

seen = {}
n = I()
for _ in range(n):
    d = I()
    seen[d] = 1

if a in seen and b in seen and c in seen:
    print('Yes')
elif j in seen and k in seen and l in seen:
    print('Yes')
elif x in seen and y in seen and z in seen:
    print('Yes')
elif a in seen and j in seen and x in seen:
    print('Yes')
elif b in seen and k in seen and y in seen:
    print('Yes')
elif c in seen and l in seen and z in seen:
    print('Yes')
elif a in seen and k in seen and z in seen:
    print('Yes')
elif x in seen and k in seen and c in seen:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 67864
using namespace std;
#include <bits/stdc++.h>
#define fdto(i, r, l) for(int i = r; i >= l; --i)
#define fto(i, l, r) for(int i = l; i <= r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
 ll n,i,cnt[10000005]={0},st[10000005],j;
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    cin>>n;

    for(i=2;i<=10000000;i++)
    {
        if(cnt[i]==0)
        {
            for(j=i;j<=10000000;j=j+i)
            {
                cnt[j]++;
                st[j]=i;
            }
        }
    }
    
    st[1]=1;
    ll ansf=0;
    for(i=1;i<=n;i++)
    {
        ll k=i;
        
        ll cnt1=0,ans=1;
        while(k>1)
        {
            ll p=st[k];
            
            cnt1=0;
            while(k%p==0)
            {
                k/=p;
                cnt1++;
            }

            ans=ans*(cnt1+1);
            
        }
    
        ansf+=i*ans;
    }
    cout<<ansf<<endl;
    return 0;
}

Measured memory_bytes: 159896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1e9+7;

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

//********************************template END****************************************//

void solve(void){

	string S; ll K;
	cin >> S >> K;
	int i = 0;
	while(S[i] == '1') {i++;}
	cout << (i+1 > K ? '1' : S[i]) << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    var ans = 0L
    for (d in 1..n) {
        val l = n / d
        ans += d * l * (l + 1) / 2
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34436
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }   
}

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    print_ans((r*100+10*g+b) % 4 == 0);
    return 0;
}


Measured memory_bytes: 256
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1

ans=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h
print(ans)
        


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

class B
{
	static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select((_, i) => $"{i + 1} {Console.ReadLine()}".Split()).OrderBy(x => x[1]).ThenBy(x => -int.Parse(x[2])).Select(x => x[0])));
}


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

#define lugan "VACATION"
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _io ios_base::sync_with_stdio(0);   cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5+7;
const int oo = 1e9+7;

inline void initf()
{
    freopen(lugan".inp", "r", stdin);
    freopen(lugan".out", "w", stdout);
}

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

int main()
{
    _io
    cin >> n;
    for (int i=1; i<=n; i++)
        for (int j=0; j<3; j++)
            cin >> a[i][j];
    for (int i=1; i<=n; i++)
        for (int j=0; j<3; j++)
            dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
    return 0;
}



Measured memory_bytes: 4224
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            p = chk
            chk = i
            for x in range(N-i):
                if C[p-x] == 'R':
                    chk = p - x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1
                if chk <= i + 1:
                    break

    print(cnt)

main_chk()


Measured memory_bytes: 10204
#include<iostream>
#include<math.h>
#include<cassert>
using namespace std;

int return_min(int a[], int n);
int return_max(int a[], int n);
long return_sum(int a[], int n);

int main()
{
	int n,a[10000];

	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}

	cout<<return_min(a, n)<<" "<<return_max(a, n)<<" "<<return_sum(a, n)<<endl;

	return 0;
}

int return_min(int *a, int n)
{
	assert(n>=0);
	if(n==0) return a[0];
	return min(a[n-1], return_min(a, n-1)); //return the largest from 1 to n
}

int return_max(int *a, int n)
{
	assert(n>=0);
	if(n==0) return a[0];
	return max(a[n-1], return_max(a, n-1));
}

long return_sum(int *a, int n)
{
	assert(n>=0);
	if(n==0) return 0;
	return a[n-1]+return_sum(a, n-1);
}

Measured memory_bytes: 3444
N=int(input())
B=list(map(int,input().split()))
A=[0]*N
ans=0
for i in range(N):
  if i==0:
    A[i]=B[i]
  elif i==N-1:
    A[i]=B[i-1]
  else:
    A[i]=min(B[i-1],B[i])
for i in A:
  ans+=i
print(ans)

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

using namespace std;
typedef long long ll;

int main()
{
	priority_queue<int> q; 
	int n,m;
	cin >>n>>m;
	for(int i=0;i<n;i++)
	{
		int x;
		cin >>x;
		q.push(x);
	}
	while(!q.empty()) 
	{
		int x=q.top();
		q.pop();
		x=x/2;
		q.push(x);
		m--;
		if(m<=0) break;
	}
	ll sum=0;
	while(!q.empty())
	{
		int x=q.top();
		q.pop();
		sum+=x;
	}
	cout <<sum<<endl;
	return 0;
 }

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(Base,lli,N,0);
  rep(i,0,N)Base[i]=i+1;
  Vec(P,lli,N,0);
  Vec(Q,lli,N,0);
  rep(i,0,N)cin >> P[i];
  rep(j,0,N)cin >> Q[j];
  sum=1;
  do{
    rep(i,0,N){
      if(Base[i]!=P[i])break;
      if(i==N-1)A=sum;
    }
    rep(i,0,N){
      if(Base[i]!=Q[i])break;
      if(i==N-1)B=sum;
    }
    sum++;
  }while(next_permutation(Base.begin(),Base.end()));
  Out(abs(A-B));
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int h[100010],nex[200010],to[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
int d[100010],v[100010],f[100010],g[100010];
void dfs(int fa,int x){
	f[x]=g[x]=v[x];
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa){
			dfs(x,to[i]);
			f[x]=max(f[x],max(g[x]+g[to[i]],f[to[i]]));
			g[x]=max(g[x],g[to[i]]+v[x]);
		}
	}
}
int main(){
	int n,i,x,y,s;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	s=0;
	for(i=1;i<=n;i++){
		s+=d[i]==1;
		v[i]=d[i]==2;
	}
	dfs(0,1);
	printf("%d",s+f[1]);
}

Measured memory_bytes: 3712
#include<iostream>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
int n,w;

int main()
{
  while(cin >> n >> w,n|w)
    {
      double V[100]; rep(i,100)V[i] = 0;
      double denom = 0;
      int last_index = 0;
      rep(i,n)
	{
	  int v;
	  cin >> v;
	  V[v/w]++;
	  denom = max(denom,V[v/w]);
	}
      for(int i=99;i>=0;i--)
	{
	  if(V[i] != 0)
	    {
	      last_index = i;
	      break;
	    }
	}

      double ans = 0.01;
      double frac = (double)last_index; 
      rep(i,last_index+1)
	{
	  ans += (frac/last_index)*(V[i]/denom);
	  frac--;
	}
      cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
    }
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    int N, M;
    cin >> N >> M;
    vint P(M), Y(M);
    map<int, vector<pair<int, int>>> T;
    rep(i, M)
    {
        cin >> P[i] >> Y[i];
        T[P[i]].push_back({Y[i], i});
    }
    vector<pair<int, int>> S(M);
    for (auto v : T)
    {
        sort(all(v.second));
        for (int i = 0; i < v.second.size(); i++)
        {
            S[v.second[i].second] = {v.first, i + 1};
        }
    }
    stringstream ss;

    for (int i = 0; i < S.size(); i++)
    {
        ss << setw(6) << setfill('0') << S[i].first << setw(6) << setfill('0') << S[i].second << "\n";
    }
    cout << ss.str();
    return 0;
}

Measured memory_bytes: 16644
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define int long long
typedef long long ll;
const ll mod=1e9+7;
vector<ll> yaku,array;
void set_yaku(ll n){
  vector<ll> kv;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0) kv.push_back(i);
  }
  for(int i=0;i<kv.size();i++){
    yaku.push_back(kv[i]);
    if(n/kv[i]!=kv[i]) yaku.push_back(n/kv[i]);
  }
  sort(yaku.begin(),yaku.end());
}
bool judge(ll n,ll k){
  priority_queue<ll> pque;
  ll sum=0;
  for(int i=0;i<array.size();i++){
    ll val=(n-(array[i]%n))%n;
    pque.push(val);
    sum+=val;
  }
  for(;sum>0;sum-=n){
    ll max_v=pque.top();
    pque.pop();
    max_v-=n;
    pque.push(max_v);
  }
  ll s2=0;
  while(!pque.empty()){
    ll kn=pque.top();
    pque.pop();
    if(kn>0) s2+=kn;
  }
  return s2<=k;
}
signed main(){
  ll n,k,sum=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    sum+=a;
    array.push_back(a);
  }
  set_yaku(sum);

  int lb=0;
  for(int i=1;i<yaku.size();i++) if(judge(yaku[i],k)) lb=i;
  cout<<yaku[lb]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define mp make_pair
#define ss second
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repp(i,a,b) for(int i = a; i <= b; i++)
#define endl '\n'
#define mod 1000000007
#define mod_in(a) bin(a, mod - 2)
#define fact(n) rep(i, 1, n+1) ft.pb((ft[i-1] * i) % mod)
#define ncr(n, r) (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n)-(r)]) % mod)) % mod) : 0LL)
#define pi 3.14159265358979323
#define INF 1e15
#define lb(v, a) lower_bound(v.begin(), v.end(), a)
#define ub(v, a) upper_bound(v.begin(), v.end(), a)

int power(int x, int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x, int n){
    int res=1; x%=mod;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}

set<int> v[26];
int flag=0;
int vis[26]={0}, par[200001]={0}, top[500001], a[200006], b[200006];

void dfs(int n){
    vis[n] = 1;
    cout<<char(n + 'a');
    for(auto i: v[n]){
        if(!vis[i]) dfs(i);
    }
}

// vector<int> adj[2000005];
// vector<int> pr(2000005, 1), xx[2000005];
// void sieve(int n){ 
//     for(int p=2; p<n; p++){ 
//         if(pr[p]){ 
//             for(int i=p; i<n; i += p){
//                 pr[i]=0;
//                 xx[i].pb(p);
//             }
//         } 
//     } 
// }  
// vector<int> ft(40);

void solve(){
    int n, k=-1, x=0, y=0, d=0; cin>>n;
    string s; cin>>s;
    for(int i=n-1; i>=0;i--){
        if(s[i]=='R'){
            k=i;
            break;
        }
    }
    if(k==-1){
        cout<<0<<endl;
    }
    else{
        rep(i,0,k+1){
            if(s[i]=='W')x++;
            else y++;
        }
        rep(i,0,y){
            if(s[i]=='W') d++;
        }
        cout<<min(min(x, d), y)<<endl;
    }
}

signed main(){
    fast
    int t=1;
    // cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;

int main()
{
    fastio;
    ll i, j, k, n, m, t;

    cin>>n>>m;

    cout<<ceil((float)n/m)<<endl;

        
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>

using namespace std;
#include <stdio.h>
int main()
{
    typedef long long int ll ;
    ll x , l ;
    cin >> x ;
    ll in[x] ;
    int i , s=0;
    int out[x] ;

    for(i=0 ; i<x ; i++){
        cin >> in[i] ;
    }


    for(i=0 ; i<x ; i++){
        if(in[i]>=in[i+1])
            s++;
        else
            s=0;

        out[i]=s;
    }

    l=out[0];

    for(i=0 ; i<x ; i++){
        if(l<out[i])
            l=out[i];
    }

    cout<< l << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;


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

	bool ans = false;
	for (int i = 0; i < K; ++i)
	{
		if (B > A) {
			if (C > B)
			{
				ans = true;
				break;
			}
			else {
				C *= 2;
			}
		}
		else
		{
			B *= 2;
		}

		if (B > A && C > B) ans = true;
	}

	if (ans)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
} 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		int a; scanf("%d", &a);
		if(a%2 == 0){
			if(a%3 != 0 && a%5 != 0){
				printf("DENIED\n");
				return 0;
			}
		}
	}
	printf("APPROVED\n");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
 char S[101];
 int L = 0;
 int Cnt = 0;
 int i;
 scanf("%s",S);
 L = strlen(S);
// printf("%d\n",L);

 for(i=0;i<L/2;i++)
 {
  //printf("%c %c\n",S[i],S[L-i-1]);
  if(S[i]!=S[L-i-1]) Cnt++;
 }
 
 printf("%d\n",Cnt);
 
 return 0;
}




Measured memory_bytes: 128
import sys
input = sys.stdin.readline

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

res = 0
for i in range(n-1):
    if x >= a[i]:
        res += 1
        x -= a[i]
    else:
        break
if x == a[-1]:
    res += 1
print(res)

Measured memory_bytes: 3060
# include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node{
    int key;
    struct node *right,*left,*parent;
};

typedef struct node *Node;

Node root;

Node Tminimum(Node x){
    while(x->left != NIL)x=x->left;
    return x;
}

Node find(Node u,int k){
    while(u != NIL && k != u->key){
        if(k < u->key)u = u->left;
        else u = u->right;
    }
    return u;
}


Node Tsuccessor(Node x){
    Node y;
    if(x->right !=  NIL)return Tminimum(x->right);
    y=x->parent;
    while(y != NIL && x == y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void Tdelete(Node z){
    Node x,y;

    if(z->left == NIL || z->right == NIL)y=z;
    else y=Tsuccessor(z);

    if(y->left != NIL){
        x=y->left;
    } else{
        x=y->right;
    }

    if(x != NIL){
        x->parent = y->parent;
    }

    if(y->parent == NIL){
        root=x;
    } else{
        if(y == y->parent->left){
            y->parent->left=x;
        }else{
            y->parent->right=x;
        }
    }

    if(y!=z){
        z->key=y->key;
    }

    free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!= NIL){
      y=x;
      if(z->key < x->key){
          x=x->left;
      }else{
          x=x->right;
      }
  }
  z->parent=y;

  if(y == NIL){
      root=z;
  }else if(z->key < y->key){
      y->left = z;
  }else{
      y->right = z;
  }
}

void inorder(Node u){
    if(u == NIL) return;

    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);

}
void preorder(Node u){
if(u == NIL) return;
printf(" %d",u->key);
preorder(u->left);
preorder(u->right);
}


int main(){
    int i,n,x;
    char com[20];
    Node t;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",com);
        if(com[0]=='f'){
            scanf("%d",&x);
            t=find(root,x);
            if(t != NIL)printf("yes\n");
            else printf("no\n");
        }else if(com[0]=='i'){
            scanf("%d",&x);
            insert(x);
        }else if(com[0] == 'p'){
        inorder(root);
        printf("\n");
        preorder(root);
        printf("\n");
        }else if(com[0] == 'd'){
            scanf("%d",&x);
            Tdelete(find(root,x));
        }
    }
    return 0;
}


Measured memory_bytes: 20436
N = int(input())
Xs = input().split()
X_i = []
for i in range(N):
  X_i.append(int(Xs[i]))

x0 = 1
Ps = []
for k in range(100):
  P = 0
  for i in range(N):
    P+= (X_i[i]-x0)**2
  Ps.append(P)
  x0+=1
print(min(Ps))

Measured memory_bytes: 3064
n, m = map(int, input().split())
h = [0] + [int(i) for i in input().split(" ")]
c = [0]*(n+1)
for i in range(m):
    a, b = map(int, input().split())
    c[a] = max(c[a], h[b])
    c[b] = max(c[b], h[a])
ans = 0
for i in range(1, n+1):
    if h[i] > c[i]:
        ans += 1
print(ans)


Measured memory_bytes: 20124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2, x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            
            p1 = n * a;
            p2 = b;

           
            if (p1 < p2)
                x = p1;
            else
                x = p2;

            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define se second
typedef long long ll;
const int maxn = 600005;
typedef pair<int, int>par;
const ll mod = 998244353;


ll f[maxn], inv[maxn];
ll pot( ll b, ll e ){
    if( e == 0 ) return 1;
    ll ret = 1, a = b;
    if( b == 0 ) return 0;
    while( e ){
        if( e & 1 )
            ret = (ret * a)%mod;
        e >>= 1;
        a = (a*a)%mod;
    }
    return ret;
}

ll comb( ll n, ll k ){
    if( n < 0 ) return 0;
    ll ret = (f[n] * inv[k])%mod;
    ret = (ret * inv[n-k])%mod;
    return ret;
}

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

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in", "r",stdin);
    #endif // acm

    ll n, m, k;
    cin >> n >> m >> k;

    f[0] = 1;
    for( ll i = 1; i <= n+k; i ++ )
        f[i] = (f[i-1] * i)%mod;

    inv[ n+k ] = pot(f[n+k], mod-2);
    for( ll i = n+k-1; i >= 0; i-- )
        inv[i] = (inv[i+1] * (i+1))%mod;


    ll sol = 0;
    for( int c = 0; c <= k; c++ ){
        int cg = n-c;
        int nn = n - cg;
        ll cf = comb( nn + cg - 1, cg - 1 );

        //sol = (sol + (cf * (pot(m-1, cg-1) * 1ll*m)%mod)%mod)%mod;
        ll a = (cf * pot(m-1, cg-1))%mod;
        ll b = (a * m)%mod;
        sol = (sol + b)%mod;
    }

    cout << sol << "\n";

    return 0;
}


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

int main(){
    string S;cin>>S;
    int N=S.size();
    while(N>7){
        if(S.substr(N-5)=="dream"){
            S=S.substr(0,N-5);
            N-=5;
        }
        else if(S.substr(N-5)=="erase"){
            S=S.substr(0,N-5);
            N-=5;
        }
        else if(S.substr(N-7)=="dreamer"){
            S=S.substr(0,N-7);
            N-=7;
        }
        else if(S.substr(N-6)=="eraser"){
            S=S.substr(0,N-6);
            N-=6;
        }
        else break;
    }
    if(S=="dream" or S=="erase" or S=="dreamer" or S=="eraser")cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 512
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn one2fourteen (x: i32) -> i32 {
	if x == 1 {
		14
	}else {
		x
	}
}

fn main () {
	let n = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();
	let alice = one2fourteen(n[0]);
	let bob = one2fourteen(n[1]);

	if alice > bob {
		println!("Alice");
	}else if bob > alice {
		println!("Bob");
	}else {
		println!("Draw");
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  N--;
  
  cout << vec.at(N) - vec.at(0) << endl;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(void){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> v(n+1);
    vector<int> ans;
    for(int i = 1; i < n+1; i++) cin >> a.at(i);
    for(int i = n/2+1; i < n+1; i++){
        v.at(i) = a.at(i);
        if(a.at(i) == 1) ans.push_back(i);
    }
    for(int i = n/2; i > 0; i--){
        int sum = 0;
        for(int j = i; j < n+1; j+=i){
            sum += v.at(j);
        }
        sum %= 2;
        if((sum + a.at(i)) %2 == 1){
            v.at(i) = 1;
            ans.push_back(i);
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for(auto i : ans) cout << i << endl;
    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
    using namespace std ;
    #define pb push_back
    #define ll long long
     
    int main() {
        ll k , l , r ;
        cin >> k  ;
     
        ll res = 100LL ,ans = 0 ;
        while(res<k){
            res = res + (res /100) ;
            ans++ ;
        }
        cout << ans ;
     
        return 0 ;
    }

Measured memory_bytes: 3676
import numpy as np

n = int(input())
a = list(map(int,input().split()))
arr = np.array(a)

# 奇数がプラス、偶数がマイナス
cost1 = 0
cum = 0
for i in range(n):
    cum += arr[i]
    tmp = abs(cum) + 1
    if i%2==1 and cum<=0: cost1 += tmp ; cum += tmp
    if i%2==0 and cum>=0: cost1 += tmp ; cum -= tmp

# 奇数がマイナス、偶数がプラス
cost2 = 0
cum = 0
for i in range(n):
    cum += arr[i]
    tmp = abs(cum) + 1
    if i%2==1 and cum>=0: cost2 += tmp ; cum -= tmp
    if i%2==0 and cum<=0: cost2 += tmp ; cum += tmp


ans = min(cost1, cost2)
print(ans)



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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	double a, b, t; cin >> a >> b >> t;
	int sum = 0;
	for (int i = 1; a * i <= t + 0.5; i++) {
		sum += b;
	}
	cout << sum;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n;
    cin>>n;
    vector<int>a(n);
    ll sum1=0,sum2=0;
    rep(i,n){
        cin>>a[i];
        sum1+=a[i];
    }
    ll ans=1e18;
    rep(i,n-1){
        sum2+=a[i];
        ans=min(ans,abs(sum1-2*sum2));
    }
    cout<<ans<<endl;
}

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

int main() {
  int n;
  int l[1000] = {};

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }

  sort(l,l+n);

  cout << l[n-1] - l[0] << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();

		if(a == b){
			if(b == c){
				System.out.println("No");
			}else{
				System.out.println("Yes");
			}
		}else{
			if(b == c){
				System.out.println("Yes");
			}else{
				if(c == a){
					System.out.println("Yes");
				}else{
					System.out.println("No");
				}
			}
		}
	}

}


Measured memory_bytes: 21716
# ----------------------------
N,M,X = map(int, input().split())
A = [list(map(int, input().split(" "))) for i in range(N)]
 
MOD = 10**9+7
a = [0]*M
value = [0]
ans = MOD
 
for i in range(2**N):
    for j in range(N+1):
        if(i >> j) & 1:
            for k in range(M):
                a[k] += A[j][k+1]
            value.append(A[j][0])
 
    if min(a) >= X :
        ans = min(ans,sum(value))
    a = [0]*M
    value = []
 
print(-1 if ans == MOD else ans)

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

int main()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;s[i];i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt;
    return 0;
}



Measured memory_bytes: 3916
#include<iostream>
#include<string>
using namespace std;
int main(){
    string h_card,t_card;
    int n,hanako,taro;
    hanako = 0;
    taro = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> t_card >> h_card;
        if(t_card > h_card){
            taro += 3;
        }
        else if(t_card == h_card){
            taro ++;
            hanako ++;
        }
        else{
            hanako += 3;
        }
        
    }
    cout << taro << " " << hanako << endl;
    
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int n, h[100000], max;
	cin >> n;
	for (int a = 0; a < n; a++) {
		cin >> h[a];
	}
	max = h[0] - 1;
	for (int i = 1; i < n; i++) {
		if (max > h[i]) {
			cout << "No" << endl;
			return 0;
		}
		else if (h[i] - 1 > max) {
			max = h[i] - 1;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
    
int main(){
    int r,d,x2000,x[1000];
    cin >> r >> d >> x2000;
    x[0]=x2000;
    for(int k = 1;k <=10 ;k++ ){
        x[k] = r*x[k-1]-d;
        cout << x[k] << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        if (a + b == 15) {
            System.out.println('+');
        } else {
            if (a * b == 15) {
                System.out.println('*');
            } else {
                System.out.println('x');
            }
        }

    }
}



Measured memory_bytes: 22484
import java.util.*;
import java.io.*;
class Main{
    public static void main(String[] args){
	try{
	    BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
	    String st;
	    boolean[] x = new boolean[1000000];
	    Arrays.fill(x, false);
	    for(int i=2; i<=1000; i++)
		if(x[i]==false)
		    for(int j=i*i; j<1000000; j+=i)
			x[j]=true;
	    while((st=s.readLine())!=null){
		int count=0, n=Integer.valueOf(st);
		for(int i=2; i<=n; i++)
		    if(x[i]==false)
			count++;
		System.out.println(count);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 10000
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4);
  var eqlist = new Array(N).fill(0);
  for(var i = 0; i < N; i++){
    if(list[i] == i+1){
       eqlist[i] = 1;
    }
  }
  myerr(eqlist);
  var ruiseki = 0;
  var output = 0;
  for(var i = 0; i < N; i++){
    if(eqlist[i] == 1){
       ruiseki++;
    }else{
       output += Math.ceil(ruiseki / 2);
       ruiseki = 0;
    }
  }
  output += Math.ceil(ruiseki / 2);
  myout(output);
}
Main(myin());

Measured memory_bytes: 55308
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b;
    scanf("%d %d", &a, &b);
    
    //評価
    if (a > b) {
        printf("a > b\n");
    }else if(a == b){
        printf("a == b\n");
    }else{
        printf("a < b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2104
n=int(input())
import itertools as it
res=0
count=3
oo=""
while count<10:
  lis=list(it.product("375",repeat=count))
  for i in range(0,len(lis)):
    hahaha=lis[i]
    if not "3" in hahaha:
      continue
    elif not "5" in hahaha:
      continue
    elif not "7" in hahaha:
      continue
    hahaha=oo.join(hahaha)
    if int(hahaha)<=n:
      res+=1
  count+=1
print(res)

Measured memory_bytes: 6756