akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

#define M 1000213

void insert(char*);
int find(char*);
int get_key(char*);
int get_keycode(char);
int get_hash_num(int,int);

char hash[M][13]={"\0"};

int main(void){
  int n;
  int i;
  char str[13],input[7];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %s",input,str);

    if(input[0]=='i') insert(str);

    if(input[0]=='f'){
      if(find(str)==1) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

void insert(char *str){
  int i=0,hash_num,data;

  data=get_key(str);

  while(1){
    hash_num=get_hash_num(data,i);
    if(strcmp(hash[hash_num],"\0")==0){
      strcpy(hash[hash_num],str);
      break;
    }
    i++;
  }

}

int find(char *str){
  int data,hash_num,i=0;

  data=get_key(str);
 
  while(1){
    hash_num=get_hash_num(data,i);
    if(strcmp(hash[hash_num],"\0")==0) return 0;
    if(strcmp(hash[hash_num],str)==0) return 1;
    i++;
  }
}

int get_key(char *str){
  int data=0,cnt=0,p=1;

  while(str[cnt]!='\0'){
    data+=p*get_keycode(str[cnt]);
    p*=5;
    cnt++;
  }

  return data;
}

int get_keycode(char work){
  switch(work){
  case 'A':
    return 1;
  case 'C':
    return 2;
  case 'G':
    return 3;
  case 'T':
    return 4;
  }
}

int get_hash_num(int data,int i){
  return ((data%M)+i*(data%(M-1)+1))%M;
}

Measured memory_bytes: 13300
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = float('inf')
k = 0
if n == 2: k = 10
elif n == 3: k = 100
for i in range(k, 1000):
    flg = True
    for s, c in sc:
        if list(str(i))[s-1] == str(c): continue
        flg = False
    if flg:
        ans = i
        break
if ans == float('inf'): ans = -1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000

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

ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}
ll fact(ll n,ll p) {
    ll res = 1;
    while (n > 1) {
        res = (res * ((n/p) % 2 ?  p-1 : 1)) % p;
        for (int i = 2; i <= n%p; ++i)
            res = (res * i) % p;
        n /= p;
    }
    return res % p;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}


int main(){
   IOS;
ll t;t=1;//cin>>t;
while(t--){
    ll x;ll k;ll d;
    cin>>x>>k>>d;
 
    if(x>0){ll n=x/d;
         if(k<=n){  cout<<x-k*d<<"\n";
       }
        else{ll x1;
            x1=x%d;
            k=k-(x/d);
              
            if(k%2==0) cout<<x1<<"\n";
            else cout<<abs(x1-d)<<"\n";
            
      }
    }
    else{x=abs(x);
        ll n=x/d;
        if(k<=n){
            cout<<abs(x-k*d)<<"\n";
        }
        else{x=abs(x);
           ll x1=x%d;
            k=k-(x/d);
            if(k%2==0) cout<<abs(-1*x1)<<"\n";
            else cout<<abs(d-x1)<<"\n";
            
        }
    }
    
}

return 0;    
}

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

int main(void)
{
    string  N;
    cin >> N;

    if(N[0] == '9' || N[1] == '9')
        cout << "Yes" << endl; 
    else 
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int A, B, C, s=0;
  cin >> A >> B >> C;
  for (int i = B; i>=A; i-=A) {
    s++;
    if (s == C) 
      break;
  }
  cout << s << endl;
  return 0;
}
      


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	ints := scanIntSlice(5)
	for i, x := range ints {
		if x == 0 {
			fmt.Printf("%d\n", i+1)
		}
	}
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}


Measured memory_bytes: 1816
n = int(input())

if n < 10:
    print(n)
elif n < 100:
    print(9)
elif n < 1000:
    sum = 9 + n - 99
    print(sum)
elif n < 10000:
    print(909)
elif n < 100000:
    sum = 909 + n - 9999
    print(sum)
else:
    print(90909)

Measured memory_bytes: 3064
/* Use the slash-star style comments or the system won't see your
   identification information */
