akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(int argc, char const *argv[]) {
  string s;
  int k, r;
  vector<string> ans;
  cin >> s >> k;
  for (int i = 1; i <= k; i++) {
    for (int ii = 0; ii + i <= s.length(); ii++) {
      ans.push_back(s.substr(ii, i));
    }
  }

  // for (int i = 0; i < ans.size(); i++) {
  //   cout << ans[i] << endl;
  // }
  sort(ans.begin(), ans.end());
  unique(ans.begin(), ans.end());

  cout << ans[k - 1];

  return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int i;
		for (i = 0; n != 1; ++i)
			n = n & 1 ? 3*n+1 : n/2;
		printf("%d\n", i);
	}

	return 0;
}

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

using std::cout;
using std::cin;
using std::endl;

/*  テンプレここから */
typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;
    std::vector<std::pair<int, int>> nums(n);
    for(int i = 0; i < n; ++ i) {
        cin >> nums[i].first;
        nums[i].second = i + 1;
    }

    sort(all(nums));

    for(int i = 0; i < n; ++ i) {
        cout << nums[i].second;
        if(i < n-1)
            cout << " ";
    }
    cout << endl;
}

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

namespace _0558
{
    class Program
    {
        static bool[,] canwalk;
        static int[] movex = new int[] { 1, -1, 0, 0 };
        static int[] movey = new int[] { 0, 0, 1, -1 };
        static int[,] d;
        const int inf = 100000000;
        static int bfs(int startx, int starty, int goalx, int goaly)
        {
            Queue<int> xqueue = new Queue<int>();
            Queue<int> yqueue = new Queue<int>();
            xqueue.Enqueue(startx); yqueue.Enqueue(starty);
            d[startx, starty] = 0;
            while (true)
            {
                int nowx = xqueue.Dequeue(); int nowy = yqueue.Dequeue();
                if (nowx == goalx && nowy == goaly) break;
                for (int i = 0; i < 4; i++)
                {
                    if (canwalk[nowx + movex[i], nowy + movey[i]] &&
                        d[nowx + movex[i], nowy + movey[i]] == inf)
                    {
                        d[nowx + movex[i], nowy + movey[i]] = d[nowx, nowy] + 1;
                        xqueue.Enqueue(nowx + movex[i]); yqueue.Enqueue(nowy + movey[i]);
                    }
                }
            }
            return d[goalx, goaly];
        }
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            canwalk = new bool[x[0] + 2, x[1] + 2]; d = new int[x[0] + 2, x[1] + 2];
            int[,] cheese = new int[x[2] + 1, 2];
            for (int i = 0; i < x[0]; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < x[1]; j++)
                {
                    if (s[j] != 'X') canwalk[i + 1, j + 1] = true;
                    switch (s[j])
                    {
                        case ('X'): break;
                        case ('.'): break;
                        case ('S'):
                        {
                            cheese[0, 0] = i + 1; cheese[0, 1] = j + 1;
                            break;
                        }
                        default:
                        {
                            int n = int.Parse(s[j].ToString());
                            cheese[n, 0] = i + 1; cheese[n, 1] = j + 1;
                            break;
                        }
                    }
                }
            }
            int ret = 0;
            for (int i = 0; i < x[2]; i++)
            {
                for (int j = 0; j < x[0] + 2; j++)
                    for (int k = 0; k < x[1] + 2; k++)
                        d[j, k] = inf;
                ret += bfs(cheese[i, 0], cheese[i, 1], cheese[i + 1, 0], cheese[i + 1, 1]);
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 17384
#include <iostream>
int main(){
    int a,b,d = 1;
    std::cin >> a >> b;
    for(int c = 0;c < a;c++){
        if((d * 2) >= (d + b)){
            d = d + b;
        }else{
            d = d * 2;
        }
    }
    std::cout <<d <<std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int x,y,n=0;

while(1){
scanf("%d %d",&x,&y);
if(x==0&&y==0) break;
if(x>y){
 printf("%d %d\n",y,x);
}
else{
   printf("%d %d\n",x,y);
}
}
return(0);
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],cnt[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,i,j,k,x,y,z;
    cin>>n;
    for (i=2;i<=n;i++)
    {
    	cin>>arr[i];
    	cnt[arr[i]]++;
	}
	for (i=1;i<=n;i++)
	{
		cout<<cnt[i]<<endl;
	}
}

Measured memory_bytes: 6776
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void){
    int num_tree;
    int interval;
    scanf("%d %d",&num_tree,&interval);
    int able=2*interval+1;
    if(num_tree%able!=0){
        printf("%d",(num_tree/able)+1);
    }
    else if(num_tree%able==0){
        printf("%d",num_tree/able);
    }
    return 0;
}

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

int main()
{
    int x,y,a,b;
    cin>>x>>y;
    while((x!=0)||(y!=0)){
        if(x<y) {
            a=x;
            b=y;
        } else{
            a=y;
            b=x;
        }
        cout<<a<<" "<<b<<endl;
        cin>>x>>y;
    }
    
    return 0;
}


Measured memory_bytes: 2980
#include <stdio.h>
#include <string.h>
#define maxn 4010
#define LL long long
LL sum;
char s[maxn];
int r[maxn],g[maxn],b[maxn],n;
void count(char a,char b,char c,int *p){//abc
	int i,j,k;
	for(i=1;i<=n;i++)
		for(k=i+1;k<=n;k++)
			if(s[i]==a&&s[k]==c){
				if((i+k)%2==0){
					j=(i+k)/2;
					if(s[j]==b)sum+=p[k-1]-p[i]-1;
					else sum+=p[k-1]-p[i];
				}else sum+=p[k-1]-p[i];
			}
}
int main(){
	int i;
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n;i++){
		r[i]=r[i-1],g[i]=g[i-1],b[i]=b[i-1];
		if(s[i]=='R')r[i]+=1;
		else if(s[i]=='G')g[i]+=1;
		else if(s[i]=='B')b[i]+=1;
	}
	count('R','G','B',g);
	count('B','G','R',g);
	count('R','B','G',b);
	count('G','B','R',b);
	count('B','R','G',r);
	count('G','R','B',r);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 1696
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x *= i;
    return x;
}


