akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int N;
    cin >> N;
    int res = -1;
    for (int i = 0; i < N + 1; i++)
    {
        if ((int)floor(i * 1.08) == N)
        {
            res = i;
        }
    }
    if (res == -1)
    {
        cout << ":(" << endl;
        return 0;
    }
    cout << res << 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 INF = 1000000009;
int main()
{
    string s;
    cin >> s;
    vector<string> check = {"dream", "eamer", "erase", "raser"};
    vector<string> add = {"dream", "dreamer", "erase", "eraser"};
    rep(i,4){
        reverse(check[i].begin(),check[i].end());
        reverse(add[i].begin(), add[i].end());
    }
    reverse(s.begin(),s.end());
    string t;
    int now = 0;
    while (t.size() < s.size())
    {
        bool flag = false;
        rep(i,4){
            string tmp = s.substr(now, 5);
            if(tmp == check[i]){
                t += add[i];
                flag = true;
                now += add[i].size();
            }
        }
        if(!flag){
            cout << "NO" << endl;
            return 0;
        }
    }
    if(s==t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int count = 0;

  int L=1, R=100000;
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    L = max(L, l);
    R = min(R, r);
  }
  if(L>R||N<L) cout << 0 << endl;
  else if(N>=R) cout << R-L+1 << endl;
  else if(N<R) cout <<  N-L+1 << endl;
}

Measured memory_bytes: 384
#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 n;
	cin >> n;
	int ans = 0;
	int m = 0;
	rep(i,n){
		int p;
		cin >> p;
		ans += p;
		if (p > m) m = p;
	}
	ans -= m/2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
s=input()
N=len(s)
gcount=0
pcount=0

def janken(me,you):
    if (me=="g")and(you=="p"):
        return -1
    elif (me=="p")and(you=="g"):
        return 1
    else:
        return 0
score=0
for i in range(N):
    if gcount==pcount:
        score=score+janken("g",s[i])
        gcount=gcount+1
    else:
        score=score+janken("p",s[i])
        pcount=pcount+1
print(score)

Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = -19191919;