/*
ID: khozmos1
TASK: beads
LANG: C++11
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <bits/stdc++.h>

using namespace std;

// Header files, namespaces,
// macros as defined above
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define f first
#define s second
#define pos first.first
#define tip first.second
#define id second
#define db long double
#define pb push_back
#define sz(c) (int)(c).size()
#define all(c) (c).begin(),(c).end()

typedef long long ll;
typedef pair <int , int> ii;
typedef pair <ii , int> iii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <iii> viii;
typedef vector <vi> vvi;
typedef vector <vii> vvii;




const int mod = 20011;
const int MAX = 3e5+5;
const db eps = 1e-13;
const ll oo = 1e18;

// basic operations
int mul( int a , int b ) {
    return (1ll*a*b)%mod;
}
void addSelf( int &a , int b , int m ) {
    a = (a+b)%m;
}


int ST[4*MAX] , lazy[4*MAX];
int mn[MAX] , mx[MAX];

void propagate( int node , int x, int y , int mt ) {
    ST[node*2] += (lazy[node]*(mt-x+1));
    ST[node*2+1] += (lazy[node]*(y-mt));
    lazy[node*2] += lazy[node];
    lazy[node*2+1] += lazy[node];
    lazy[node] = 0;
}

void update( int node , int x , int y , int a, int b , int v ) {

    if( y < a || x > b )
        return;
    if( x >= a && y <= b ) {
        ST[node] += (v*(y-x+1));
        lazy[node] += v;
        return;
    }
    int mt = (x+y)>>1;
    if( lazy[node] != 0 )
        propagate(node,x,y,mt);
    update(node*2,x,mt,a,b,v);
    update(node*2+1,mt+1,y,a,b,v);
}

int query( int node , int x , int y, int a, int b ) {
    if( y < a || x > b )
        return 0;
    if( x >= a && y <= b ) {
        return ST[node];
    }
    int mt = (x+y)>>1;
    if( lazy[node] != 0 )
        propagate(node,x,y,mt);

    return query(node*2,x,mt,a,b)+query(node*2+1,mt+1,y,a,b);
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    vi ans;
    int N , K , S;
    cin>>N>>K>>S;
    while( K-- ) {

        ans.pb(S);

    }
    while( sz(ans) < N ) {

        if( S==(1000000000) ) {
            ans.pb(S-1);
        } else {
            ans.pb(S+1);
        }

    }
    for( int i: ans )
        cout<<i<<" ";
}
/*
2 3 7 18 3
2 3 3 3 4 3 4 1 1 1 1 1 2 2 2 3 3 4
*/