int main(){
    ll n,sum=0;
    cin>>n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    
    rep(i,n){
        if(b[i]<=a[i]){
            sum+=b[i];
            a[i]-=b[i];
            continue;
        }
        else if(b[i]-a[i]<=a[i+1]){
            sum+=b[i];
            a[i+1] -= (b[i]-a[i]);
            continue;
        }
        else if(b[i]>a[i]+a[i+1]){
            sum+=a[i]+a[i+1];
            a[i]=0;
            a[i+1]=0;
            continue;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
    if(N==M)
        cout<<YES<<endl;
    else
    {
        cout<<NO<<endl;
    }
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#define LL long long
using namespace std;
multiset<LL> s1, s2;
LL dp[110000], dp2[110000];
int x[110000], n, E, T;
int main(){
	scanf("%d%d%d", &n, &E, &T);
	dp2[0] = T;s1.insert(T);
	for(int i = 1, j = 0; i <= n; i++){
		scanf("%d", &x[i]);
		while(j < i && 2 * (x[i] - x[j + 1]) >= T){
			s1.erase(s1.find(dp2[j]));
			dp2[j] = dp2[j] - T - 2 * (x[j + 1]);
			s2.insert(dp2[j]);
			j++;
		}
		dp2[i] = (((LL)1)<<50);
		if(!s1.empty()) dp[i] = max(dp[i], *s1.begin() + x[i]);
		if(!s2.empty()) dp[i] = min(dp[i], *s2.begin() + (LL)3 * x[i]);
		dp2[i] = dp[i] - x[i] + T; 
		s1.insert(dp2[i]);
	}
	cout<<dp[n] - x[n] + E;
	return 0;
}

Measured memory_bytes: 6912
#include "bits/stdc++.h"
 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define rep(i, x, n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define trav(a, x) for(auto& a: x)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007
#define endl '\n'
#define MAX 100002
#define pii pair<int, int>
#define pll pair<long long, long long>
 
typedef vector<int> vec;
typedef long long int ll;
typedef unsigned long long ull;



int main(){
    fast_cin();
    double n;cin>>n;
    double ans=2*n*3.14;
    printf("%.20f\n",ans);
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  if(b<=c || d<=a) cout << 0 << endl;

  else if (c>=a && d>=b) cout << b-c << endl;

  else if (c>=a && b>=d) cout << d-c << endl;

  else if (a>=c && d>=b) cout << b-a << endl;

  else if (a>=c && b>=d) cout << d-a << endl;


}

Measured memory_bytes: 256
import numpy as np

ll = []
# li=[1,2,3,4,5,...,n]
li = list(map(int,input().split()))
ll += li
li = list(map(int,input().split()))
ll += li
li = list(map(int,input().split()))
ll += li

cnt = 0
cnt += ll.count(1)%2
cnt += ll.count(2)%2
cnt += ll.count(3)%2
cnt += ll.count(4)%2

if ll.count(1) > 2 or ll.count(2) > 2 or ll.count(3) > 2 or ll.count(4) > 2:
    print("NO")
    exit()

if cnt>2:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 15748
#include <stdio.h>

int main()
{
    int n;
    int a[100], color[9] = {0};
    int i, j, k;
    int min;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", a + i);
        if (a[i] >= 1 && a[i] <= 399)
            color[0]++;
        if (a[i] >= 400 && a[i] <= 799)
            color[1]++;
        if (a[i] >= 800 && a[i] <= 1199)
            color[2]++;
        if (a[i] >= 1200 && a[i] <= 1599)
            color[3]++;
        if (a[i] >= 1600 && a[i] <= 1999)
            color[4]++;
        if (a[i] >= 2000 && a[i] <= 2399)
            color[5]++;
        if (a[i] >= 2400 && a[i] <= 2799)
            color[6]++;
        if (a[i] >= 2800 && a[i] <= 3199)
            color[7]++;
        if (a[i] >= 3200)
            color[8]++;
    }
    for (i = 0; i < 7; i++) {
        min = color[i];
        k = i;
        for (j = i + 1; j < 8; j++) {
            if (min > color[j]) {
                min = color[j];
                k = j;
                if (k != i) {
                    color[j] = color[i];
                    color[i] = min;
                }
            }
        }
    }
    k = 0; min = 0;
    for (i = 0; i < 8; i++) {
            if (color[i] != 0)
                k++;
            else
                min++;
        }
    if (k != 0) {
        if (min != 0)
            printf("%d %d ", k, k + color[8]);
        else {
            if (color[8] != 0 )
                printf("%d %d ", k, k + color[8]);
            else
                printf("%d %d ", k, k);
        }       
    }
    else {
        printf("%d %d", 1, color[8]);
    }


    return 0;
}


Measured memory_bytes: 128
// LM10: The next Ballon d'Or
import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;
public class Main
{
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }
    public static void main(String[] args)throws IOException {
        /*

        */
        PrintWriter pw = new PrintWriter(System.out);
        FastReader fr = new FastReader();
        int t=1;
        for(int ti=0;ti<t;++ti)
        {
            int n=fr.i();
            int [] heights=new int [n];
            fr.scanIntArr(heights);
            int [] dp=new int[n];
            dp[0]=0;
            dp[1]=dp[0]+abs(heights[1]-heights[0]);
            for(int ni=2;ni<n;++ni)
            {
                dp[ni]=min(dp[ni-1]+abs(heights[ni]-heights[ni-1]),dp[ni-2]+abs(heights[ni]-heights[ni-2]));
            }
            pw.println(dp[n-1]);
        }

        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;
int MOD = 1e9 + 7;

int main(){
    int a; cin >> a;
    string s; cin >> s;
    if(a < 3200) cout << "red" << endl;
    else cout << s << endl;
}

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



int main(void) {
  ll n, m;
  cin >> n >> m;

  if (n * 2 >= m) {
    cout << m / 2 << endl;
  }
  else {
    cout << n + (m - 2 * n) / 4 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		ll u,v;
		cin>>u>>v;
		long double temp,r;
		temp=u*u+v*v;
		r=sqrt(temp);
		// cout<<r<<" ";
		if(r<=m)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3668
dice = input().split()
div1 = [[0, 1, 5, 4], [0, 3, 5, 2], [1, 3, 4, 2]]
div2 = [[2, 3], [1, 4], [5, 0]]
for i in range(int(input())):
    x = 0
    a, b = [dice.index(j) for j in input().split()]
    for j, k in zip(div1, div2):
        if a in j and b in j:
            if j.index(a) < j.index(b):
                x = k[0]
            else:
                x = k[1]
            if abs(j.index(a) - j.index(b)) == 3:
                x = 5 - x
    print(dice[x])



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;
ll n;

double dp[310][310][310];

double ans(ll i, ll j, ll k)
{
    double res = 0.0;
    if(dp[i][j][k] >= 0.0) return dp[i][j][k];
    if(i == 0 && j == 0 && k == 0) return 0.0;
    if(i > 0) res += ans(i-1,j,k)*(double)i;
    if(j > 0) res += ans(i+1, j-1, k)*(double)j;
    if(k > 0) res += ans(i,j+1,k-1)*(double)k;
    res += (double)n;
    res *= 1.0/(double)(i + j + k);
    return dp[i][j][k] = res;
}

int main()
{
    ll i,j;
    cin >> n;
    ll one = 0, two = 0, three = 0;
    for(i = 0;i < n;++i){
        ll a;
        cin >> a;
        if(a == 1) ++one;
        else if(a == 2) ++two;
        else ++three; 
    }
    memset(dp, -1.0, sizeof(dp));
    cout << fixed << setprecision(10) << ans(one, two, three) << endl;

    return 0;
}

Measured memory_bytes: 233088
//============================================================================
// Name        : q
// Date        : Mon Mar  4 22:28:40 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define jam(x, n) cout << "Case #" << x << ": " << n << "\n"
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

// one-index based bit tree.
template <class T>
struct Bit {
    vector<T> x;
    Bit(int n) : x(n + 1) {}

    void add(int k, T a) {
        for (; k < sz(x); k += (k & -k)) {
            x[k] = max(x[k], a);
        }
    }

    // query [1...k]
    T query(int k) {
        T s = 0;
        for (; k > 0; k -= (k & -k)) {
            s = max(s, x[k]);
        }
        return s;
    }
};


void solve() {
    int n; cin >> n;
    vi h(n), a(n);
    fori (i, 0, n) {
        cin >> h[i];
    }

    fori (i, 0, n) {
        cin >> a[i];
    }

    Bit<ll> bit(n);
    vl dp(n);
    fori (i, 0, n) {
        // Query maximum value in range [1...h[i]], if we found one,
        // there must have h[i] > h[j] (j < i) satisfied.
        dp[i] += bit.query(h[i]) + a[i];
        bit.add(h[i], dp[i]);
    }

    // trace(h, a, dp);
    output(bit.query(n));
}

void test() {
    Bit<int> bit(5);
    vi aa = {1, 2, 3, 4, 5};
    bit.add(1, 1);
    bit.add(2, 2);
    bit.add(3, 3);
    bit.add(5, 5);
    trace(bit.query(1));
    trace(bit.query(2));
    trace(bit.query(3));
    trace(bit.query(5));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    // test();
    return 0;
}



Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int loop = 1;

            while (Math.Pow(2, loop) <= N)
            {
                loop++;
            }

            Console.WriteLine(Math.Pow(2, loop - 1));
        }
    }
}


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

using namespace std;

int n,i,j,a[105];

int main(){
	scanf("%d", &n);
	
	int s = 0;
	
	vector <int> tmp;
	
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
		s += a[i];
		tmp.push_back(a[i]);
	}
	
	sort(tmp.begin(), tmp.end());
	
	if(s % 10 != 0)
	printf("%d\n", s);
	else{
		for(i = 0; i < tmp.size(); i++){
			if(tmp[i] % 10 != 0)
			return 0 * printf("%d\n", s - tmp[i]);
		}
		printf("0\n");
	}
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
int dist[1002][1002];
int h,ww;
int x,y,z,w;
deque<pair<int,int>> que;

int rec(){
	dist[x][y]=0;
	que.PB(MP(x,y));
    while(que.size()){
        pal t=que.front(); que.pop_front();
        for(int i=0;i<4;i++){
            if(dist[t.F+dx[i]][t.S+dy[i]]>dist[t.F][t.S]){
                if(t.F+dx[i]>1001 || t.F+dx[i]<1 ||t.S+dy[i]>1001 || t.S+dy[i]<1 ) continue;
                dist[t.F+dx[i]][t.S+dy[i]]=dist[t.F][t.S];
                que.push_front(MP(t.F+dx[i],t.S+dy[i]));
            }
        }
        for(int i=-2;i<3;i++){
        	for(int j=-2;j<3;j++){
                if(i==0&&j==0) continue;
                if(t.F+i>1001 || t.F+i<1 ||t.S+j>1001 || t.S+j<1 ) continue;
            	if(dist[t.F+i][t.S+j]>dist[t.F][t.S]+1){
                    
                	dist[t.F+i][t.S+j]=dist[t.F][t.S]+1;
                	que.push_back(MP(t.F+i,t.S+j));
            	}
        	}
    	}
    }
    
	return 0;

}

int main(){

    cin >> h >> ww >> x >> y>> z>>w;

    fill(dist[0],dist[0]+1002*1002,-1);

    
    for(ll i=1;i<=h;i++){
        for(ll j=1;j<=ww;j++){
            char tmp;
            cin >> tmp;
            if(tmp =='.'){
                dist[i][j]=1000000;
            }
        }
    }
    rec();

    if(dist[z][w]==1000000){
        cout << -1 << endl;
    }else{
        cout << dist[z][w] << endl;
    }
    return 0;
}


Measured memory_bytes: 7556
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    for (int i = 1;; i++) {
        n /= k;
        if (n == 0) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <map>
#include <list>
#include <set>

using namespace std;

typedef long long ll;

int main() {

    int n, a ,b;
    cin >> n >> a >> b;

    cout << (int)min(n*a,b);
    return 0;
}

Measured memory_bytes: 256
var t:longint;
    a:int64;
    c:char;
begin
  while not eoln do
  begin
    read(c);
    if c='A' then
      inc(t);
    if c='B' then
    begin
      read(c);
      if c='C' then
      begin
        inc(a,t);
        continue;
      end
      else
        if c='A' then
          t:=1
        else
          t:=0;
    end;
    if c='C' then
      t:=0;
  end;
  writeln(a);
end.

Measured memory_bytes: 128
from subprocess import*
call(('python3','-c',"""
import sys
sys.setrecursionlimit(10**6)
e=enumerate
def dfs(v):
  d=sorted(map(dfs,t[v]))
  l=len(d)
  return max([0]+[l-i+d for i,d in e(d)])
n,*a=map(int,open(0))
t=[[]for _ in[0]+a]
for i,v in e(a,1):t[v-1]+=i,
print(dfs(0))
"""))

Measured memory_bytes: 253512
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time



def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

def rec(li, i, M, N, a, b, c, d, cans):
    # print(i, li, len(li), N)
    if len(li) >= N:
        # print(li, N)
        ans = 0
        for j in range(len(a)):
            if li[b[j]-1] - li[a[j]-1] == c[j]:
                ans += d[j]
        # print(ans, li)
        return ans

    # for j in range(1, len(lis[i])):
    #     for v in lis[i][j]:

    ans = 0
    if len(cans[i]) == 0:
        ans = max(ans, rec(li + [1], i+1, M, N, a, b, c, d, cans))
    else:
        for v in cans[i]:
            ans = max(ans, rec(li + [v], i+1, M, N, a, b, c, d, cans))

    return ans


def main():
    N, M, Q = MI()
    a = [0] * Q
    b = [0] * Q
    c = [0] * Q
    d = [0] * Q
    didx = [None] * Q
    lis = [[[] for i in range(N+1)] for i in range(N+1)]
    cans = [set() for i in range(N+1)]

    for i in range(Q):
        a[i], b[i], c[i], d[i] = MI()
        # didx[i] = (d[i], i)

    ans = 0
    A = [i for i in range(1, M + 1)]
    for v in itertools.combinations_with_replacement(A, N):
        tmp = 0
        for j in range(len(a)):
            if v[b[j]-1] - v[a[j]-1] == c[j]:
                tmp += d[j]
        ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69304
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string S; cin >> S;
	string F, B;
	while (S.size() != 0) {
		S.pop_back();
		F = " "; B = " ";
		if (S.size() % 2 == 0) {
			for (int i = 0; i < S.size() / 2; i++) F += S[i];
			for (int i = S.size() / 2; i < S.size(); i++) B += S[i];
			if (F == B) {
				cout << S.size() << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}
vector<vector<lli>> a;
vector<lli> dp1;
vector<lli> dp2;
vector<lli> vis;
lli n;
void filldp(){
	// dp1 gives the score for each subset mask
	dp1[0]=0;
	for(lli mask=1;mask<(1<<n);mask++){
		for(lli i=0;(1<<i)<=mask;i++){
			if((mask&(1<<i))==0)continue;
			for(lli j=0;(1<<j)<=mask;j++){
				if((mask&(1<<j))==0)continue;
				dp1[mask]+=a[i][j];
			}
		}
		dp1[mask]/=2;
	}
}
lli go(lli mask){
	if(vis[mask])return dp2[mask];
	vis[mask]=1;
	if(num1bit(mask)==1)return dp2[mask]=0;
	dp2[mask]=dp1[mask];
	for(lli ss=(mask-1)&mask;ss>0;ss=(ss-1)&mask){
		dp2[mask]=max(dp2[mask],dp1[ss]+go(mask-ss));
	}
	return dp2[mask];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	a.assign(n,vector<lli>(n));	
	for(lli i=0;i<n;i++){
		for(lli j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	dp1.assign(1<<n,0);
	dp2.assign(1<<n,0);
	vis.assign(1<<n,0);
	filldp();
	cout<<go((1<<n)-1)<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

using namespace std;

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

    int n, k;
    scanf("%d%d", &n, &k);

    vector<int> costs(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &costs[i]);
    }

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j <= i + k and j < n; ++j) {
            dp[j] = min({dp[j], dp[i] + abs(costs[i] - costs[j])});
        }
    }

    printf("%d", dp[n - 1]);
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

ll calc(ll n,int a){
    ll num = 1;
    rep(i,0,n){
        num = num*a%mod;
    }
    return num%mod;
}

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll ans = 0;
    ll num = 1;
    ans = (ans+calc(n,10))%mod;
    ans = (ans-calc(n,9)+mod)%mod;
    ans = (ans-calc(n,9)+mod)%mod;
    ans = (ans+calc(n,8))%mod;
    cout<<ans<<endl;
}

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

int main() {
    int p,q,r;
    cin >> p >> q >> r;
    int n = max(max(p,q),r);
    cout << p+q+r-n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,string> P;
const int INF=1e9+1;
int dat[50];
int n;
void rec(int p,int c){
      int tmp[50];
      REP(i,n)tmp[i]=dat[i];
      for(int i=0;i<c;i++)tmp[i]=dat[i+p-1];
      for(int i=c;i<c+p-1;i++)tmp[i]=dat[i-c];
      REP(i,n)dat[i]=tmp[i];
}
int main(){
      int r;
      while(cin>>n>>r&&(n||r)){
            REP(i,n)dat[i]=n-i;
            REP(i,r){
                  int a,b;
                  cin>>a>>b;
                  rec(a,b);
            }
            cout<<dat[0]<<endl;
      }
}

Measured memory_bytes: 1160
A, B, N = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
l.append(min(a) + min(b))
for _ in range(N):
  aq, bq, d = map(int, input().split())
  l.append( a[aq-1] + b[bq-1] - d )
print(min(l))

Measured memory_bytes: 24832
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char c;
bool flag;
int main()
{
	while(cin>>c)
	{
		if(c=='C') flag=1;
		if(c=='F'&&flag)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	int a[n][m];
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j];
	int b[m];
	for(int &i:b) cin >> i;
	int c[n]{};
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) c[i] += a[i][j] * b[j];
	for(int &i:c) cout << i << endl;
}

Measured memory_bytes: 3096
#include<stdio.h>
#include<math.h>
int main(){
  
  int n,i,j,cnt,a[10000];
  cnt=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  for(i=0;i<n;i++){
    
    if(a[i] == 2 || a[i] == 3) cnt++;
    
    if(a[i] > 3){
      for(j=2;j<=(int)sqrt(a[i]);j++){
	if(a[i] % j == 0) break;
	if(j == (int)sqrt(a[i])){cnt++;break;} 
      }
    }
  }
  printf("%d\n",cnt);
}


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

typedef long long ll;

const int mod = 1000000007;
const int Maxn = 1000005;

int mx[Maxn];
int n;
int a[Maxn];
int got[Maxn];
int res;

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int main()
{
    for (int i = 2; i < Maxn; i++) if (mx[i] == 0)
        for (int j = i; j < Maxn; j += i)
            mx[j] = i;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        res = (res + toPower(a[i], mod - 2)) % mod;
        int num = a[i];
        while (num > 1) {
            int cur = mx[num];
            int cnt = 0;
            while (mx[num] == cur) {
                cnt++; num /= cur;
            }
            got[cur] = max(got[cur], cnt);
        }
    }
    for (int i = 0; i < Maxn; i++) if (got[i])
        res = ll(res) * toPower(i, got[i]) % mod;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int main()
{
  int h, w;
  int a, b;
  while(1){
    cin >> h >> w;
    if(h==0 && w==0) break;
    for(a=0; a<h; a++){
      for(b=0; b<w; b++){
	if((b%2==0&&a%2==0)||(b%2==1&&a%2==1)){
	  cout << "#";
	}else{
	  cout << ".";
	}
	
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数・K - 取得
	int liK;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siACnt, &liK);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 合計
	int liSum = 0;
	for (i = 0; i < liK; i++) {
		liSum += si1Array[i];
	}

	// 最大値
	int liMax = liSum;
	for (i = liK; i < siACnt; i++) {
		liSum += si1Array[i];
		liSum -= si1Array[i - liK];
		if (liMax < liSum) {
			liMax = liSum;
		}
	}
	double ldMax = (double)(liMax + liK) / 2.0;

	// 出力
	sprintf(lc1Buf, "%.7lf\n", ldMax);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1Array, 0, sizeof(si1Array));						// 配列

																// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

vector<int>g[26];
int main()
{
    string s,t;
    cin >> s >> t;
    for(int i = 0;i < s.size();i++){
        int d = s[i] - 'a';
        g[d].push_back(i);
    }
    LL done = -1,complete = 0;
    for(int i = 0;i < t.size();i++){
        int d = t[i] - 'a';
        auto it = upper_bound(g[d].begin(),g[d].end(),done);
        if(it == g[d].end()){
            complete++;
            done = -1;
            it = upper_bound(g[d].begin(),g[d].end(),done);
            if(it == g[d].end()){
                cout << -1 << "\n";return 0;
            }
            done = *it;
        }else{
            done = *it;
        }
    }
    cout << complete * s.size() + done + 1 << "\n";
}



Measured memory_bytes: 1216
n = int(input())
lst = [x for x in input().split()]

lst1 = lst[0::2]
lst2 = lst[1::2]

if n % 2 == 0:
    lst2.reverse()
    ret = lst2 + lst1
else:
    lst1.reverse()
    ret = lst1 + lst2

print(" ".join(ret))


Measured memory_bytes: 27044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps=1e-10;
const int N=2e3+5,M=1900,C=100,mod=1e9+7;
ll dp[N][N],pre[N][N];
int n,m,a[N];
void work()
{
	dp[1][1]=pre[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			if(a[i])//i is after i-1.
				dp[i][j]=pre[i-1][j-1];
			else
				dp[i][j]=(pre[i-1][i-1]-pre[i-1][j-1]+mod)%mod;
		}
		for(int j=1;j<=i;j++)
			pre[i][j]=(pre[i][j-1]+dp[i][j])%mod;
	}
	cout<<pre[n][n]<<endl;
}
bool equ(double a,double b)
{
	if(fabs(a-b)<eps)
		return true;
	return false;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	double p=1;
	for(int i=1;i<=m;i++)
		p=p/2.0;
	double q=1.0-p,win=1;
	double i=1,ans=0;
	while(true)
	{
		if(win==1)
			win*=p;
		else
			win*=q;
		double x=win*(M*m+(n-m)*C)*i;
		if(equ(x,0))
			break;
		ans+=x;
		i++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

use_clipboard=True
bbn=1000000007
	
#+++++

		
def main():
	h, a = map(int, input().split())
	ret = (h+a-1)//a
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
const int maxn=300+10;
template<typename T> void read(T &x){
	T f=1;x=0;
	char c=getchar();
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	x*=f;
}
bool cmp(double a,double b){
	return a>b;
}
double n;
int a[maxn];
double pre[maxn];
double ans=0;
double f[maxn][maxn][maxn];
int cnt[4];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(re int i=1;i<=n;i++){
		cin>>a[i];	
		cnt[a[i]]++;
	}
	for(re int k=0;k<=cnt[3];k++){
		for(re int j=0;j<=cnt[2]+cnt[3];j++){
			for(re int i=0;i<=cnt[1]+cnt[2]+cnt[3];i++){
				double tmp=i+j+k;
				if(!tmp) continue;
				f[i][j][k]+=n/tmp;
				if(i)
					f[i][j][k]+=f[i-1][j][k]*i/tmp;
				if(j)
					f[i][j][k]+=f[i+1][j-1][k]*j/tmp;
				if(k)
					f[i][j][k]+=f[i][j+1][k-1]*k/tmp;
			}
		}
	}
	cout<<fixed<<setprecision(10)<<f[cnt[1]][cnt[2]][cnt[3]]<<endl;
	return 0;
}


Measured memory_bytes: 227584
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;
int dp[M+4];
int nxt[M+4];
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    f(i,1,n)
    {
        if(s[i]=='1')dp[i]=inf;
    }
    dp[n]=0;
    set<pi>yo;
    yo.insert(mp(dp[n],n));
    rf(i,n-1,0)
    {
        if(s[i]=='1')
        {
            yo.insert(mp(dp[i],i));
            continue;
        }
        int lft=i+1,rgt=min(i+m,n);
        while(1)
        {
            pi chk=*yo.begin();
            if(chk.si>rgt)
            {
                yo.erase(yo.begin());
            }
            else break;
        }
        pi x=*yo.begin();
        dp[i]=1+dp[x.si];
        nxt[i]=x.si;
        yo.insert(mp(dp[i],i));
    }
    if(dp[0]>=inf)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int cur=0;
    while(1)
    {
        int x=nxt[cur];
        int gap=x-cur;
        cout<<gap<<" ";
        cur=x;
        if(cur==n)break;
    }
    cout<<endl;
    return 0;

}





































Measured memory_bytes: 8144
#include <stdio.h>
#include <math.h>

#define N 999999

int main()
{
  int i,j,n;
  char prime[N];

  for (i=0;i<N;i++){
    prime[i]=1;
  }
  prime[0]=0;
  for (i=1;i<(int)sqrt(N);i++){
    if (prime[i]==1){
      for (j=i+1;(i+1)*j<=N;j++){
        prime[(i+1)*j-1]=0;
      }
    }
  }
  while (scanf("%d",&n)){
    if (n==0)
      break;
    int cnt=0,sum=0;
    for (i=0;i<N;i++){
      if (prime[i]==1){
        sum+=i+1;
        cnt++;
      }
      if (cnt>=n)
        break;
    }
    printf("%d\n",sum);
  }

  return 0;
}

Measured memory_bytes: 1576
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func small(N, X, M int) {
	a := X
	ans := X
	for i := 2; i <= N; i++ {
		a *= a
		a %= M
		ans += a
	}
	out(ans)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, X, M := getInt(), getInt(), getInt()

	// if N < 1000000000 {
	// 	small(N, X, M)
	// return
	// }

	m := make([]int, M)
	b := make([]int, 0)
	last := -1
	a := X
	b = append(b, a)
	tot := a
	m[a]++
	for i := 1; i < N; i++ {
		a *= a
		a %= M
		if m[a] != 0 {
			last = a
			break
		}
		if a == 0 {
			out(tot)
			return
		}
		tot += a
		m[a]++
		b = append(b, a)
	}
	if last == -1 {
		out(tot)
		return
	}
	start := 0
	ans := 0
	for i := 0; i < len(b); i++ {
		if b[i] == last {
			start = i
			break
		}
		ans += b[i]
		tot -= b[i]
	}
	N -= start
	loop := len(b) - start
	// out(N, loop, tot)
	n := N / loop
	ans += n * tot
	rest := N % loop
	for i := 0; i < rest; i++ {
		ans += b[start+i]
	}
	// out(n*loop + rest)
	out(ans)
}


Measured memory_bytes: 4940