int main()
{
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    vector<int> ans(4*n,-INF);
    int st = 2*n;
    int idx = 0;
    rep(i,n)
    {
        ans[st+idx] = a[i];

        idx = -idx;
        if(i%2==0) ++idx;
    }

    int s = 0;
    while(ans[s]==-INF) ++s;

    vector<int> x(n);
    rep(i,n) x[i]=ans[s+i];

    if(n%2==0) reverse(all(x));

    rep(i,n) printf("%d%c", x[i], (i==n-1)?'\n':' ');

    return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define vd vector<double>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define reverse_v(a) reverse(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    (c) ? (cout << "Yes" << endl) : (cout << "No" << endl);
}

void Print(bool c)
{
    (c) ? (cout << "YES" << endl) : (cout << "NO" << endl);
}

//最小公倍数
template <typename T>
T gcd(T a, T b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

//最大公約数
template <typename T>
T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}
//セカンドキー->ファーストキーの順ソート
bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

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

int eve(int x)
{
    if (x % 400 == 0)
        return 1;
    if (x % 100 == 0)
        return 0;
    if (x % 4 == 0)
        return 1;
    return 0;
}

int main(void)
{
    string s;
    ll k;
    cin >> s >> k;
    ll sp = 0;
    while (1)
    {
        if (sp == s.size() - 1)
        {
            k %= 26;
            s[sp] = (26 - (s[sp] - 'a') <= k) ? 'a' + k - (26 - (s[sp] - 'a')) : s[sp] + k;
            k = 0;
        }
        else if (s[sp] == 'a')
        {
            sp++;
            continue;
        }
        else if (26 - (s[sp] - 'a') <= k)
            k -= (26 - (s[sp] - 'a')), s[sp] = 'a';

        if (0 >= k)
            break;
        sp++;
    }
    cout << s << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 1000005;

int n,id = 1;
int ch[MAXN][26];
int sz[MAXN];
int cnt[MAXN][26];

long long ans;

char S[MAXN];

vector<char> s[MAXN];

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
	{
		scanf("%s",S);
		int l = strlen(S),cur = 1;
		sz[1]++;
		for (int j = 0;j < l;j++)
			s[i].push_back(S[j]);
		for (int j = l - 1;j >= 0;j--)
		{
			if (!ch[cur][S[j] - 'a'])
				ch[cur][S[j] - 'a'] = ++id;
			cur = ch[cur][S[j] - 'a'];
			sz[cur]++;
		}
	}
	for (int i = id;i >= 1;i--)
		for (int k = 0;k < 26;k++)
			if (ch[i][k])
				for (int j = 0;j < 26;j++)
					cnt[i][j] += (j == k ? sz[ch[i][k]] : cnt[ch[i][k]][j]);
	for (int i = 1;i <= n;i++)
	{
		int cur = 1;
		for (int j = s[i].size() - 1;j >= 1;j--)
			cur = ch[cur][s[i][j] - 'a'];
		ans += cnt[cur][s[i][0] - 'a'] - 1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 235444
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

signed main(){
    int n; cin >> n;
    string ans = "";
    while(n > 0){
        n--;
        ans += (char)(n%26 + 'a');
		n /= 26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <assert.h>
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n,m,k;
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
char s[1005][1005];
int sx, sy;
int dist[1005][1005];
queue < pair < int , int > > q;

int main(){
	
	scanf("%d%d%d",&n,&m,&k);
	for ( int i = 0; i < n; i++ ){
		scanf("%s",&s[i]);
		for ( int j = 0; j < m; j++ ){
			if ( s[i][j] == 'S' ){
				sx = i;
				sy = j;
				break;
			}
		}
	}

	memset(dist,-1,sizeof(dist));
	dist[sx][sy] = 0;
	q.push(mp(sx,sy));
	while ( !q.empty() ){
		sx = q.front().fi;
		sy = q.front().se;
		q.pop();
		if ( sx == 0 || sy == 0 || sx == n-1 || sy == m-1 ) continue;
		if ( dist[sx][sy] == k ) continue;
		for ( int l = 0; l < 4; l++ ){
			int x = dx[l] + sx , y = dy[l] + sy;
			if ( dist[x][y] == -1 && s[x][y] != '#' ) {
				dist[x][y] = dist[sx][sy] + 1;
				q.push(mp(x,y));
			}
		}
	}

	int ans = 1e9;
	for ( int i = 0; i < n; i++ ){
		for ( int j = 0; j < m; j++ ){
			if ( dist[i][j] != -1 ){
				int tmp = min(i,j);
				int tmp2 = min(n-i-1, m-j-1);
				int both = min( tmp , tmp2 );
				int res = both / k;
				if ( both % k != 0 ) res++;
				ans = min( ans, res);
			}
		}
	}

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

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t M = 1000000007LL;
  int64_t sum = 0;
  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    sum %= M;
  }
  for (int i = 0; i < N-1; i++) {
    sum -= A.at(i);
    if (sum < 0) sum += M;
    ans += A.at(i) * sum;
    ans %= M;
  }
  cout << ans % M << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	string s,t;

	cin>>s>>t;

	lli start = s.size() - t.size();
	if(start<0){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}

	for(lli i=start;i>=0;i--){
		if(DEBUG)cout<<"i="<<i<<endl;
		bool flag=true;
		for(lli j=0;j<t.size();j++){
			if(DEBUG)cout<<"j="<<j<<" i+j="<<i+j<<endl;
			if(s.at(i+j)!='?' && s.at(i+j)!=t.at(j)){
				flag = false;
				break;
			}
		}
		if(!flag)continue;
		for(lli k=0;k<s.size();k++){
			if(k<i){
				if(s.at(k)=='?')cout<<'a';
				else cout<<s.at(k);
			}
			else if(i<=k && k<(i+t.size())){
				cout<<t.at(k-i);
			}
			else{
				if(s.at(k)=='?')cout<<'a';
				else cout<<s.at(k);
			}
		}
		return 0;
	}

	cout<<"UNRESTORABLE"<<endl;
	return 0;


	return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 998244353

def check(mid, points, origin, rotate):
    height = origin * math.cos(math.radians(rotate))
    # print(height)
    cs = math.cos(math.radians(rotate))
    sn = math.sin(math.radians(rotate))
    for px, py in points:
        py = py - origin
        rx, ry = px*cs - py * sn, px * sn + py * cs
        if abs(rx) > height + 0.0000001 or abs(ry) > height + 0.0000001:
            # print("FALSE", rotate)
            return False

    return True


class Segtree_op():
    def __init__(self, n):
        self.size = 1
        while (n >= 1):
            self.size = self.size << 1
            n = n // 2

        self.arr = [self.unit() for i in range(self.size * 2)]

    def op(self, lch, rch):
        return lch + rch

    def unit(self):
        return 0

    def update(self, k, val):
        k += self.size - 1
        self.arr[k] = val
        while (k):
            k = (k - 1) // 2
            self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2])

    def query(self, l, r):
        L = l + self.size
        R = r + self.size
        s = self.unit()
        while L < R:
            if R & 1:
                R -= 1
                s = self.op(s, self.arr[R - 1])

            if L & 1:
                s = self.op(s, self.arr[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def show(self):
        idx = 1
        while (idx <= self.size):
            print(self.arr[idx - 1:idx * 2 - 1])
            idx *= 2


def solve():
    k = getN()
    s = input().strip()
    if len(s) <= k:
        print(s)
        return
    else:
        print(s[:k] + "...")

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    solve()



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

int main() {
    string s,t;
    cin>>s>>t;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int s[2019 * 2 + 5] = {};

int main() {
  int L, R;
  while (cin >> L >> R) {
    int n = 0;
    for (int i = L; i <= R && i <= L + (2019 * 2 + 1); i++) {
      s[n++] = i % 2019;
    }
    int ans = 2018;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        ans = min(ans, s[i] * s[j] % 2019);
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

ll d(ll a)
{
    ll ret = 0;
    while (a > 0)
    {
        a /= 10;
        ret++;
    }
    return ret;
}

//エラトステネスの篩
bool is_prime[1000000 + 1];
vector<ll> P;
void Eratosthenes(const ll N)
{
    for (ll i = 0; i <= N; i++)
    {
        is_prime[i] = true; //初期化
    }
    for (ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (ll j = 2 * i; j <= N; j += i)
            {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
}

int main()
{
    int n, a, b;
    cin >> n;
    vector<int> p(n), q(n), v(n);
    rep(i, n)
    {
        cin >> p[i];
        v[i] = i + 1;
    }
    rep(i, n)
    {
        cin >> q[i];
    }
    int c = 0;
    int tmp;
    do
    {
        c++;
        tmp = 1;
        rep(i, n)
        {
            if (p[i] != v[i])
            {
                tmp = 0;
            }
        }
        if (tmp == 1)
        {
            a = c;
        }

        tmp = 1;
        rep(i, n)
        {
            if (q[i] != v[i])
            {
                tmp = 0;
            }
        }
        if (tmp == 1)
        {
            b = c;
        }

    } while (next_permutation(v.begin(), v.end()));

    print(abs(a - b));
}


Measured memory_bytes: 256
#include <cinttypes>
#include <cstdint>
#include <cstdio>
#include <algorithm>
using ui16 = std::uint_fast16_t;
using ui32 = std::uint_fast32_t;
using ui64 = std::uint_fast64_t;
using std::scanf;
using std::printf;
const ui16 N_MAX = 100, v_MAX = 1000;
ui64 F[static_cast<ui32>(N_MAX) * static_cast<ui32>(v_MAX)];
int main()
{
	ui16 N, v;
	ui32 W, w;
	scanf("%" SCNuFAST16 "%" SCNuFAST32, &N, &W);
	std::fill(F + 1, F + static_cast<ui32>(N) * static_cast<ui32>(v_MAX) + 1, UINT_FAST64_MAX);
	for (ui16 i = 1; i <= N; ++i)
	{
		scanf("%" SCNuFAST32 "%" SCNuFAST16, &w, &v);
		for (ui32 j = static_cast<ui32>(i) * static_cast<ui32>(v_MAX); j >= static_cast<ui32>(v); --j)
		{
			if (F[j - static_cast<ui32>(v)] == UINT_FAST64_MAX)
				continue;
			F[j] = std::min(F[j], F[j - static_cast<ui32>(v)] + static_cast<ui64>(w));
		}
	}
	for (ui32 i = static_cast<ui32>(N) * static_cast<ui32>(v_MAX);; --i)
	{
		if (F[i] <= static_cast<ui64>(W))
		{
			printf("%" PRIuFAST32 "\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(f.readLine());
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = Integer.parseInt(tokenizer.nextToken());
        }
        int res = 0;
        for (int i = 0; i < n - 2; i++) {
            for (int j = i +1; j < n - 1; j++)
                for (int k = j + 1; k < n; k++) {
                    int[] ar = {l[i], l[j], l[k]};
                    Arrays.sort(ar);
                    if (ar[0] == ar[1]) continue;
                    if (ar[1] == ar[2]) continue;
                    int sum = ar[0] + ar[1];
                    if (sum > ar[2]) {
                        res++;
                    }
                }
        }

        out.println(res);
        out.close();
    }

}

Measured memory_bytes: 38508
#include<stdio.h>
int main()
{
    int n,p;
    while(~scanf("%d%d",&n,&p)&&(n+p))
    {
        int a[150]={0},ans,flag=0,ball=p;
        while(1)
        {
            for(int i=0;i<n;i++)
            {
                if(ball)
                    a[i]++,ball--;
                else
                    ball+=a[i],a[i]=0;
                if(a[i]==p)
                {
                    ans=i;
                    flag=1;
                    break;
                }
            }
            if(flag)
                break;
        }
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    int res = t.size();
    for(int i=0;i<=s.size()-t.size();++i){
        int diff = 0;
        for(int j=0;j<t.size();++j){
            if(s[i+j] != t[j]) diff++;
        }
        res = min(res, diff);
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3644
import java.util.Arrays;
import java.util.Scanner;

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


            long[] h=new long[n];
            for(int i=0;i<n;i++){
                h[i]=in.nextInt();
            }
        if(k>=n) {
            System.out.println(0);
        }
        else {
            long attacks = 0;
            Arrays.sort(h);
            for (int i = n - 1; i >= 0; i--, k--) {
                if (k <= 0) {
                    attacks += h[i];
                }
            }
            System.out.println(attacks);
        }

    }
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(H, vector<int>(W));
    int res = 0;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(a[i][j] == 1) {
                dp[i][j] = 0;
            } else if(i == 0 || j == 0) {
                dp[i][j] = 1;
            } else {
                dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1])) + 1;
            }
            res = max(res, dp[i][j]);
        }
    }
    cout << res*res << endl;
}


Measured memory_bytes: 18108
#include <bits/stdc++.h>
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, s, N) for(ll i{N - 1}; i > s - 1; i--)
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
struct UnionFind{vector<ll> par;UnionFind(ll n) : par(n, -1){}void init(ll n){par.assign(n, -1);}ll root(ll x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(ll x, ll y){return root(x) == root(y);}bool merge(ll x, ll y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};

/* ここからコード開始 */

int main(){
  kyopro;
  vector<ll> f(5);
  ll min10{10};
  for(auto&& i : f){
    cin >> i;
    if(i % 10 == 0){
    }
    else{
      min10 = min(min10, i % 10);
      i = i / 10 * 10 + 10;
    }
  }
  cout << accumulate(f.begin(), f.end(), 0LL) + min10 - 10 << rt;
}

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

// https://atcoder.jp/contests/abc067/tasks/abc067_b

int solver(int allStick,int selStick,vector<int> eStick){
    int result;
    sort(eStick.begin(),eStick.end(),greater<int>());
    result = 0;
    for(int j=0;j<selStick;j++){
        result = result + eStick.at(j);
    }
    return result;
}

int main(void){
    int answer=0;
    int N,K;
    cin >> N >> K;
    vector<int> l(N);
    for(int j=0;j<N;j++){
        cin >> l.at(j);
    }
    answer = solver(N,K,l);
    cout << answer << endl;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;
const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmax(const T &a, T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(const T &a, T b){if(a > b){a=b; return true;} return false;}

int main(){
    string s; cin >> s;
    bool flag=0;
    int ans=0;
    int cnt=0;
    for(int i=0; i<3; i++){
        if(s[i] == 'R'){
            flag=1;
            cnt++;
            ans=max(ans, cnt);
        }
        if(s[i] != 'R' && flag){
            flag=0;
            cnt=0;
        }
    }
    ans=max(ans, cnt);
    cout << ans << endl;
    return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli d[64];

void func(long long N, std::vector<long long> A){

    lli sum = 0;

    //REP(i,0,62)if(A[0]&(1LL<<i))d[i]++;

    lli maxA = 0;
    REP(i,0,N){
        maxA = max(maxA,A[i]);
        REP(j,0,62){
            if(A[i]&(1LL<<j))d[j]++;
        }
    }

    lli two = 1;
    REP(i,0,62){
        if(maxA<(1LL<<i))break;
        lli plus = (d[i])*(N-d[i]);
        plus %= MOD;
        sum += (plus * two)%MOD;
        sum%=MOD;
        two*=2;
        two%=MOD;
    }
    cout<<sum<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    func(N, std::move(A));
    return 0;
}


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

int main() {
	int n;
	cin >> n;

	string judge = "Yes";
	vector<string> w(101);
	for(int i=0;i<n;i++) {
		cin >> w.at(i);
	}

	for(int i=0;i<n-1;i++) {
		if((w[i]).at(w[i].size()-1) != (w[i+1]).at(0)) judge = "No";
	}

	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if((i != j) && (w[i] == w[j])) judge = "No";
		}
	}

	cout << judge << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("test.in");ofstream coutt("test.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int x,a;cin>>x>>a;
    if(x<a)cout<<0;
    else cout<<10;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
/*    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll a,b;
  cin>>a>>b;
  if(a%b==0)
  cout << 0 << endl;
else 
{
  cout << 1 << endl;
}

  
  

}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || (MX+1)/ans < a || ans*a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
x = int(input())
Pow = [1]
curr = 2
while True:
    if curr**5 - Pow[-1]**5 > x:
        break
    Pow.append(curr)
    curr += 1

mx = Pow[-1]
for i in range(mx + 1):
    Pow.append(-i)

for i in Pow:
    for j in Pow:
        if i**5 - j**5 == x:
            print(i, j)
            exit(0)



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

int main() {
  int A, B, Q; cin >> A >> B >> Q;
  vector<ll> s(A), t(B);
  for (int i = 0; i < A; i++) cin >> s[i];
  for (int i = 0; i < B; i++) cin >> t[i];
  auto f = [&](const vector<ll>& v, ll k) -> int {
    int lo = 0, hi = v.size();
    while (hi - lo > 1) {
      int mid = lo + (hi - lo)/2;
      if (v[mid] <= k) lo = mid;
      else hi = mid;
    }
    return lo;
  };
  while (Q--) {
    ll x; cin >> x;
    
    int sidx = f(s, x), tidx = f(t, x);
    auto g = [&](bool sf, int idx) -> ll {
      const auto &a = sf ? s : t, &b = sf ? t : s;
      if (idx >= a.size()) return 1e18;
      ll sc = abs(a[idx] - x);
      int bidx = f(b, a[idx]);
      sc += min(abs(a[idx] - b[bidx]), abs(a[idx] - b[min(bidx + 1, (int)b.size() - 1)]));
      return sc;
    };
    cout << min({g(true, sidx), g(true, sidx + 1), g(false, tidx), g(false, tidx + 1)}) << endl;
  }
  return 0;
}

Measured memory_bytes: 2944
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto A = IN();
	auto B = IN();
	auto K = IN();
	set<int> st;
	REP(i, K)
	{
		int val = A + i;
		if (A <= val && val <= B)
			st.insert(val);
	}
	REP(i, K)
	{
		int val = B - (K - 1) + i;
		if (A <= val && val <= B)
			st.insert(val);
	}
	for (auto it = st.begin(), end = st.end(); it != end; ++it)
		print(*it);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
N, K = map(int, input().split())

bs = {K: 0}
x = K
while x:
    bs[x - 1] = 0  # x-1:xの最下位bitを消して、その下位bitをすべて立てたもの
    x -= x & (-x)  # 最下位bitを消していく
    # https://atcoder.jp/contests/tenka1-2017/submissions/6793509

for _ in range(N):
    num, value = map(int, input().split())
    for b in bs:
        if (b | num) == b:  # orでmaskに別のbitが立たないなら加算
            bs[b] += value

print(max(bs.values()))


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
using namespace std;
struct node{
	int cnt,id;
}ath[100005];
int used[100005];
int a[305][305];
bool cmp(node a,node b){
	return a.cnt>b.cnt;
}
int main(){
//	freopen("sports.in","r",stdin);
//	freopen("sports.out","w",stdout);
	int n,m,i,j,k,o,p,l;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++)ath[i].id=i;
	for(i=1;i<=n;i++)for(j=1;j<=m;j++){
		scanf("%d",&a[i][j]);
		if(j==1)ath[a[i][j]].cnt++;
	}
	int ans=1<<30;
	int xm=m;
	while(xm--){
		sort(ath+1,ath+1+m,cmp);
		ans=min(ans,ath[1].cnt);
		used[ath[1].id]=1;
		for(i=1;i<=m;i++)ath[i].id=i,ath[i].cnt=0;
		for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		if(used[a[i][j]]==0){
			ath[a[i][j]].cnt++;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<ll, int> ii;

const int len = 1e5+5;
const ll inf = 1e15;
int a[len], n, en, t, nex[len];
ll dp[len], suf[len];
//deque<ii> deq;

int main(){
    scanf("%d %d %d", &n, &en, &t);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (int i = 1, j = 1; i <= n; i++){
        while (j <= n && 2*(a[j]-a[i]) <= t)
            j++;
        nex[i] = j;
    }

    //deq.push_back(mp(0, n+1));
    suf[n+1] = inf;
    for (int i = n; i >= 1; i--){
        int j = nex[i];

        dp[i] = min(dp[j]+t, suf[j]-2*a[i]);
        //dp[i] = min(deq.front().fi+t, suf[j]-2*a[i]);

        suf[i] = min(suf[i+1], dp[i+1]+2*a[i]);
        /*while (!deq.empty() && dp[i] <= deq.back().fi)
            deq.pop_back();
        deq.push_back(mp(dp[i], i));
        while(!deq.empty() && deq.front().se > nex[i-1])
            deq.pop_front();*/
    }

    printf("%lld\n", dp[1]+en);
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;
    int x1, x2, y1, y2;
    x1 = y1 = 0;
    x2 = w, y2 = h;

    for (int i = 0; i < n; i++){
        int x, y, a;
        cin >> x >> y >> a;

        if(a == 1){
            if (x > x1) x1 = x;
        }
        if(a == 2){
            if (x < x2) x2 = x;
        }
        if(a == 3){
            if(y > y1) y1 = y;
        }
        if(a == 4){
            if (y < y2) y2 = y;
        }

        if(x1 >= x2 || y1 >= y2){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (x2 - x1) * (y2 - y1) << endl;
    return 0;
}

Measured memory_bytes: 256
class Acc2D:
    def __init__(self, a):
        h, w = len(a), len(a[0])
        self.acc2D = self._build(h, w, a)
        self.H = len(self.acc2D)
        self.W = len(self.acc2D[0])

    def _build(self, h, w, a):
        ret = [[0] * (w + 1) for _ in range(h + 1)]
        for r in range(h):
            for c in range(w):
                ret[r + 1][c + 1] = ret[r][c + 1] + ret[r + 1][c] - ret[r][c] + a[r][c]
                # 末項は必要に応じて改変すること
        return ret

    def get(self, r1, r2, c1, c2):
        # [r1,r2), [c1,c2) : 0-indexed
        if r1 < 0: r1 = 0
        if r2 >= self.H: r2 = self.H - 1
        if c1 < 0: c1 = 0
        if c2 >= self.W: c2 = self.W - 1
        acc2D = self.acc2D
        return acc2D[r2][c2] - acc2D[r1][c2] - acc2D[r2][c1] + acc2D[r1][c1]


def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())

    g = [[0] * (K * 2) for _ in range(K * 2)]
    for _ in range(N):
        x, y, c = input().split()
        x = int(x) % (K * 2)
        y = (int(y) - (K if c == 'B' else 0)) % (K * 2)
        g[x][y] += 1  # White

    acc2d = Acc2D(g)
    ans = -1
    for r in range(K):
        for c in range(K):
            t = acc2d.get(0, r, 0, c)
            t += acc2d.get(0, r, c + K, c + K * 2)
            t += acc2d.get(r, r + K, c, c + K)
            t += acc2d.get(r + K, r + K * 2, 0, c)
            t += acc2d.get(r + K, r + K * 2, c + K, c + K * 2)
            ans = max(ans, t, N - t)
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 9;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int64 N, X, D, P[50];
vector< int > g[50];

int64 v[50], w[50], m[50];

void dfs(int idx) {
  v[idx] = 1;
  w[idx] = P[idx];
  m[idx] = idx == 0 ? inf : D;
  for(auto &to : g[idx]) {
    dfs(to);
    v[idx] += v[to];
    w[idx] += w[to];
  }
}

const int lim = 50 * 50 * 50;

int main() {
  cin >> N >> X >> D;
  cin >> P[0];
  for(int i = 1; i < N; i++) {
    int p;
    cin >> P[i] >> p;
    --p;
    g[p].emplace_back(i);
  }
  dfs(0);

  // 重さの合計X以下
  // i種類目 重さw[i] 価値v[i]  i>0でD個以下


  vector< int64 > dp(lim + 1, infll);
  dp[0] = 0;
  for(int i = 0; i < N; i++) {
    int k = min(50ll, m[i]);
    m[i] -= k;
    while(k--) {
      for(int j = lim; j >= v[i]; j--) chmin(dp[j], dp[j - v[i]] + w[i]);
    }
  }

  vector< int > ord(N);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int a, int b) {
    return 1LL * v[a] * w[b] > 1LL * v[b] * w[a];
  });

  int64 ret = 0;
  for(int i = 0; i < dp.size(); i++) {
    if(dp[i] > X) continue;
    int64 rest = X - dp[i], cost = i;
    for(auto &p : ord) {
      int64 get = min((int64) m[p], rest / w[p]);
      cost += get * v[p];
      rest -= get * w[p];
    }
    chmax(ret, cost);
  }

  cout << ret << endl;
}





Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:
#define error(args...) {}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}


const ll limit = 200010;
ll minus_values[limit],plus_values[limit];

int main(void){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	minus_values[0] = 1;
	{
		stack<int> stk;
		rep(i,1,n){
			ll prv = -2LL * a[i-1];
			minus_values[i] = minus_values[i-1];
			ll cur = -2LL * a[i];
			minus_values[i]++;
			while(abs(prv) < abs(cur)){
				ll offset = 0;
				if(!stk.empty()){
					offset = stk.top();
					stk.pop();
				}
				minus_values[i] += 2LL * (i - offset);
				prv *= 4LL;
			}
			ll stock = 0LL;
			while(4LL * abs(cur) < abs(prv)){
				stock++;
				cur *= 4LL;
			}
			rep(loop,stock) stk.push(i);
		}
	}

	plus_values[n-1] = 0;
	{
		stack<int> stk;
		rrep(i,n-1,0){
			ll prv = a[i+1];
			plus_values[i] = plus_values[i+1];
			ll cur = a[i];
			while(abs(prv) < abs(cur)){
				ll offset = n-1;
				if(!stk.empty()){
					offset = stk.top();
					stk.pop();
				}
				plus_values[i] += 2LL * (offset - i);
				prv *= 4LL;
			}
			ll stock = 0LL;
			while(4LL * abs(cur) < abs(prv)){
				stock++;
				cur *= 4LL;
			}
			rep(loop,stock) stk.push(i);
		}
	}
 
	ll ans = min(minus_values[n-1],plus_values[0]);
	rep(i,n-1) chmin(ans, minus_values[i] + plus_values[i+1]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstring>
#include <climits>
#define int long long
using namespace std;

int gcd(int a,int b)
{
	if(b>a)swap(a,b);
	if(a%b==0)return b;
	else return gcd(b,a%b);
}

int lcm(int a,int b)
{
	return a*b/gcd(a,b);
}

main()
{
	int a[3],m[3];
	
	while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2]&&a[0])
	{
		int b[3]={};
		for(int i=0;i<3;i++)
		{
			int p[3]={1,1,1};
			do
			{
				p[i]*=a[i];
				p[i]%=m[i];
				b[i]++;
			}while(p[i]!=1);
		}
		cout<<lcm(lcm(b[0],b[1]),b[2])<<endl;
	}
}

Measured memory_bytes: 1156
import java.util.*;

public class Main
{
	static	double EPS=1e-5;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			Point p1=new Point(in.nextDouble(), in.nextDouble()); 
			Point p2=new Point(in.nextDouble(), in.nextDouble()); 
			if(p1.x==0&&p1.y==0&&p2.x==0&&p2.y==0)
				return;
			Point p3=new Point(in.nextDouble(), in.nextDouble()); 
			Point p4=new Point(in.nextDouble(), in.nextDouble()); 
			Point p5=new Point(in.nextDouble(), in.nextDouble()); 
			Point p6=new Point(in.nextDouble(), in.nextDouble());
			boolean judge=true;
			if(!lineCross(p1, p2, p3, p4))
				judge=false;
			if(!lineCross(p3, p4, p5, p6))
				judge=false;
			if(!lineCross(p5, p6, p1, p2))
				judge=false;

			if(judge)
			{
				double a1=slanting(p1, p2);
				double a2=slanting(p3, p4);
				double x1=(a1*p1.x-p1.y-a2*p3.x+p3.y)/(a1-a2);
				if(a1==-1.123)
					x1=p1.x;
				else if(a2==-1.123)
					x1=p3.x;
				double y1=(p2.y-p1.y)/(p2.x-p1.x)*(x1-p1.x)+p1.y;
				if(a1==-1.123)
					y1=(p4.y-p3.y)/(p4.x-p3.x)*(x1-p3.x)+p3.y;

				a1=slanting(p3, p4);
				a2=slanting(p5, p6);
				double x2=(a1*p3.x-p3.y-a2*p5.x+p5.y)/(a1-a2);
				if(a1==-1.123)
					x2=p3.x;
				else if(a2==-1.123)
					x2=p5.x;
				double y2=(p4.y-p3.y)/(p4.x-p3.x)*(x2-p3.x)+p3.y;
				if(a1==-1.123)
					y2=(p5.y-p6.y)/(p5.x-p6.x)*(x2-p5.x)+p5.y;

				a1=slanting(p5, p6);
				a2=slanting(p1, p2);
				double x3=(a1*p5.x-p5.y-a2*p1.x+p1.y)/(a1-a2);
				if(a1==-1.123)
					x3=p5.x;
				else if(a2==-1.123)
					x3=p1.x;
				double y3=(p6.y-p5.y)/(p6.x-p5.x)*(x3-p5.x)+p5.y;
				if(a1==-1.123)
					y3=(p2.y-p1.y)/(p2.x-p1.x)*(x3-p1.x)+p1.y;

				Point a=new Point(x1, y1);
				Point b=new Point(x2, y2);
				Point c=new Point(x3, y3);
				double S=triangleArea(a, b, c);
				
				if(S<EPS)
					System.out.println("kyo");
				else if(S<100000)
					System.out.println("syo-kichi");
				else if(S<1000000)
					System.out.println("kichi");
				else if(S<1900000)
					System.out.println("chu-kichi");
				else 
					System.out.println("dai-kichi");			
			}
			else
				System.out.println("kyo");
		}
	}

	static boolean lineCross(Point p1,Point p2,Point p3,Point p4)
	{
		double jc1=(p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x);
		double jd1=(p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x);
		double jc2=(p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x);
		double jd2=(p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x);
		return jc1*jd1<=0 && jc2*jd2<=0;
	}

	static double slanting(Point p1,Point p2)
	{
		if(Math.abs(p1.x-p2.x)<EPS)
			return -1.123;
		else
			return (p1.y-p2.y)/(p1.x-p2.x);
	}
	//3頂点からなる三角形の面積
	static double triangleArea(Point p1,Point p2,Point p3)
	{
		return Math.abs((p3.y-p1.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p1.x))/2;
	}
}
class Point
{
	double x;
	double y;
	Point(double x,double y)
	{
		this.x=x;
		this.y=y;
	}
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <math.h>



int main(void){
	int a,b,c;
	int count=0;
	while(scanf("%d %d",&a,&b)!=EOF){
		count=0;
		c=a+b;
		while(1){
			count++;
			if(c<10){
				break;
			}
			c/=10;
		}
		printf("%d\n",count);
	}

    return 0;
}


Measured memory_bytes: 2068
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Contest
{


    class Program
    {


        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();

            Queue<long> queue = new Queue<long>();
            queue.Enqueue(a[0]);
            long res = 0;

            foreach(var item in a.Skip(1))
            {
                res += queue.Dequeue();
                queue.Enqueue(item);
                queue.Enqueue(item);
            }
            Console.WriteLine(res);

        }

    }
}


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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  double n;
  //string s;
  cin >> n;
  double pi = acos(-1);
  
  cout << 2.0*n*pi << endl;
}

Measured memory_bytes: 3768