Measured memory_bytes: 1912
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	int num[400][400] = {};
	int box[400] = {};
	bool flag[400] = {};
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)cin >> num[i][j];
	}
	int sum[400] = {};
	for (int i = 0; i < N; i++) {
		sum[num[i][0]]++;
	}
	for (int i = 1; i <= M; i++) {
		ans = max((int)ans,sum[i]);
	}
	for (int i = 0; i < M - 1; i++) {
		int fig = 1;
		for (int j = 1; j <= M; j++) {
			if (sum[fig] < sum[j]) {
				fig = j;
			}
		}
		flag[fig] = true;
		sum[fig] = 0;
		for (int j = 0; j < N; j++) {
			if (num[j][box[j]] == fig) {

				while (flag[num[j][box[j]]]) {
					box[j]++;
				}
				sum[num[j][box[j]]]++;
			}
		}
		int work = 0;
		for (int j = 1; j <= M; j++) {
			work = max(work, sum[j]);
		}
		//cout << fig << " " << work << endl;
		ans = min((int)ans, work);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define INF 1000000000
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
using namespace std;
int res=INF,n,k,x;
vector<int>v1,v2;
int main()
{
	cin>>n>>k;
	rep(i,n){cin>>x;if(x<0)v1.push_back(x);else v2.push_back(x);}
	reverse(v1.begin(),v1.end());
	rep(i,(min((int)v1.size(),k)+1))
	{
		if(k-i>v2.size())continue;int ans=0,hh=INF;
		if(i>0)ans-=v1[i-1],hh=min(hh,-v1[i-1]);else hh=0;
		if(k-i>0)ans+=v2[k-i-1],hh=min(hh,v2[k-i-1]);else hh=0;
		res=min(res,ans+hh);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1020
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n,p = m()

s = input().split()[0]

co = 0

mo = [0 for i in range(p)]

data = [0 for i in range(n)]

po = [1 for i in range(n)]

for i in range(1,n):
    po[i] = (po[i-1] * 10) % p

if p == 2:
    for i in range(n):
        if int(s[i]) % 2 == 0:
            co += i+1
elif p == 5:
    for i in range(n):
        if int(s[i]) % 5 == 0:
            co += i+1

else:
    s = s[::-1]
    data[0] = int(s[0]) % p
    for i in range(1,n):
        data[i] = (int(s[i]) * (po[i]) + data[i-1]) % p

    mo[0] = 1
    for i in range(n):
        co += mo[data[i]]
        mo[data[i]] += 1



print(co)









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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> H(N); for (ll i = 0; i < N; i++) cin >> H[i];
  sort(H.rbegin(), H.rend());

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (i < K) continue;
    ans += H[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
int main()
{
    string str;

    cin>>str;


    if(str=="SUN")cout<<7<<endl;
    else if(str=="MON")cout<<6<<endl;
    else if(str=="TUE")cout<<5<<endl;
    else if(str=="WED")cout<<4<<endl;
   else if(str=="THU")cout<<3<<endl;
   else if(str=="FRI")cout<<2<<endl;
   else if(str=="SAT")cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int a, b, c;
int main()
{
	cin >> a >> b >> c;
	if((a+b+c==17)&&(a*b*c==175))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())

h = [2,4,5,7,9]
p = [0,1,6,8]
b = [3]

if h.count(N%10)==1:
    print('hon')
if p.count(N%10)==1:
    print('pon')
if b.count(N%10)==1:
    print('bon')

Measured memory_bytes: 9124
k=gets.to_i
l=[0]
z=1
while k>0
  if l==[9]*z
    l=[1]+[0]*z
    z+=1
  else
    f=false
    -1.downto(-z+1) do |i|
      if l[i-1]==9&&l[i]-l[i-1]<0||l[i-1]<9&&l[i]-l[i-1]<1
        l[i]+=1
        (i+1).upto(-1) do |j|
          if l[j-1]==0
            l[j]=l[j-1]
          else
            l[j]=l[j-1]-1
          end
        end
        f=true
        break
      end
    end
    if !f
      l[0]+=1
      (-z+1).upto(-1) do |j|
        if l[j-1]==0
          l[j]=l[j-1]
        else
          l[j]=l[j-1]-1
        end
      end
    end
  end
  k-=1
end
puts l.join


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

int main(){
    string s;
    cin >> s;
    bool can = false;
    int n = s.size();
    int center = n/2;
    if(s.substr(0,center) == s.substr(center+1,center)) can = true;
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
  int n,i;
  scanf("%d",&n);
  i=n%10;
  switch(i)
  {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:printf("hon");break;
    case 0:
    case 1:
    case 6:
    case 8:printf("pon");break;
    case 3:printf("bon");break;
  }
  return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n, k;
	cin >> n >> k;

	int zero_id = -1;
	vector<int> x;
	rep (i, 0, n) {
		int tmp;
		cin >> tmp;
		x.push_back(tmp);

		if (tmp == 0)
			zero_id = i;
	}

	int tmp_k;
	if (zero_id == -1) {
		x.push_back(0);
	  sort(x.begin(), x.end());
		zero_id = distance(x.begin(), find(x.begin(), x.end(), 0));
		tmp_k = k;
	} else {
		tmp_k = k - 1;
	}

	int neg_ele_num = zero_id;
	int pos_ele_num = x.size() - (zero_id + 1);
	ll res = INT_MAX;
	if (tmp_k == 0 && zero_id == 0) {
		res = 0;
	} else {
		rep (i, 0, tmp_k + 1) {
			int neg = tmp_k - i;
			int pos = i;

			if (neg > neg_ele_num) {
				pos += neg - neg_ele_num;
				neg = neg_ele_num;
			}
			if (pos > pos_ele_num) {
				neg += pos - pos_ele_num;
				pos = pos_ele_num;
			}
			ll neg_size = abs(x[zero_id - neg]);
			ll pos_size = abs(x[zero_id + pos]);
			ll tmp = 0;
			if (neg_size < pos_size)
				tmp = neg_size * 2 + pos_size;
			else
				tmp = pos_size * 2 + neg_size;
			res = min(res, tmp);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int n;
vector<double> v;
int main()
{
  cin >> n;
  rep(i,n){
    double a;
    cin >> a;
    v.push_back(a);
  }

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

  rep(i,n-1){
    double nw = (v[0]+v[1])/2;
    v.erase(v.begin(),v.begin()+2);
    v.push_back(nw);
    sort(v.begin(), v.end());    
  }
  
  printf("%.5f\n", *v.begin());
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll ib = b * 100 + 0.5;
    a *= ib;
    a /= 100;
    cout << a << '\n';
}


Measured memory_bytes: 3712
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt()*100;
		int b=scan.nextInt()*10;
		int c=scan.nextInt();
		if((a+b+c)%4==0) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21972
def solve():
    S = input()
    if S == 'RRR':
        print(3)
    elif S == 'RRS' or S == 'SRR':
        print(2)
    elif S == 'SSS':
        print(0)
    else:
        print(1)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 9032
import sys

input = sys.stdin.readline

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(N-1):
    B.append(A[i+1] - A[i])
B.append(K - A[N-1] + A[0])
print(sum(B) - max(B))





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

int n,d;

int main(){
	cin>>n>>d;
	if(n % (2 * d + 1) == 0){
		cout<<n / (2 * d + 1)<<endl;
	}else{
		cout<<n / (2 * d + 1) + 1<<endl;
	}
}


Measured memory_bytes: 256
s=input()
ans=0
up=0
down=0
if(s[0]=='>'):
    down+=1
else:
    up+=1


for i in range(1,len(s)):
    if(s[i]=='>'):
        down+=1
    else:
        if(s[i-1]=='>'):
            high=max(up,down)
            low=min(up,down)
            ans+=(high+1)*(0+high)//2
            low-=1
            ans+=(low+1)*(0+low)//2
            up=1
            down=0
        else:
            up+=1
else:
    high=max(up,down)
    low=min(up,down)
    ans+=(high+1)*(0+high)//2
    low-=1
    ans+=(low+1)*(0+low)//2
print(ans)

Measured memory_bytes: 4116
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a[6];
	for (int i = 0; i < 6; i++)
	{
		cin >> a[i];
	}
	sort(a, a + 4);
	sort(a + 4, a + 6);
	cout << a[1] + a[2] + a[3] + a[5] << endl;
	
	return 0;
}

Measured memory_bytes: 3140
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define uptol(a, b, i) for (i64 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i64 n, a, b;
i64 v[51];

//pair<i64, i64> rec(i32 x, i32 c, i32 i) {
//    if (x <= c || i > n) return make_pair(0, 1);
//    auto r1 = rec(x, c, i+1);
//    auto r2 = rec(x, c+1, i+1); r2.first += v[i];
//    if (r1.first == r2.first) {
//        return make_pair(r1.first, r1.second + r2.second);
//    } else {
//        return max(r1, r2);
//    }
//}

i32 main()
{
    cin >> n >> a >> b;
    upto(1, n, i) {
        cin >> v[i];
    }
    //i64 ansv = 1, ansx = 1, ansc = 0;
    //upto(a, b, x) {
    //    auto p = rec(x, 0, 1);
    //    if (ansv*x < p.first*ansx) {
    //        ansv = p.first;
    //        ansx = x;
    //        ansc = p.second;
    //    } else if (ansv*x == p.first*ansx) {
    //        ansc += p.second;
    //    }
    //}
    //cout << setprecision(8) << fixed << f64(ansv)/f64(ansx) << endl;
    //cout << ansc  << endl;

    pair<i64, i64> dp[51][51];
    dp[0][0] = make_pair(0, 1);
    dp[0][1] = make_pair(0, 1);
    upto(1, n, i) {
        dp[i][0] = make_pair(0, 1);
        upto(1, n, j) {
            auto p1 = dp[i-1][j];
            auto p2 = dp[i-1][j-1]; p2.first += v[i];
            if (p1.first == p2.first) {
                dp[i][j] = make_pair(p1.first, p1.second + p2.second);
            } else {
                dp[i][j] = max(p1, p2);
            }
        }
    }
    i64 ansv = 1, ansx = 1, ansc = 0;
    upto(a, b, x) {
        auto p = dp[n][x];
        if (ansv*x < p.first*ansx) {
            ansv = p.first;
            ansx = x;
            ansc = p.second;
        } else if (ansv*x == p.first*ansx) {
            ansc += p.second;
        }
    }
    cout << setprecision(8) << fixed << f64(ansv)/f64(ansx) << endl;
    cout << ansc << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def print_ans(S):
    """Test Case
    >>> print_ans("000")
    1
    >>> print_ans("10010010")
    3
    >>> print_ans("0")
    0
    """
    before = "2"
    ans = 0
    for s in S:
        if s == before:
            ans += 1
            if s == "1":
                before = "0"
            else:
                before = "1"
        else:
            before = s

    print(ans)

if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)


Measured memory_bytes: 3188
def printer(A):
    ret = str(A[0])
    for i in range(1, len(A)):
        ret += " " + str(A[i])
    print(ret)
    return True


n = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if A[minj] > A[j]:
            minj = j
    if i != minj:
        ans += 1
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
printer(A)
print(ans)


Measured memory_bytes: 5600
from collections import deque

di = [-1, 0, 1, 0]
dj = [ 0, 1, 0,-1]

H,W = map(int, input().split())
s = list()
si,sj = map(int, input().split())
ti,tj = map(int, input().split())
si -= 1
sj -= 1
ti -= 1
tj -= 1

for i in range(H):
  s.append(input())
  
q = deque()
inf = 10**9
dist = [[inf] * W for i in range(H)]
q.append([si,sj])
dist[si][sj] = 0

while(len(q) > 0):
  tmp = q.popleft()
  i = tmp[0]
  j = tmp[1]
  d = dist[i][j]
  for v in range(4):
    ni = i + di[v]
    nj = j + dj[v]
    if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
      continue
    if s[ni][nj] == "#":
      continue
    if dist[ni][nj] <= d:
      continue
    dist[ni][nj] = d
    q.appendleft([ni,nj])
    
  for ei in range(-2, 3, 1):
    for ej in range(-2, 3, 1):
      ni = i + ei
      nj = j + ej
      if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
        continue
      if s[ni][nj] == "#":
        continue
      if dist[ni][nj] <= d+1:
        continue
      dist[ni][nj] = d+1
      q.append([ni,nj])
    
ans = dist[ti][tj]
if ans == inf:
  ans = -1
print(ans)

Measured memory_bytes: 99728
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  ll H,W;

  cin>>H>>W;

  ll ans =INF;

  if(H%3==0) ans=0;
  else ans=min(ans,W);

  ll hv;

  rep(i,3){

    hv=H/3+i;

    ans=min( ans ,max({ abs((hv*W)-(H-hv)*(W/2)) , abs((hv*W)-(H-hv)*(W-W/2)) , abs((H-hv)*(W/2)-(H-hv)*(W-W/2)) }) );

  }
  swap(H,W);
  if(H%3==0) ans=0;
  else ans=min(ans,W);
  rep(i,3){

    hv=H/3+i;

    ans=min( ans ,max({ abs((hv*W)-(H-hv)*(W/2)) , abs((hv*W)-(H-hv)*(W-W/2)) , abs((H-hv)*(W/2)-(H-hv)*(W-W/2)) }) );

  }
  cout<< ans<<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n = 0, i = 0, sum = 0;
	int d[101] = { 0 };

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	for (i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			sum += d[i] * d[j];
		}
	}
	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/arc081/tasks/arc081_b

# 幅1: 色数だけ縦 (3)
# 幅2: 色数だけ横と縦に2本選ぶ (6)
# 隣接している場所の色の塗り方が問題

N = int(input())
MOD = 1000000007
if N == 1:
    print(3)
    exit()
S = [list(input()) for _ in range(2)]

ans = 1
i = 0
is_x = None
while i < N:
    if i == 0:
        if S[0][i] == S[1][i]:
            ans *= 3
            i += 1
            is_x = True
        else:
            ans *= 6
            i += 2
            is_x = False
    else:
        if S[0][i] == S[1][i]:
            if is_x:
                ans *= 2
            else:
                ans *= 1
            is_x = True
            i += 1
        else:
            if is_x:
                ans *= 2
            else:
                ans *= 3
            is_x = False
            i += 2
    ans = ans % MOD
print(ans)

Measured memory_bytes: 62024
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n;
    ll a[100009];
    cin>>n;
    rep(i,n) cin>>a[i];
    bool f=false;
    rep(i,n){
        if(a[i]%2==1) f=true;
    }
    if(f) cout<<"first"<<endl;
    else cout<<"second"<<endl;
}


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

int main(){
	int a,b,k;

	cin>>a>>b>>k;

	for(int i = a;i < min(b,a+k); i++){
		cout<<i<<endl;
	}
	for(int i = max(b-k+1,min(a+k,b));i<=b;i++) cout<<i<<endl;


}

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

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

  rep(i, n) ans = __gcd(ans, a[i]);
  cout << ans << endl;
}
  


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

int n, a[3];
int l[8], used[8];

int dfs(int);

int main()
{
	scanf("%d%d%d%d", &n, a, a + 1, a + 2);
	for (int i{}; i < n; i++) scanf("%d", l + i);
	std::fill(used, used + n, -1);
	printf("%d\n", dfs(0));
	
	return 0;
}

int dfs(int index)
{
	if (index == n)
	{
		int each_sum[3]{}, ret{-30};
		for (int i{}; i < n; i++)
			if (used[i] >= 0)
			{
				each_sum[used[i]] += l[i];
				ret += 10;
			}
		for (int i{}; i < 3; i++)
		{
			if (!each_sum[i]) return 1 << 30;
			ret += std::abs(each_sum[i] - a[i]);
		}
		return ret;
	}

	int min{dfs(index + 1)};
	for (int i{}; i < 3; i++)
	{
		used[index] = i;
		min = std::min(min, dfs(index + 1));
	}
	used[index] = -1;
	return min;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    MOD = 10 ** 9 + 7
    ans = pow(10, N, MOD)
    ans -= pow(9, N, MOD) * 2
    ans += pow(8, N, MOD)
    print(ans % MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a))
#define ld long double
const ll mod=1e9+7;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
void solve(){
    ll m;
    cin >> m;
    ll l,r;
    cin >> l >> r;
    bool f=0;
    for(int i=l; i<=r; i++){
        if(i%m==0){
            f=1;
            break;
        }
    }
    if(!f) cout << "NG" << endl;
    else cout << "OK" << endl;
}
int main() {
    IOS;
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3608
n,m=[int(i) for i in input().split()]
ans=0

ans=(n-2)*(m-2)

if n==1:
    ans=m-2
if m==1:
    ans=n-2

if n==1 and m==1:
    ans=1
if n==2 and m==1:
    ans=0
if m==2:
    ans=0


print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int n,i,j,s;
	cin>>n;
	int a[n][3]={0},b[3][101]={0};
	for(i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		b[0][a[i][0]]++;
		b[1][a[i][1]]++;
		b[2][a[i][2]]++;
	}
	for(i=0;i<n;i++){
		for(s=j=0;j<3;j++){
			if(b[j][a[i][j]]==1)s+=a[i][j];
		}
		cout<<s<<endl;
	}
}

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

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    map<int, int> A;
    for (int i = 1; i < N+1; i++) {
        for (int j = i+1; j < N+1; j++) {
            int dmin = j - i;
            if (i <= X && j >= Y) {
                dmin = j-i-(Y-X)+1;
            } else if (i <= X && j > X) {
                dmin = X - i + min(j-X, Y-j+1);
            } else if (i < Y && j >= Y) {
                dmin = j - Y + min(Y-i, i-X+1);
            } else if (i >= X && j <= Y) {
                dmin = min(j-i, Y-j + i-X + 1);
            } 
            A[dmin]++;
        }
    }
    for (int k = 1; k < N; k++){
        cout << A[k] << endl;
    } 
}




Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;
int t;
int n,k;

int main() {
	cin >> t;
//	cout << t;
	for (int i = 0; i < t; ++i)
	{
		cin >> n >> k;
		//cout << n << " " << k << endl;
		int x[n];
		for (int j = 0; j < n; ++j)
		{
			cin >> x[j];
			//cout << x[j] << " ";
		}
		//cout << endl;
		int A[n-1];
		for (int i = 0; i < n-1; ++i)
		{
			A[i] = x[i+1]-x[i];
			//cout << A[i] << endl;
		}
		sort(A,A+n-1);
		//for (int i = 0; i < n-1; ++i) cout << A[i] << endl;
		int sum=0;
		for (int i = 0; i < (n-1)-(k-1); ++i)
		{
			sum += A[i];
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3916
#include <iostream>
#include <vector>
//#include <list>
//#include <queue>
//#include <unordered_map>
#include <algorithm>
//#include <string>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
	long long int i,j,k,n,m;
	long long int x,y,z;
	long long int w;
	cin>>n>>w;
	int wt[n];
	int va[n];
	for(i=0;i<n;i++)
	{
		cin>>wt[i]>>va[i];
	}
	
	long long int dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=w;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>=wt[i-1])
				dp[i][j]=max(dp[i][j], va[i-1] + dp[i-1][j-wt[i-1]]);
		}
	}
	/*for(i=0;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	cout<<dp[n][w]<<"\n";
	return 0;
}



Measured memory_bytes: 79104
// https://atcoder.jp/contests/abc112/tasks/abc112_a
#include <bits/stdc++.h>
using namespace std;
using P = pair<double, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n == 1) {
        cout << "Hello World\n";
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}


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

#define ll long long



using namespace std;

int n;
string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    if(n & 1)
    {
        cout << "No\n";
        return 0;
    }
    s = " " + s;
    for(int i = 1; i <= n / 2; i++)
        if(s[i] != s[i + n / 2])
        {
            cout << "No\n";
            return 0;
        }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
	long long int n,i;
	cin>>n;
	long long int h[n];
	for(i=0;i<n;i++){
		cin>>h[i];
	}
	
	long long int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+ abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll ans = 0;
    ll cnt = 0;
    rep(i,s.size()){
      if(s[i] == 'W'){
        ans += i-cnt;
        cnt++;
      }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main()
{
  ll N, P;
  cin >> N >> P;
  if (N == 1)
  {
    cout << P << endl;
    return 0;
  }
  if (N > sqrt(P))
  {
    cout << 1 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 2; i <= sqrt(P); i++)
  {
    int cnt = 0;
    while (P % i == 0)
    {
      P /= i;
      cnt++;
      if (cnt == N)
      {
        ans *= i;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(void)
{
    int i;
    char c[8];
    while(1){
        gets(c);
        int n=atoi(c);
        if( n<=0 ) break ;
        int z=1,d=5,t=1,s=3,x;
        while(n--){
            gets(c);
            switch(*c){
            case 'N': x=d;d=t;t=7-x; break ;
            case 'E': x=s;s=t;t=7-x; break ;
            case 'W': x=t;t=s;s=7-x; break ;
            case 'S': x=t;t=d;d=7-x; break ;
            case 'R': x=s;s=d;d=7-x; break ;
            case 'L': x=d;d=s;s=7-x; break ;
            }
            z+=t;
        }
        printf("%d\n",z);
    }
    return 0 ;
}

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

using namespace std;

int main() {
  string a, b;
  cin >> a >> b;
  if (a.length() == b.length()) {
    puts(a < b ? "LESS" : (a == b) ? "EQUAL" : "GREATER");
  } else {
    puts(a.length() < b.length() ? "LESS" : "GREATER");
  }
  return 0;
}


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){
    int n;
    cin >> n;
    vector<int>p;
    rep(i,n){
        int x;
        cin >> x;
        p.push_back(x);
    }
    sort(p.begin(), p.end());
    int sum=0;
    for(int i= p[n/2-1];i<p[n/2];i++){
        sum++;
    }
    cout << sum << endl;
    
    return 0;
}




















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

int check(int x,int y,vector<string> &A,vector<string> &B,int M){
	int i,j;
		for(i=0;i<M;i++){
			for(j=0;j<M;j++){
				if(A[x+i][j+y]!=B[i][j])return 0;
			}
		}
		return 1;
}
int main(void){
	int N,M;
	cin >> N >> M;
	vector<string> A(N);
	vector<string> B(M);
	int i,j,flag;
	for(i=0;i<N;i++)cin >> A[i];
	for(i=0;i<M;i++)cin >> B[i];
	
	for(i=0;i<=(N-M);i++){
		for(j=0;j<=(N-M);j++){
			flag = check(i,j,A,B,M);
			if(flag==1){
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
	
}


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

long long w, h, x, y;
bool ch = 0;

double solve();

int main() {
  cout << fixed << setprecision(10);
  cin >> w >> h >> x >> y;
  cout << solve() << " ";
  cout << ch << endl;
  return 0;
}

double solve() {
  double ans = 0;
  ans = (double)w * h / 2;
  if(w % 2 == 0 && w / 2 == x && h % 2 == 0 && h / 2 == y)
    ch = 1;

  return ans;
}


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

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<long long>; using vvll = vector<vll>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Preprocessing & "Global" variables {{{
struct Solver {
	Solver() {}
	int solve();
};
// }}}


int Solver::solve() {
	int n; cin >> n;
	vi a(n); cin >> a;
	for (int &x : a) x /= 400;
	const int M = 13;
	vi cnt(M);
	for (int x : a) cnt[x]++;
	int curc = 0;
	for (int i = 0; i <= 7; i++) if (cnt[i] > 0) curc++;
	int fre = 0;
	for (int i = 8; i < M; i++) fre += cnt[i];
	cout << max(int(fre > 0), curc) << ' ';
	cout << fre + curc << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	Solver solver;
	#ifdef JUDGE_MULTI_CASE
		int t; cin >> t; for (int i = 1; i <= t; i++)
	#endif
	solver.solve();
	// cout << "Case #" << i << ": ", solver.solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input1 = new Scanner(System.in);
		int len = input1.nextInt();
		int first = input1.nextInt();
		int next = input1.nextInt();
		int curMin = Math.min(first, next);
		int curMax = next - first;
		// int diff;
		
		for (int i = 0; i < len-2; i++) {
			curMin = Math.min(curMin, next);
			next = input1.nextInt();
			// int diff = next - first;
			curMax = Math.max(curMax, next - curMin);			
			first = next;
		}		
		input1.close();
		System.out.println(curMax);
	}
}


Measured memory_bytes: 100052
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;

int N;
int D[110];
int A[110];
int dp[110][60000];

int factorial(int x) {
  if (x == 1) return 1;
  return x * factorial(x-1);
}

int enc(int a, int b, int c, int d, int e, int f, int g) {
  vector<int> v;
  int t[7] = {a, b, c, d, e, f, g};
  int ret = 0;
  for (int i=0; i<7; i++) v.push_back(i);
  for (int i=0; i<7; i++) {
    int k = find(v.begin(), v.end(), t[i]-1) - v.begin();
    ret += factorial(7-i) * k;
    v.erase(v.begin() + k);
  }
  return ret;
}

int max_at(int i) {
  int m[] = {1, 2, 3, 4, 5, 6, 7};
  int ret = 0;
  do {
    int s = enc(m[0], m[1], m[2], m[3], m[4], m[5], m[6]);
    ret = max(ret, dp[i][s]);
  }
  while (next_permutation(m, m+7));
  return ret;
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) cin >> D[i];
  for (int i=0; i<N; i++) cin >> A[i];

  int m[] = {1, 2, 3, 4, 5, 6, 7};
  do {
    int score = 0;
    for (int i=0; i<min(N, 7); i++) {
      for (int b=max(0, i-D[i]); b<=min(i+D[i], 6); b++) {
        if (i != b && m[i] > m[b]) score += A[i];
      }
    }
    dp[7][enc(m[0], m[1], m[2], m[3], m[4], m[5], m[6])] = score;
  }
  while (next_permutation(m, m+min(7, N)));

  for (int i=7; i<N; i++) {
    int m[] = {1, 2, 3, 4, 5, 6, 7};
    do {
      int s = enc(m[0], m[1], m[2], m[3], m[4], m[5], m[6]);

      for (int k=1; k<=8; k++) {
        int mc[8] = {0, 0, 0, 0, 0, 0, 0, 0};
        int mc2[7] = {0, 0, 0, 0, 0, 0, 0};
        for (int j=0; j<7; j++) mc[j] = m[j];
        mc[7] = k;
        for (int j=0; j<7; j++) {
          if (mc[j] >= k) mc[j]++;
        }
        for (int j=1; j<8; j++) {
          mc2[j-1] = mc[j];
          if (mc[j] > mc[0]) mc2[j-1]--;
        }
        int ns = enc(mc2[0], mc2[1], mc2[2], mc2[3], mc2[4], mc2[5], mc2[6]);
        int score = 0;
        for (int j=max(0, 7-D[i]); j<7; j++) {
          if (mc[j] < mc[7]) score += A[i];
        }
        for (int j=max(0, i-7); j<i; j++) {
          if (mc[7-(i-j)] > mc[7] && i-j <= D[j]) {
            score += A[j];
          }
        }
        dp[i+1][ns] = max(dp[i+1][ns], score + dp[i][s]);
      }
    }
    while (next_permutation(m, m+7));
  }
  cout << max_at(max(N, 7)) << "\n";
  return 0;
}

Measured memory_bytes: 16168
import sys
readline = sys.stdin.buffer.readline

H, W = list(map(int, readline().split()))
CH, CW = list(map(int, readline().split()))
DH, DW = list(map(int, readline().split()))
S = []
for _ in range(H):
    S.append(list(input()))

# 1-index -> 0-index
CH -= 1
CW -= 1
DH -= 1
DW -= 1

from collections import deque
seen = set()
queue = deque([(0, CH, CW)])
offsets = [(-1, 0), (1, 0), (0, -1), (0, 1)]

while queue:
    move, row, col = queue.popleft()

    # print(row, col, queue)

    if (row, col) in seen:
        continue

    if row == DH and col == DW:
        print(move)
        sys.exit(0)

    seen.add((row, col))

    for r_offset, c_offset in offsets:
        new_row = row + r_offset
        new_col = col + c_offset
        if 0 <= new_row < H and 0 <= new_col < W and S[new_row][new_col] == '.' and (new_row, new_col) not in seen:
            queue.appendleft((move, new_row, new_col))


    for i in range(-2, 3):
        for j in range(-2, 3):
            new_row = row + i
            new_col = col + j

            if 0 <= new_row < H and 0 <= new_col < W and S[new_row][new_col] == '.' and (new_row, new_col) not in seen:
                queue.append((move+1, new_row, new_col))

print(-1)

Measured memory_bytes: 270096
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
using namespace std;

typedef long long ll;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

struct State{
  double a,b,c;
};
State st[100];
double t[100][100];
int n,m;
double ans;
void solve(int cur , int rest ,bool *use){
  if(rest == 0){
    double tmp = 0;
    rep(i,n){
      REP(j,i+1,n){
        if(use[i] && use[j]){
          tmp += t[i][j];
        }
      }
    }
    ans = max(ans , tmp);
    return;
  }
  if(cur == n)return;
  solve(cur+1,rest,use);
  use[cur] = true;
  solve(cur+1 , rest-1 , use);
  use[cur] = false;
}

int main(){
  while(cin>>n>>m){
    rep(i,n){
      cin>>st[i].a>>st[i].b>>st[i].c;
    }
    rep(i,n){
      REP(j,i+1,n){
        double a,b,c;
        a = st[i].a -st[j].a;
        a *=a;
        b = st[i].b -st[j].b;
        b *=b;        
        c = st[i].c -st[j].c;
        c *=c;
        t[i][j] = a+b+c;
      }
    }
    bool use[21];
    memset(use,0,sizeof(use));
    ans = 0;
    solve(0,m,use);
    printf("%.10f\n",ans);
  }
}

Measured memory_bytes: 952
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair


int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    string r;
    cout << "? 10000000000" << endl;
    cin >> r;
    if (r == "Y") {
        ll x = 2;
        while(true) {
            cout << "? " << x << endl;
            cin >> r;
            if (r == "Y") {
                cout << "! " << x / 2 << endl;
                return 0;
            }
            x *= 10;
        }
    }

    ll R = 10;
    while(true) {
        cout << "? " << R << endl;
        cin >> r;
        if (r == "N") break;
        R *= 10;
    }

    ll L = R / 10;
    L--;
    R--;
    while(R - L > 1) {
        ll x = (L + R) / 2;
        cout << "? " << x << "0" << endl;
        cin >> r;
        if (r == "Y")
            R = x;
        else
            L = x;
    }
    cout << "! " << R << endl;

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 2e5 + 7;
struct Fen {
int f[N];
void clear() {
    for (int i = 0; i < N; ++i) f[i] = 0;
}   
void add(int i, int x) {
    for (; i < N; i |= i + 1) 
        f[i] += x;
}   
int get(int i) {
    int ans = 0;
    for (; i >= 0; i &= i + 1, --i) ans += f[i];
    return ans;
}   
int get(int l, int r) {
    return get(r) - get(l - 1);
}   
} f;

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vector <int> p(n);
    vector <int> c;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        c.app(p[i]);
    }   
    sort(all(c));

    vector <int> bad[2];
    for (int i = 0; i < n; ++i) {
        p[i] = lower_bound(all(c), p[i]) - c.begin();
        if ((i ^ p[i]) & 1) {
            bad[i & 1].app(i);
        }   
    }
    
    if (bad[0].size() != bad[1].size()) {
        cout << "LMAO" << endl;
    }   

    cout << bad[0].size() << endl;

    /*
    cout << "bad :\n";
    for (int e : bad[0])
        cout << e << ' ';
    cout << endl;
    for (int e : bad[1])
        cout << e << ' ';
    cout << endl;

    vector <int> to(n);
    for (int i = 0; i < n; ++i)
        to[i] = i;
    for (int i = 0; i < bad[0].size(); ++i) {
        to[bad[0][i]] = bad[1][i];
        to[bad[1][i]] = bad[0][i];        
    }   
    int ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        ans += f.get(to[i]);
        f.add(to[i], 1);
    }   
    cout << ans << endl;
    */
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 55;
double v[T];
int n;

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v[i] = x;
    }

    sort(v,v+n);
    for(int i = 1; i < n; i++) v[i] = (v[i]+v[i-1])/2;
    cout << fixed << setprecision(5) << v[n-1] << endl;

    return 0;
}


Measured memory_bytes: 256