akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector <int> a(n + 1);
  vector <int> b(n + 1);
  vector <int> c(n + 1);
  vector <vector <int> > dp(n + 1, vector <int>(3, 0));
  REP1(i, n) {
	cin >> a[i] >> b[i] >> c[i];
  }
  REP1(i, n) {
	dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
	dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
	dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
  return 0;
}


Measured memory_bytes: 6912
package main

import (
  "fmt"
)

func main() {
  var A, B int
  fmt.Scanf("%d %d", &A, &B)
  
  sum := A + B
  sub := A - B
  mul := A * B
  
  result := sum
  if result < sub {
  	result = sub
  }
  if result < mul {
  	result = mul
  }
  
  fmt.Println(result)
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string a,b,e;
    int c,d;
    cin >> a >> b >> c >> d >> e;
    if(a == e){
        c--;
    }else{
        d--;
    }
    cout << c << " " << d << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>

using namespace std;

struct SegmentTree{

    vector<int> data;
    vector<int> lazy;
    int n;

    SegmentTree(int n_){
        n=1;
        while(n<n_)n*=2;
        data.resize(n*2-1);
        lazy.resize(n*2-1);
    }

    void eval(int k,int a,int b){
        data[k]+=lazy[k];
        if(k<n-1){
            lazy[2*k+1]+=lazy[k]/2;///合計なので
            lazy[2*k+2]+=lazy[k]/2;///半分にして追加している
        }
        lazy[k]=0;
    }

    void add(int a,int b,int x,int k,int l,int r){
        eval(k,l,r);

        if(l>=b||r<=a)return;
        if(l>=a&&r<=b){
            lazy[k]+=(r-l)*x;///合計なのでr-lを掛けている
            eval(k,l,r);
            return;
        }
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
        data[k]=(data[2*k+1]+data[2*k+2]);///合計なので子ノードの和
    }

    void add(int a,int b,int x){
        add(a,b,x,0,0,n);
    }

    int getSum(int a,int b,int k,int l,int r){
        eval(k,l,r);

        if(l>=b||r<=a)return 0;
        if(l>=a&&r<=b)return data[k];

        return (getSum(a,b,2*k+1,l,(r+l)/2) + getSum(a,b,2*k+2,(r+l)/2,r));///合計なので子ノードの和
    }

    int getSum(int a,int b){
        return getSum(a,b,0,0,n);
    }

};

int main(){


    vector<int> length;

    int N,M;cin>>N>>M;
    vector<pii> pairs[M+1];

    REP(i,N) {
        int l,r;cin>>l>>r;r++;
        length.push_back(r-l);
        pairs[r-l].push_back({l,r});
    }

    sort(ALL(length));
    SegmentTree seg(M+1);
    //遅延SegTree
    //調べてる長さ以下の長さの(l,r)をsegtreeに追加
    //sum[i]+sum[2*i]+sum[3*i]...を計算
    REP(i,M){
        int ans=length.end() - lower_bound(ALL(length),i+1);
        for (pii p : pairs[i])seg.add(p.first,p.second,1);
        for(int p = i+1;p<=M;p+=i+1)ans+=seg.getSum(p,p+1);
        cout<<ans<<endl;
    }


    return 0;
}

Measured memory_bytes: 11892
main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      print $ solve n
      main


solve :: Int -> Int
solve n = fix $ to8 n
  where
    to8 :: Int -> Int
    to8 0 = 0
    to8 n = (n `mod` 8) + 10 * (to8 (n `div` 8))
    fix :: Int -> Int
    fix n = (read . fix') (show n)
      where
        fix' :: String -> String
        fix' [] = []
        fix' (x:xs)
          | x == '4' = '5':(fix' xs)
          | x == '5' = '7':(fix' xs)
          | x == '6' = '8':(fix' xs)
          | x == '7' = '9':(fix' xs)
          | otherwise = x:(fix' xs)

Measured memory_bytes: 4076
S = input()
Q = int(input())

r = False
prefix = []
suffix = []
for _ in range(Q):
    query = input()
    if query == '1':
        r ^= True
    else:
        _, f, c = query.split()
        front = f == '1'

        if r ^ front:
            prefix.append(c)
        else:
            suffix.append(c)

if r:
    S = ''.join(suffix[::-1]) + S[::-1] + ''.join(prefix)
else:
    S = ''.join(prefix[::-1]) + S + ''.join(suffix)

print(S)


Measured memory_bytes: 12140
s=int(input())
a=[0]*10**6
a[0]=s

def f(x):
  if x%2==0:
    return x//2
  else:
    return 3*x+1
t=0 
while f(a[t])>0:
  p=f(a[t])
  if p in a:
    print(t+2)
    exit()
  a[t+1]=p
  t+=1
  

Measured memory_bytes: 16584
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a*b%2==1){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	int N;
	cin >> N;

	cout << N / 3 << endl;

	return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
now = n
for i in range(1,n+1):
  if now == i:
    key = -1
    top = i
    break
  elif now - i < 0:
    key = i - now
    top = i
    break
  else:
    now -= i
for i in range(1,top+1):
  if i != key:print(i)

Measured memory_bytes: 3700
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get!(usize);
    let mut cs = Vec::new();
    let mut ss = Vec::new();
    let mut fs = Vec::new();
    for _ in 1..n {
        let (c, s, f) = get!(i64, i64, i64);
        cs.push(c);
        ss.push(s);
        fs.push(f);
    }
    for x in 0..n-1 {
        let mut t = 0;
        for i in x..n-1 {
            if t < ss[i] { t = ss[i]; }
            if t % fs[i] != 0 { t += fs[i] - t % fs[i]; }
            t += cs[i];
        }
        println!("{}", t);
    }
    println!("0");
}

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

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int kai = 6 - a - b;

            Console.Write(kai);
        }
    }
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("111100");
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("001001");
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("000000");
            //0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];
        Console.WriteLine(S.ToCharArray().Count(X => X == '1'));
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <cstring>
#include <deque>

using namespace std;

int L, C, W, S;
deque<string> lines;

void Print() {
  if (lines.size() < L*C) lines.resize(L*C);
  for (int i = 0; i < L; ++i) {
    string buf(W*C + S*(C-1), '.');
    for (int j = 0; j < C; ++j) {
      memcpy(&buf[(W+S)*j], lines[L*j+i].data(), lines[L*j+i].size());
    }
    cout << buf << endl;
  }
  cout << "#" << endl;
  lines.erase(lines.begin(), lines.begin() + L*C);
}

int main() {
  while (cin >> L >> C >> W >> S && L) {
    lines.clear();
    string line;
    getline(cin, line);
    while (getline(cin, line) && line != "?") {
      if (line.empty()) {
	lines.push_back(line);
      } else {
	for (int x = 0; x < line.size(); x += W) {
	  lines.push_back(line.substr(x, W));
	}
      }
      while (lines.size() > L*C) Print();
    }
    if (!lines.empty()) Print();
    cout << "?" << endl;
  }
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int search(int a[],int n, int key){
    int left = 0;
    int right = n;
    while(left < right){
        int mid = (left + right)/2;
        if(a[mid] == key) return 1;
        else if(key < a[mid]) right = mid;
        else left = ++mid;
    }
    return 0;
}
int main(){
    int n,q,ans = 0;
    cin >> n;
    int s[n+1];
    REP(i,n) cin >> s[i];
    cin >> q;

    REP(i,q){
        int t;
        cin >> t;
        ans += search(s,n,t);
    }
    cout << ans << endl;
}




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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] cnt = new int[200005];
		for(int i=0;i<n;i++){
			cnt[sc.nextInt()]++;
		}
		
		Arrays.sort(cnt);
		
		int r = 0;
		for(int i=cnt.length-1-k;i>=0;i--){
			if(cnt[i]!=0)
				r+=cnt[i];
			else
				break;
		}
		
		System.out.println(r);
	}

}


Measured memory_bytes: 64648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n;
    deque<ll> a;
    deque<ll> b;

    cin >> n;
    rep(i, 0, n){
        ll t;
        cin >> t;
        a.push_back(t);
    }
    sort(a.begin(), a.end(), greater<ll>());

    ll sum1 = 0, sum2 = 0;
    if(n % 2 == 1){
        rep(i, 0, n){
            if(i <= n / 2 - 1){
                sum1 += a[i] * 2;
            }else if(i <= n / 2 + 1){
                sum1 -= a[i];
            }else{
                sum1 -= a[i] * 2;
            }
        }
        rep(i, 0, n){
            if(i <= n / 2 - 2){
                sum2 += a[i] * 2;
            }else if(i <= n / 2){
                sum2 += a[i];
            }else{
                sum2 -= a[i] * 2;
            }
        }
        cout << max(sum1, sum2) << endl;
    }else{
        rep(i, 0, n){
            if(i <= n / 2 - 2){
                sum1 += a[i] * 2;
            }else if(i <= n / 2 - 1){
                sum1 += a[i];
            }else if(i <= n / 2){
                sum1 -= a[i];
            }else{
                sum1 -= a[i] * 2;
            }
        }
        cout << sum1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    string s;
    cin >> s;
    if (s.size() % 2 == 0) {
        auto l = s.size() / 2;
        auto a = s.substr(0, l);
        auto b = s.substr(l, l);
        if (a == b) {
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	
	int N;
	cin >> N;
	for(int cnt = 0; cnt < N; cnt++) {
		string s[2];
		int num[2][4];
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 4; j ++)
				num[i][j] = 0;
		stringstream ans;
		cin >> s[0] >> s[1];

		//数値解析
		for(int i = 0; i < 2; i++) {

			//千の位
			int tmp = s[i].find("m",0);
			if(tmp == string::npos)		num[i][3] = 0;
			else if(tmp == 0)			num[i][3] = 1;
			else num[i][3] = s[i].at(0) - '0' ;

			//百の位
			tmp = s[i].find("c",0);
			if(tmp == string::npos)		num[i][2] = 0;
			else if( tmp == 0 || s[i].at( tmp - 1 ) > '9' ) num[i][2] = 1;
			else num[i][2] = s[i].at(tmp - 1) - '0' ;

			//十の位
			tmp = s[i].find("x",0);
			if(tmp == string::npos)		num[i][1] = 0;
			else if( tmp == 0 || s[i].at( tmp - 1 ) > '9' ) num[i][1] = 1;
			else num[i][1] = s[i].at( tmp - 1 ) - '0';

			//一の位
			tmp = s[i].find("i",0);
			if(tmp == string::npos)		num[i][0] = 0;
			else if( tmp == 0 || s[i].at( tmp - 1 ) > '9' ) num[i][0] = 1;
			else num[i][0] = s[i].at( tmp - 1 ) - '0';

		}

		int p[2];
		for(int i = 0; i < 2; i++) p[i] = num[i][3]*1000 + num[i][2]*100 + num[i][1]*10 + num[i][0];
		
		int ans_i = p[0] + p[1];

		//答えの文字列の生成
		if( ans_i / 1000 > 1) {
			ans << ans_i / 1000;
			ans << "m";
		} else if(ans_i / 1000 == 1) {
			ans << "m";
		}
		ans_i -= ans_i/1000*1000;
		//答えの文字列の生成
		if( ans_i / 100 > 1) {
			ans << ans_i / 100;
			ans << "c";
		} else if(ans_i / 100 == 1) {
			ans << "c";
		}
		ans_i -= ans_i/100*100;
		//答えの文字列の生成
		if( ans_i / 10 > 1) {
			ans << ans_i / 10;
			ans << "x";
		} else if(ans_i / 10 == 1) {
			ans << "x";
		}
		ans_i -= ans_i/10*10;
		//答えの文字列の生成
		if( ans_i / 1 > 1) {
			ans << ans_i / 1;
			ans << "i";
		} else if(ans_i / 1 == 1) {
			ans << "i";
		}
		
		cout << ans.str() << endl;

	}

	
	//while(1){}
	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int length,pos;
    cin >> length;
    
    string message;
    cin >> message;
    
    cin >> pos;
    
    string target =  message.substr(pos-1,1);
    
    string ans = "";
    for(int i=0; i<length; i++)
    {
        if(message.substr(i,1) != target)
        {
            ans +="*";
        }
        else
        {
            ans +=target;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [int(input()) for _ in range(n)]
A.sort()
if n%2==1:print(max(2*sum(A[n-n//2:])-sum(A[n-n//2-2:n-n//2])-2*sum(A[:n-n//2-2]),-2*sum(A[:n//2])+sum(A[n//2:n//2+2])+2*sum(A[n//2+2:])))
else:print(-2*sum(A[:(n-2)//2])-A[(n-2)//2]+A[(n-2)//2+1]+2*sum(A[(n-2)//2+2:]))

Measured memory_bytes: 7504
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A <= 9 && B <= 9) {
      System.out.println(A * B);
    } else {
      System.out.println(-1);
    }
  }
}

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

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  int ret = 0;
  for (int i = 0; i < n - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
N = input()

maxn = 0
cnt = 0
for i in N:
    if i == "A" or i == "T" or i == "G" or i == "C":
        cnt += 1
    else:
        if maxn < cnt:
            maxn = cnt
        cnt = 0

if maxn < cnt:
    maxn = cnt

print(maxn)



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

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        const int sz = 723,
                  base = 539;
        int sum[m][sz] = {};

        int r;
        cin >> r;
        rep (i, r) {
            int t, nn, mm, s;
            cin >> t >> nn >> mm >> s;
            t -= base;
            mm--;

            if (s) sum[mm][t] += 1;
            else   sum[mm][t] += -1;
        }

        rep (i, m) {
            rep (j, sz - 1) {
                sum[i][j + 1] += sum[i][j];
                sum[i][j] = abs(sum[i][j]) > 1 ? sum[i][j] > 0 ? 1 : -1 : sum[i][j];
            }
            sum[i][sz - 1] = abs(sum[i][sz - 1]) > 1 ? sum[i][sz - 1] > 0 ? 1 : -1 : sum[i][sz - 1];
        }

        rep (i, m) rep (j, sz - 1) {
            sum[i][j + 1] += sum[i][j];
        }

        int q;
        cin >> q;
        rep (i, q) {
            int a, b, c;
            cin >> a >> b >> c;
            a -= base;
            b -= base;
            c--;

            cout << sum[c][b - 1] - sum[c][a - 1] << endl;
        }
    }
    return 0;
}


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

typedef pair<int, int>P;
const int N = 1000010;

int Pri[N];
int X[N];
int Y[N];

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

int mp[1100][1100];

vector<P>vec;

void init(){
    for(int i=0;i<N;i++){
        Pri[i] = 1;
    }
    Pri[0] = 0;
    Pri[1] = 0;
    for(int i=2;i*i<=N;i++){
        if(Pri[i]==0)continue;
        for(int j=i+i;j<N;j+=i){
            Pri[j]=0;
        }
    }
    for(int x=550, y=550, CNT=1, p=0, cnt=0, i=1;i<N;){
        mp[x][y] = i;
        X[i] = x;
        Y[i] = y;
        vec.push_back(P(y, i));
        x += dx[p];
        y += dy[p];
        i++;
        cnt++;
        if(cnt==CNT){
            cnt=0;
            p++;
            if(p==2){
                CNT++;
            }
            if(p==4){
                p=0;
                CNT++;
            }
        }
    }
    sort(vec.begin(), vec.end());
}

int main(){

    init();
    for(int m, n;cin>>m>>n, m;){
        int ans = 0, lstmx = 0;
        std::vector<int>tmp(N, -1);
        tmp[n] = 0;
        for(int i=0;i<vec.size();i++){
            int num = vec[i].second;
            if(num > m)continue;
            if(tmp[num] < 0)continue;
            if(Pri[num]){
                tmp[num]++;
                if((tmp[num] > ans) || (tmp[num]==ans && num > lstmx && ans>0)){
                    ans = tmp[num];
                    lstmx = num;
                }
            }
            for(int t = -1; t <= 1; t++){
                int y = Y[num] + 1;
                int x = X[num] + t;
                int nxt = mp[x][y];
                tmp[nxt] = max(tmp[nxt], tmp[num]);
            }
        }

        cout<<ans<<" "<<lstmx<<endl;
    }

    return 0;
}


Measured memory_bytes: 30604
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
map<ll, ll> mp;
ll n, a, b, c, d;
ll dfs(ll x) {
    if(x == 0) return 0;
    if(x == 1) return d;
    if(mp.count(x)) return mp[x];
    ll l2 = (x / 2) * 2, r2 = ((x + 1) / 2) * 2;
    ll l3 = (x / 3) * 3, r3 = ((x + 2) / 3) * 3;
    ll l5 = (x / 5) * 5, r5 = ((x + 4) / 5) * 5;
    ll ans = 1e18;
    if(x < ans / d) ans = x * d;
    ans = min(ans, a + llabs(l2 - x) * d + dfs(l2 / 2));
    ans = min(ans, a + llabs(r2 - x) * d + dfs(r2 / 2));
    ans = min(ans, b + llabs(l3 - x) * d + dfs(l3 / 3));
    ans = min(ans, b + llabs(r3 - x) * d + dfs(r3 / 3));
    ans = min(ans, c + llabs(l5 - x) * d + dfs(l5 / 5));
    ans = min(ans, c + llabs(r5 - x) * d + dfs(r5 / 5));
    return mp[x] = ans;
}
int main()
{
    int T; scanf("%d", &T);
    while(T--) {
        scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
        mp.clear();
        printf("%lld\n", dfs(n));
    }
    return 0;
}


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

using namespace std;
#define ll long long
#define N 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

ll mpow(ll b, ll ex){
    if (b==1)   return 1;
    long long r = 1;
    while (ex ){
        if (ex&1)   r=(r * b);
        ex = ex >> 1;
        b = (b * b);
    }
    return r;
}

int main() {
	int n,k;
	double f=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
	    if(i>=k)    f++;
	    else{
	        int p=0,q=i;
	        while(q<k){
	            q=q*2;
	            p++;
	        }
	        f+=(float)1/(double)mpow(2,p);
	    }
	}
	//cout<<setprecision(9)<<f;
	cout<<setprecision(10)<<f/(double)n;
	return 0;
}


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

using namespace std;

int main() {
	long n, m = 1e18;
	cin >> n;
	for (int i = 0; i < 5; i++) {
		long a;
		cin >> a;
		m = min(m, a);
	}
	cout << (n - 1) / m + 5 << endl;
	return 0;
}


Measured memory_bytes: 256
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    string s;
    cin >> s;
    if(s[2] == s[3] and s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
s = list(input())
q = int(input())
d = deque()
d.append(0)
now = 1
for i in range(q):
    q1 = list(input())
    if len(q1) == 1:
        now *= -1
    else:
        if q1[2] == "1":
            if now == 1:
                d.appendleft(q1[4])
            else:
                d.append(q1[4])
        else:
            if now == 1:
                d.append(q1[4])
            else:
                d.appendleft(q1[4])
ans = ""
#print(now,d)
while len(d):
    if now == 1:
        a = d.popleft()
    else:
        a = d.pop()
    if a == 0:
        if now == 1:
            for i in range(len(s)):
                ans += s[i]
        else:
            for i in range(len(s)):
                ans += s[-(i+1)]
    else:
        ans += a
print(ans)

Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll x;
	cin >> x;
	ll ans = 1000*(x/500);
	x %= 500;
	ans += 5*(x/5);
	print(ans)
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
// Problem https://atcoder.jp/contests/agc010/tasks/agc010_a
// Reference https://atcoder.jp/img/agc010/editorial.pdf

/**
 * 戦略:奇数と奇数の和は偶数になるので奇数が二つ減り偶数が一つ増える
 * 偶数と偶数の和は偶数になるので偶数が一つ減る
 * 奇数が偶数個あれば奇数は全部偶数になり、この偶数を使えば最終的には一つになる
 * しかし、奇数個だと最後に奇数と偶数が一個ずつ残る
 * これを調べるには単純に全部の数を足して奇数か偶数か調べれば良い
 */
bool solver(int N){

    bool result;
    long long int sum;
    result = true;
    sum = 0;
    for(int j=0;j<N;j++){
        long long int A;
        cin >> A;
        sum = sum + A;
    }
    // cout << "sum=" << sum << endl;
    if(sum%2==0){
        result = true;
    }
    else{
        result = false;
    }
    return result;
}

int main(void){
    bool answer;
    answer = true;
    int N;
    cin >> N;
    answer = solver(N);
    if(answer){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll t[2], a[2], b[2];
  cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1];
  if ((a[0] - b[0]) * t[0] + (a[1] - b[1]) * t[1] == 0) {
    cout << "infinity" << endl;
    return 0;
  }
  if ((a[0] - b[0]) * t[0] + (a[1] - b[1]) * t[1] < 0) {
    a[0] ^= b[0];
    b[0] ^= a[0];
    a[0] ^= b[0];
    a[1] ^= b[1];
    b[1] ^= a[1];
    a[1] ^= b[1];
  }
  b[0] -= a[0];
  a[0] = 0LL;
  b[1] -= a[1];
  a[1] = 0LL;
  ll x = b[0] * t[0] + b[1] * t[1];
  x *= -1LL;
  ll ans = 0LL;
  if (b[0] > 0) {
    ans += b[0] * t[0] / x;
    ans *= 2LL;
    if (b[0] * t[0] % x != 0LL) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int i,n,s;
 s=0;
 cin >> n;
 int a[n],b[n];
 for(i=0;i<n;i++)
 {    
  cin >> a[i];
  b[i]=a[i];
  if(i>0)
  b[i]+=b[i-1];
 }
 for(i=(n-1);i>=1;i--)
 s+=a[i]*b[i-1];
 cout << s;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll a, b; cin >> a >> b;
	char m[100][100] = {};
	ll s = 100;

	rep(i, 0, s / 2) {
		rep(j, 0, s) {
			m[i][j] = '#';
		}
	}
	rep(i, s / 2, s) {
		rep(j, 0, s) {
			m[i][j] = '.';
		}
	}
	a--; b--;

	rep(i, 0, s / 2) {
		rep(j, 0, s) {
			if ((i & 1) && (j & 1)) {
				m[i][j] = '.';
				a--;
			}
			if (a == 0)break;
		}
		if (a == 0)break;
	}
	cout << s << " " << s << endl;
	rep(i, s / 2 + 1, s) {
		rep(j, 0, s) {
			if ((i & 1) && (j & 1)) {
				m[i][j] = '#';
				b--;
			}
			if (b == 0)break;
		}
		if (b == 0)break;
	}
	rep(i, 0, s) {
		rep(j, 0, s) {
			cout << m[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def solve(n, k, s):
    u = s + s[::-1]
    t = min(u[i:i + n] for i in range(n + 1))
    i, h = 0, t[0]
    for i, c in enumerate(t):
        if c != h:
            break
    j = i
    for _ in range(k - 1):
        j <<= 1
        if j >= n:
            return h * n
    return h * j + t[i:i + n - j]


n, k = map(int, input().split())
s = input()
print(solve(n, k, s))


Measured memory_bytes: 3064
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,1,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                x=row.index(S[i-1])
                for j in range(x+1,27,1):
                    if row[j] not in S_:
                        S_.append(row[j])
                        break
                S_=''.join(S_)
                print(str(S_))
                break
        else:
            print(row[row.index(S[0])+1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A , B;
  int p , q , r , s , t;
  int x = 0;
  // ここにプログラムを追記
  

    cin >> A >> B;
 for (int i = A; i < B + 1; i++) {
      p = i % 10;
      q = ((i - p) / 10) % 10;
      r = i / 1000;
      s = r % 10;
      t = ((r - s) / 10) % 10;
   
   if (p == t && q == s) {
     x = x + 1;
   }
} 
  
  cout << x << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> vc = {a,b,c};
    sort(vc.begin(), vc.end());
    decltype(vc)::iterator res = unique(vc.begin(), vc.end());
    vc.erase(res, vc.end());
    cout << vc.size() << "\n";
}


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

typedef long long ll;
const ll MOD = 1000000007;

#define MAX 100010

//Fast Exponentiation
ll fexp(ll base, ll exp, ll mod) {
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1)
            result = (result * base) % mod;
        exp >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

int dp[MAX][13], n;
string s;

int solve(int idx, int rem) {
    if (idx >= n) {
        if (rem != 0) return 0;
        return 1;
    }

    if (dp[idx][rem] != -1) return dp[idx][rem];

    if (s[idx] != '?') {
        int r = s[idx] - '0';
        int x = fexp(10, n - 1 - idx, 13);
        int res = (rem - x * r) % 13;
        while (res < 0) res += 13;
        
        dp[idx][rem] = solve(idx + 1, res);
        return dp[idx][rem];
    }

    int ans = 0;
    for (int r = 0; r < 10; r++) {
        int x = fexp(10, n - 1 - idx, 13);
        int res = (rem - x * r) % 13;
        while (res < 0) res += 13;
        ans += solve(idx + 1, res);
        if (ans >= MOD) ans -= MOD;
    }

    dp[idx][rem] = ans;
    return ans;
}

int main() {
    cin >> s;
    n = s.length();
    
    memset(dp, -1, sizeof(dp));
    
    cout << solve(0, 5);

    return 0;
}

Measured memory_bytes: 13312
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
int main()
{
	int a[5];
	rep(i,5)
	{
		cin>>a[i];
		if(a[i]==0) cout<<i+1;
	}
	return 0;
}

Measured memory_bytes: 3524
width,height,n = map(int,input().split())
lst =[]
lost_x_left =0
lost_x_right =0
lost_y_up =0
lost_y_down =0
for i in range(n):
    lst.append(list(map(int, input().split())))
for i in range(n):
    if(lst[i][2] == 1):
        if(lst[i][0] > lost_x_left):
            lost_x_left = lst[i][0]
    elif(lst[i][2] == 2):
        a = width - lst[i][0]
        if(a > lost_x_right):
            lost_x_right = a
    elif(lst[i][2] == 4):
        b = height - lst[i][1]
        if(b> lost_y_up):
            lost_y_up = b
    else:
        if(lst[i][1]> lost_y_down):
            lost_y_down = lst[i][1]
if ((lost_x_left + lost_x_right >= width) or (lost_y_up + lost_y_down >= height)):
    ans =0
else:
    ans = (width-(lost_x_left+lost_x_right)) * (height-(lost_y_up+lost_y_down))


print(ans)    
            

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


int main(){
	int N, W;
	cin >> N >> W;
	vector<long long> w(N), v(N);
	for(int i=0; i<N; i++){
		cin >> w[i] >> v[i];
	}
	
	map<long long, long long> dp;
	dp[0] = 0;
	for(int i=0; i<N; i++){
		auto tmp = dp;
		for(auto p : tmp){
			dp[p.first + w[i]] = max(dp[p.first + w[i]], p.second + v[i]);
		}
	}
	
	long long res = 0;
	for(auto ans : dp){
		if (ans.first <= W){
			res = max(res, ans.second);
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int x = in();
    cout << (abs(x-in())-abs(x-in())>0 ? "B" : "A") << "\n";
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main() {
 
    int n1, k1, d1, a1;
    cin >> n1 >> k1;
 
    bool snack[n1] = {false};
 
    for (int i = 0; i < k1; i++) {
        cin >> d1;
        for (int j = 0; j < d1; j++) {
            cin >> a1;
            snack[a1 - 1] = true;
        }
    }
 
    int c1 = 0;
    for (int i = 0; i < n1; i++) {
        if (!snack[i])
            c1++;
    }
 
    cout << c1;
 
    return 0;
}

Measured memory_bytes: 3644
import itertools as it
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0

s = list(it.accumulate(p))
ss = [s[k-1]]
for i in range(k, n):
    ss.append(s[i] - s[i-k])
    
ans = max(ss)
print((ans+k)/2)

Measured memory_bytes: 25540
#include<bits/stdc++.h>
using namespace std;
long long fnd(const vector<int> &v) {
  const int n = v.size();
  long long ans = 0;
  map<int, int> mp;
  for(int i = 0; i < n; i++) {
    ans += mp[i - v[i]];
    mp[v[i] + i]++;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n; cin >> n;
  vector<int> v(n);
  for(auto &x: v) cin >> x;
  long long ans = fnd(v);
  cout << ans << '\n';
}

Measured memory_bytes: 21116
n,x=map(int,input().split())
l=list(map(int,input().split()))
len=0
res=0
for i in range(n):
  if len>x:
    break
  res=i+1
  len+=l[i]
if res==n and len<=x:
  print(n+1)
else:
  print(res)

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10**6)

(H,W)=map(int,(input().split()))

INF=1000
mymap=list()

for i in range(H):
    mymap.append(input().rstrip())

#print(mymap)

costmap=[[INF for i in range(W)] for j in range(H)]
#print(costmap)

def make_costmap(i,j,prev_state,c):
    #print(i,j,prev_state,c)
    state=mymap[i][j]
    if (prev_state == "." and state=="#"):
        c+=1
    if costmap[i][j] == INF or costmap[i][j]>c:
        costmap[i][j]=c
    else:
        return
        
    if (i<H-1):
        make_costmap(i+1,j,state,c)
    if (j<W-1):        
        make_costmap(i,j+1,state,c)
    return

make_costmap(0,0,".",0)

#for i in range(H):
#    print(mymap[i])
#for i in range(H):
#    print(costmap[i])

print(costmap[H-1][W-1])



Measured memory_bytes: 3188
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//const int inf = 0x3f3f3f3f;
const ll inf = 1ll << 62;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define pi 3.14159265358979323846
#define pc putchar
#define gc getchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
//char __wzp[1<<15|1],*__S=__wzp+32768;
//#define gc() (__S>=__wzp+32768?(__wzp[fread(__wzp,sizeof(char),1<<15,stdin)]=EOF),*((__S=__wzp)++):*(__S++))
#define rd read
#define mem(x,v) memset(x,v,sizeof(x))
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
#define MAXN 100000+233
bool partz,e[MAXN + 1], viz[MAXN + 1];
vector<int> g[MAXN+1];
void dfs(int x) {
	viz[x] = 1;
	int cnt = 0;
	for (auto &y : g[x]) {
		if (viz[y] == 0) {
			dfs(y);
			cnt += 1 - e[y];
		}
	}
	if (cnt == 1) e[x] = 1;
	else if (cnt > 1) partz = 1;
}
signed main() {
	int n;
	scanf("%lld", &n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%lld%lld",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1);
	partz |= 1-e[1];
	if(partz) printf("First\n");
	     else printf("Second\n");
	return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    ll l[n];
    rep(i, n)cin >> l[i];

    ll ans = 0;
    for(ll i = 0; i < n; ++i){
        for(ll j = i+1; j < n; ++j){
            for(ll k = j+1; k < n; ++k){
                if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k])continue;
                ll mx = max(l[i], max(l[j], l[k]));
                ll len = l[i] + l[j] + l[k];

                if(mx < len-mx)ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3668
#include<stdio.h>

#define MAX_CHAR 1000

int main(){

    char num_as_char[MAX_CHAR + 1];
    unsigned int i = 0, sum = 0;

    while(1){

        scanf("%s", num_as_char);
        if(num_as_char[0] == '0') break;

        while (num_as_char[i] != '\0'){
            sum += num_as_char[i] - '0';
            i++;
        }

        printf("%d\n", sum);
        sum = 0;
        i = 0;
    
    }

    return 0;

}


Measured memory_bytes: 2660
using System;

namespace Volume10_1009
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            while(!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                var sep = input.Split(' ');
                var num1 = Convert.ToInt32(sep[0]);
                var num2 = Convert.ToInt32(sep[1]);
                var big = Math.Max(num1, num2);
                var small = Math.Min(num1, num2);

                int residue;
                residue = big % small;
                while (residue > 0)
                {
                    big = small;
                    small = residue;
                    residue = big % small;
                }
                Console.WriteLine(small);
            }
        }
    }
}

Measured memory_bytes: 9060
//Bismillahir-Rahmanir-Rahim
#include <stdio.h>

int main()
{
    char s;
    scanf("%c", &s);
    if(s>='a' && s <='z')
        printf("a");
    else if(s>='A' && s<='Z')
       printf("A");
  return 0;
}









Measured memory_bytes: 1596
MOD = 1000000007
def mod(n):         
  return n % MOD
def multiply(a, b): #mod(a*b)を求める
  return mod(mod(a)*mod(b))
def divide(a, b):   #mod(a / b)を求める
  ans = mod(a) * inverse(b)
  return mod(ans)
def modpow(a, n):   #mod(a**n)を高速で求める
    res = 1  
    digit = len(str(bin(n))) - 2
    for i in range(digit):
      if (n >> i) & 1:
        res *= mod(a)
        res = mod(res)
      a = mod(a**2)
    return mod(res)
def inverse(a):     #aの逆元を求める
  return modpow(a, MOD-2)
def comb(n, k):
  res = 1
  for i in range(k):
    res = multiply(res, n - i) 
  for i in range(k):
    res = divide(res, i + 1)
  return mod(res)

n, a, b = map(int, input().split())
ans = modpow(2, n) - 1
resa = comb(n, a)
resb = comb(n, b)
print(mod(ans - resa - resb))

Measured memory_bytes: 49368
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll a, b, c;
    cin>>a>>b;
    c = pow(b-1, a-1);
    if(a == 1)
    {
    	cout<<b<<endl;
    	return 0;
    }
    else
    {
    	cout<<c*b<<endl;
    }
    return 0;
}

Measured memory_bytes: 4052
import numpy as np

N, W = map(int, input().split())
goods = [tuple(map(int, input().split())) for _ in range(N)]

dp = np.zeros(W + 1, dtype=np.int64)
for n in range(N):
    tmp = np.zeros_like(dp, dtype=np.int64)
    tmp[goods[n][0]:] = dp[:W + 1 - goods[n][0]] + goods[n][1]
    dp = np.maximum(dp, tmp)
print(dp[W])


Measured memory_bytes: 14800
import sys

import math
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
p = na()
q = na()
l = list(itertools.permutations(list(range(1, n+1))))
print(abs(l.index(tuple(p)) - l.index(tuple(q))))

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

using namespace std;
int n;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,n) for(int i = a; i < n; i++)
typedef vector<int> VI;
const int INF = 1e9;
bool check(int i, int j, VI& x, VI& y, VI& r){
  int dist = (x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j]);
  int rdist = (r[i] + r[j]) * (r[i] + r[j]);
  return dist < rdist;
}

bool dp[1<<24];

int func(int bit,VI& ng, VI& c){
  if(dp[bit]++) return -INF;
  int res = 0;

  rep(i,n){
    if((bit>>i) & 1){
      FOR(j,i+1,n){
        if((bit>>j) & 1 && c[i] == c[j] && !(bit&ng[i]) && !(bit & ng[j])) {
          res = max(res, func(bit & ~(1<<i) & ~(1<<j),ng,c) + 2);
        }
      }
    }
  }
  return res;
}


int main(){
  while(true){
    cin >> n;
    if(n == 0) break;
    memset(dp,false,sizeof(dp));

    VI x(n), y(n), r(n), c(n);
    VI ng(n,0);
    rep(i,n){
      cin >> x[i] >> y[i] >> r[i] >> c[i];
      rep(j,i) if(check(i,j,x,y,r)) ng[i] |= 1<<j;
    }
    cout << func((1<<n) - 1,ng,c) << endl;
  }
}



Measured memory_bytes: 19420
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
	int n,m;
  	cin>>n>>m;
  	double a[n];
  	for(int i=0;i<n;i++)cin>>a[i];
  	long long sum=0;
  	for(int i=0;i<m;i++)sum+=a[i];
	long long maxi=sum,ind=0;
  	for(int i=m;i<n;i++){
    	sum=sum-a[i-m]+a[i];
    	if(maxi<sum){maxi=sum;ind=i-m+1;}
    }
  	double ans=0;
  	for(int i=ind;i<(ind+m);i++){
  		ans=ans+(a[i]+1)/2;
  	}
  	cout<<fixed<<setprecision(8)<<ans<<endl;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 1792
#include <map>
#include <string>
#include <queue>
#include <utility>
#include <iostream>

using namespace std;

typedef pair<int,string> P;

int main(){
  
  int d[4] = {-1,1,-4,4};
  
  map<string,int> ans;
  
  ans["01234567"] = 0;
  
  queue<P> que;
  
  que.push(P(0,"01234567"));
  
  while(que.size()){
    P p = que.front(); que.pop();
    int k = ans[p.second];
    for(int i = 0;i < 4;i++){
      
      int n = p.first + d[i];
      if(i == 0 && n == 3)continue;
      if(i == 1 && n == 4)continue;
      if(n >= 0 && n < 8){
	string tmp;
	tmp = p.second;
	
	tmp[p.first] = tmp[n];
	tmp[n] = '0';
	
	if(ans.find(tmp) == ans.end()){
	  ans[tmp] = k + 1;
	  que.push(P(n,tmp));
	}
	
      }
    }
    
  }
  string s;
  char t;
  while(cin >> t){
    s += t;
    for(int i = 0;i < 7;i++){
      cin >> t;
      s += t;
    }

    cout << ans[s] << endl;
    
    s.clear();
  }

  return 0;
  
}


Measured memory_bytes: 5344
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

void comp(ll b, int n, vector<mint>& q){
    
    mint x(1);
    rep(i, n + 1){
        if (i < b) {
            q.push_back(0);
        } else if (i == b){
            q.push_back(1);
        } else {
            x *= (mint)i;
            x /= (mint)(i-b);
            q.push_back(x);
        }
    }
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    sort(a.begin(), a.end());

    vector<int> adiff;
    rep(i, n-1){ adiff.push_back(a[i+1] - a[i]);}
    vector<mint> comp_arr;
    comp(k, n, comp_arr);
    //for(auto i: comp_arr){cout << i.x << " ";}
    //cout << endl;
    mint ans = 0;
    rep(i, n-1){
        mint sub = comp_arr[n] - comp_arr[i+1] - comp_arr[n-(i+1)];
        //cout << sub.x << endl;
        ans += sub * (mint)adiff[i];
    }

    cout << ans.x << endl;

}



Measured memory_bytes: 2168
#include<stdio.h>
int A[10000000];
int m,count=0;
int G[1000000];

void insert(int *A,int n,int g){
  int v;
  int i,j;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      count++;
    }
    A[j+g]=v;
  }
}
void shell(int *A,int n){
  int h,i;
  for(i=0,h=1;;i++){
    if(h>n)break;
    G[i]=h;
    h=3*h+1;
  }
  m=i+1;//G.length =m;
  for(i=m-1;i>=0;i--){
    insert(A,n,G[i]);
  }
}
int main(){
  int n,i,j;
  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);
  shell(A,n);
  printf("%d\n",m-1);
  for(i=m-2;i>=0;i--){
    printf("%d",G[i]);
    if(i)printf(" ");
  }
  // printf("\n");
  printf("\n%d\n",count);
  for(i=0;i<n;i++)printf("%d\n",A[i]);

  return 0;
}

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

using namespace std;

int main(){
  	int a, b;
  	scanf("%d %d", &a, &b);
	int sum = a+b;
  	int diff = a-b;
  	int mult = a*b;
  	int ans = max(sum, diff);
  	ans = max( ans, mult);
  	printf("%d",ans);
  	return 0;
}

Measured memory_bytes: 256