akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

# x[0], x[-1]
def get_len(x0, xm1):
    left = abs(x0) + abs(xm1-x0)
    right = abs(xm1) + abs(xm1-x0)
    return min(left, right)



count = INF
for i in range(N-K+1):
    l = get_len(X[i], X[i+K-1])
#    print(X[i], X[i+K-1], l)
    count = min(count, l)

print(count)


Measured memory_bytes: 14308
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
	int N, count = 50, t;
	int a;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		for (int j = 0; j < 30; j++) {
			if (a % 2 == 1) {
				t = j;
				break;
			}
			else {
				a = a/2;
			}
		}
		if (t == 0) {
			count = 0;
			break;
		}
		else if (count > t) {
			count = t;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, x int
	fmt.Scan(&a, &b, &c, &x)

	count := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			sum := i * 500 + j * 100

			if sum > x {
				break
			}

			diff := x - sum
			if (diff / 50) <= c {
				count++
			}
		}
	}

	fmt.Println(count)
}


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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 105;

int main() {
	int n;
	scanf("%d", &n);
	int x[N];
	for(int i = 0; i < n; i++){
		scanf("%d", x+i);
	}
	int ans = 1e9;
	for(int p = 1; p <= 100; p++){
		int aux = 0;
		for(int i = 0; i < n; i++){
			aux += (x[i] - p) * (x[i] - p);
		}
		ans = min(ans, aux);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
//**************************
//*** author  :  Alex Hu **
//************************

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

typedef long long ll; 
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MX=1e5+7;

vi g[MX];
bool was[MX];
int f[MX];

int dfs(int v)
{
	if (was[v]) return f[v];
	was[v]=true;
	for (int to:g[v]) f[v]=max(f[v],dfs(to)+1);
	return f[v];
}

int main()
{
	int n,m;
	cin>>n>>m;
	rept(i,0,m)
	{
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
	}
	int ans=0;
	rept(i,1,n+1) ans=max(ans,dfs(i));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7552
def make_divisors(n,m):
    divisors=[]
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            divisors.append(i)
            if i != m // i:
                divisors.append(m//i)

    divisors.sort()
    return divisors

N=int(input())

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

if len(A)==1:
  print(A[0])
  exit()

div=(make_divisors(A[0],A[1]))
div=list(set(div))
div.sort(reverse=True)
if len(A)<=2:
  print(div[0])
  exit()
for i in div:
  count=0
  for a in A[2:]:
    if a%i!=0:
      count+=1
    if count==2:
      break
  if count==0 or (count==1 and A[0]%i==0 and A[1]%i==0):
    print(i)
    exit()

Measured memory_bytes: 14488
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

static const int n_max = 100;

void print_column(vector<int> a, int n) {
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << a.at(i);
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);

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

  print_column(a, n);

  for (int i = 1; i < n; i++) {
    int v = a.at(i);
    int j = i - 1;
    for (j = i - 1; j >= 0; j--) {
      if (a.at(j) > v) {
        a.at(j + 1) = a.at(j);
      } else {
        break;
      }
    }
    a.at(j + 1) = v;
    print_column(a, n);
  }
  return 0;
}


Measured memory_bytes: 3164
#include<stdio.h>
#include<string.h>
main()
{
	int N;
	char S[50];
	int i;
	int count=0;
	scanf("%d", &N);
	getchar();
	scanf("%[^\n]%*c", S);
	for(i=0; i<strlen(S)-2; ++i){
		if(strlen(S)!=N){
			break;
		}
		else{
			if(S[i]<'A' || S[i]>'Z'){
				break;
			}
			else{
				if(S[i]=='A'){
					if(S[i+1]=='B'){
						if(S[i+2]=='C'){
							count = count+1;
						}
					}
				}
					
			}
		}
	}
	printf("%d", count);
}

Measured memory_bytes: 128
import java.util.Scanner;

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

        sc.close();
        long count = b / x - a / x;
        if(a % x == 0) {
            count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23508
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int main(){
	std::ios::sync_with_stdio(false);
	ll val=0,a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	val=min(min(x,y)*(a+b),min(x,y)*2*c);
	if(x>y){
		val+=min((x-y)*a,2*(x-y)*c);
	}
	else{
		val+=min((y-x)*b,2*(y-x)*c);
	}
	cout<<val<<endl;

} 
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define x first
#define y second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;

ll h, w, n;
LL A[3005];
ll DP[3005];
ll fact[2 * MAXN];	
ll invfact[2 * MAXN];

ll bigmod(int a, int b) {
	if (b == 0) return 1;
	ll now = bigmod(a, b / 2) % MOD;
	now = now * now % MOD;
	if (b % 2) now = now * a % MOD;
	return now;
}

ll comb(ll a, ll b) {
	if (b == 0) return 1;
	if (b == a) return 1;
	return fact[a] * invfact[a - b] % MOD * invfact[b] % MOD;
}

ll rek(int pos) {
	ll &ret = DP[pos];
	if (ret != -1) return ret;
	ret = comb(A[pos].x + A[pos].y, A[pos].x);
	//cout << pos << ' ' << A[pos].x << ' ' << A[pos].y << ' ' << ret << "eA\n";
	REP(i, pos) {
		if (A[i].y <= A[pos].y) {
			ret = (ret - rek(i) * comb(A[pos].x + A[pos].y - A[i].x - A[i].y,
					A[pos].x - A[i].x)) % MOD;
			if (ret < 0) ret += MOD;
		}
	}
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	fact[0] = 1;
	FOR(i, 1, 2 * MAXN - 1) fact[i] = (fact[i - 1] * i) % MOD;
	FOR(i, 0, 2 * MAXN - 1) invfact[i] = bigmod(fact[i], MOD - 2); 
	cin >> h >> w >> n;
	REP(i, n) {
		LL x;
		cin >> x.x >> x.y;
		x.x--;
		x.y--;
		A[i] = x;
	}
	A[n++] = mp(h - 1, w - 1);	
	sort(A, A + n);
	memset(DP, -1, sizeof DP);
	cout << rek(n - 1) << '\n';
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;

    int q; cin >> q;
    vector<int> s_a(s.size()+1), t_a(t.size()+1);
    s_a[0] = 0;
    for(int i = 0; i < s.size(); ++i){
        s_a[i+1] = s_a[i] + (s[i] == 'A');
    }

    for(int i = 0; i < t.size(); ++i){
        t_a[i+1] = t_a[i] + (t[i] == 'A');
    }
    for(int i = 0; i < q; ++i){
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        int s_a_num = s_a[b] - s_a[a-1];
        int t_a_num = t_a[d] - t_a[c-1];
    
        JUDGE(((2*s_a_num+(b-a+1-s_a_num)) % 3) == ((2*t_a_num+(d-c+1-t_a_num)) % 3));
    }

    return 0;
}


Measured memory_bytes: 1744
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
using namespace std;
int n, ans[123456];
vector<pair<int, int>>v[123456];
bool b[123456];
void f1(int d, int c) {
	b[d] = 1;
	int k = 0;
	for (pair<int, int>p1 : v[d]) if (!b[p1.first]) {
		k++; if (k == c)k++;
		ans[p1.second] = k;
		f1(p1.first, k);
		ans[0] = max(ans[0], k);
	}
}
int main() {
	cin >> n;
	for1(i, n - 1) {
		int s, t; cin >> s >> t;
		v[s].push_back(make_pair(t, i));
		v[t].push_back(make_pair(s, i));
	}
	f1(1, 0);
	for0(i, n)puts(ans[i]);
}

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

bool f(char ch){
  return (ch=='a'||ch=='i'||ch=='u'||ch=='e'||ch=='o');
}



char g(string str){
  for(int i=0;i<(int)str.size();i++)
    if(f(str[i]))return str[i];
  return '-';
}

bool h(string str){
  if(str.size()==1)return false;
  char ch=str[0];
  return ch=='k'||ch=='s'||ch=='t'||ch=='h'||ch=='p';
}

bool H(string str){
  char ch=str[0];
  return ch=='k'||ch=='s'||ch=='t'||ch=='h'||ch=='p';
}

bool last;

void pr(string str,bool flg){
  if(!last)flg=false;
  
  for(int i=0;i<(int)str.size();i++){
    if(flg&&f(str[i]))cout<<"("<<str[i]<<")";
    else cout<<str[i];
  }

  if(!flg)last=true;
  else last=false;
}
int len;
string s;
vector<string> t;
bool u[1000];

int main(){
  while(1){
    cin>>s;
    if(s=="#")break;
    t.clear();memset(u,0,sizeof(u));
    len=s.size();
    s+="...";
    for(int i=0;i<len;i++){
      if(s[i]=='\''){
        u[t.size()-1]=true;
        continue;
      }

      if(s[i]=='n'&&!f(s[i+1])&&s[i+1]!='y'){
        t.push_back(s.substr(i,1));
        continue;
      }

      if(f(s[i])){
        t.push_back(s.substr(i,1));
        continue;
      }
      
      if(s[i]==s[i+1]){
        t.push_back(s.substr(i,1));
        continue;
      }
      string tmp;
      if(s[i+1]=='y'){
        tmp=s.substr(i,3);
        i+=2;
      }else{
        tmp=s.substr(i,2);
        i++;
      }

      t.push_back(tmp);
    }

    last=true;
    int ts=t.size();
    for(int i=0;i<ts;i++){
      if(t[i].size()==1){
        cout<<t[i];
        if(u[i])cout<<'\'';
        continue;
      }
      
      if(h(t[i])){
        if(g(t[i])=='i'||g(t[i])=='u'){
          pr(t[i],(i+1==ts||(H(t[i+1]))));
        }else if(g(t[i])=='a'||g(t[i])=='o'){
          pr(t[i],(i+1<ts&&h(t[i+1])&&g(t[i+1])==g(t[i])));
        }else{
          pr(t[i],false);
        }
      }else{
        pr(t[i],false);
      }
      if(u[i])cout<<'\'';

    }
    cout<<endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >>N;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  map<string,int>kazu;
  int saidai=0;
  for(string a:S){
    kazu[a]++;
    saidai=max(saidai,kazu[a]);
  }
  for(auto a:kazu){
    if(a.second==saidai){
      cout<<a.first<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 28672
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	if( s == "Sunny" ) cout << "Cloudy" << endl;
	if( s == "Cloudy" ) cout << "Rainy" << endl;
	if( s == "Rainy" ) cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string ret = string.Empty;
            foreach (var s in S)
            {
                var index = (chars.IndexOf(s) + N) % 26;
                ret += chars[index];
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 34772
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int line = int.Parse(System.Console.ReadLine().Trim());
        System.Console.WriteLine(new string(char.Parse(((line - 1) / 111 + 1).ToString()), 3));

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato ha kawaii
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.
 
 
int main(){
 int N,M;
 cin>>N>>M;
 int Y; 
  if(N>1||M>1){cout<<(N-1)*(N-1+1)/2+(M-1)*(M-1+1)/2<<endl;}
  else if(N<2&&M<2){cout<<0;}
  return 0;}


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

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



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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll ans=b-a+1;
    ll l=(c*d)/__gcd(c,d);
    ll rem=(b/c + b/d - b/(l))-((a-1)/c + (a-1)/d - (a-1)/(l));
    cout<<ans-rem;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

left = [False] * n
right = [False] * n

for i in range(1, n):
    if p[i-1] < p[i]:
        left[i] = True

for i in range(n-1, 1, -1):
    if p[i] < p[i-1]:
        right[i-1] = True

count = 0
for i in range(1,n-1):
    if not(left[i] and right[i]):
        if left[i] or right[i]:
            count += 1

print(count)


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

using namespace std;

int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	if (s1[s1.size() - 1] == s2[0] && s2[s2.size() - 1] == s3[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) {
        int ta;
        cin >> ta;
        if (ta % 2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}


ll ans=0;

ll tosum(ll a){
  ll sum=0;
  while(a>0){
    sum+=a%10;
    a/=10;
  }
  if(sum>9)sum=tosum(sum);
  return sum;
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll m,ngs=0;cin>>m;
  priority_queue<ll> q;
  rep(i,0,m){
    ll d,c;
    cin>>d>>c;
    ngs+=c;
    q.push(tosum(d*c));
    ans+=(max(0ll,d*c-1))/9;
  }
  ans+=ngs-1;
  //cout<<ans<<endl;

  while(siz(q)>1){
    ll now=q.top();q.pop();
    ll next=q.top();q.pop();
    ans+=(max(0ll,now+next-1))/9;
    q.push(tosum(now+next));
  }
  cout<<ans<<endl;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 2420
unittest
{
//	assert( [ "needed" ].parse.expand.solve == "2 5" );
	assert( [ "needed" ].parse.expand.solve == "2 3" );
	assert( [ "atcoder" ].parse.expand.solve == "-1 -1" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	// アンバランスな文字列には必ず "aa" か "aba" が含まれるので2パターンだけチェックすればよい
	for( auto i = 0L; i + 1 < s.length; i++ )
	{
		if( s[ i ] == s[ i + 1 ] ) return format( "%s %s", i + 1, i + 2 );
	}
	for( auto i = 0L; i + 2 < s.length; i++ )
	{
		if( s[ i ] == s[ i + 2 ] ) return format( "%s %s", i + 1, i + 3 );
	}
	return "-1 -1";
}


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

const long long INF = 1LL<<60;

int main(){
    int N;
    long long int W;
    cin >> N >> W;
    vector<long long int> weight(110);
    vector<long long int>value(110);
    for(int i=0; i<N; i++){
        cin >> weight.at(i) >> value.at(i);   
    }
   
    vector<vector<long long int>>dp(110,vector<long long int>(100100));
    for (int i = 0; i < 110; ++i) for (int j = 0; j < 100100; ++j) dp[i][j] = INF;
    dp.at(0).at(0) =0; 
    for(int i=0; i<N; i++){
        for(int j=0; j<100100; j++){
            if(j-value.at(i)>=0 ){
                dp.at(i+1).at(j) = min(dp.at(i+1).at(j),dp.at(i).at(j-value.at(i))+weight.at(i));
            }
            dp.at(i+1).at(j) = min(dp.at(i+1).at(j), dp.at(i).at(j));
        }
    }

    long long int res = 0;
    for(int i=0; i<100100; i++){
        if(dp.at(N).at(i)<= W) res = i;
    }
    cout << res << endl;
}

Measured memory_bytes: 90360
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Node[] aN = new Node[n];
        Node nil = new Node(-1, null, null);
        
        for (int i = 0; i < n; i++) {
            aN[i] = new Node(i, nil, null);
        }
        
        for (int i = 0; i < n; i++) {
            int val = scanner.nextInt();
            int dim = scanner.nextInt();
            Node[] a = new Node[dim];
            for (int j = 0; j < dim; j++) {
                int val2 = scanner.nextInt();
                aN[val2].parent = aN[val];
                a[j] = aN[val2];
            }
            aN[val].children = a;
        }
        
        for (int i = 0; i < n; i++) {
            String kind = aN[i].parent.val == -1 ? "root" : aN[i].children.length == 0 ? "leaf" : "internal node";
            String children = getStr(aN[i].children);
            
            System.out.print(
                    "node " + aN[i].val + ": parent = " + aN[i].parent.val + ", depth = " + aN[i].calcDepth() + 
                    ", " + kind + ", " + children);
            System.out.println();
        }
    }
    
    private static String getStr(Node[] a) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        
        for (int i = 0; i < a.length; i++) {
            if (i != 0) {
                sb.append(", ");
            }
            sb.append(a[i].val);
        }
        sb.append("]");
        return sb.toString();
    }

    public static class Node {
        int val;
        Node parent;
        Node[] children;
        public Node(int val, Node parent, Node[] children) {
            this.val = val;
            this.parent = parent;
            this.children = children;
        }
        
        public int calcDepth() { 
            int depth = 0;
            Node p = this.parent;
            while(p.val != -1) {
                depth++;
                p = p.parent;
            }
            return depth;
        }
    }
}


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

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int ans = 0;
  int x = 0;
  
  vector<vector<int>> data(H, vector<int>(W, 1));
  
  if( H <= W ){
    for(int i = 0; i < H; i++) {
      ans++;
      for (int j = 0; j < W; j++) {
        x++;
      }
      if(x >= N){
        break;
      }
    }
  } else {
    for(int i = 0; i < W; i++) {
      ans++;
      for (int j = 0; j < H; j++) {
        x++;
      }
      if(x >= N){
        break;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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


int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()>k)
    {
        s=s.substr(0,k);
        s+="...";
    }
    cout<<s<<endl;
    return 0;

}


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

int N, ans; string A, B, C;

int main() {
	cin >> N >> A >> B >> C;
	for (int i = 0; i < N; i++) {
		int bit[26]; for (int j = 0; j < 26; j++) bit[j] = 0;
		bit[A[i] - 'a']++;
		bit[B[i] - 'a']++;
		bit[C[i] - 'a']++;
		int ret = 0;
		for (int j = 0; j < 26; j++) ret = max(ret, bit[j]);
		ans += (3 - ret);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define vec vector
typedef int64_t intl;
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
vec<int> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};



int main(){
  string S,T;
  cin >> S >>T;
  if (S.size() != T.size() -1 ) {cout <<"No"; return 0;} 
  Rep (i, S.size() ){
    if ( S.at(i) != T.at(i) ){ cout << "No";return 0;}
  }
  cout << "Yes";
}

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

int main() {
    ll n;
    cin>>n;
    V ans(n);
    rep(i,n){
        ll a;
        cin>>a;
        ans[a-1]=i+1;
    }
    rep(i,n){
        cout<<ans[i];
        if(i!=n-1)cout<<" ";
        else cout<<endl;
    }
}


Measured memory_bytes: 1664
*d=0;*c=0,2,5,5,4,5,6,3,7,6;eval"N,_,*A="+`dd`.split*?,;p d[N.times{|i|d[i]&&A.map{|x|d[t=i+c[x]]=[d[t]||0,d[i]*10+x].max}}]

Measured memory_bytes: 29056
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;



int main() {
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	while (n > 0) {
		if (n % 4 == 0) {
			cout << "Yes";
			return 0;
		}
		n -= 7;
	}

	if (n == 0) cout << "Yes";
	else cout << "No";

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [x, y, z] <- readInts
  solve x y z

solve x y z = putStr (show z) >> putStr " " >> putStr (show x) >> putStr " " >> putStrLn (show y)

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 380
import java.util.*;

public class Main {
    public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      int a = Integer.parseInt(scan.next());
      long b = Long.parseLong(scan.next());
      long n = Long.parseLong(scan.next());
      scan.close();
      
      long x = Math.min(b-1,n);
      System.out.println((a*x/b)-a*(x/b));
    }
}

Measured memory_bytes: 35736
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
//	入力の読み込み
		Scanner sc = new Scanner(System.in);
		int member = sc.nextInt();  //すぬけの人数
		int sweet = sc.nextInt();  //お菓子の種類数
		int result = 0;  //いたずらされる人数
		int[] brother = new int[member];  //誰が何個持っているかを入れる箱

//
		for(int i=0 ; i<sweet ; i++) {
			int num = sc.nextInt();
			for(int j=0 ; j<num ; j++) {
				int sunuke = sc.nextInt();
				brother[sunuke-1] += 1;
			}
		}
//
		for(int i=0 ; i<member ; i++) {
			if(brother[i]==0) {
				result++;
			}
		}
		System.out.print(result);
	}
}

Measured memory_bytes: 37200
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
//大きい順
int compareInt(const void* a, const void* b){int aNum = *(int*)a;int bNum = *(int*)b;return bNum - aNum;}

long long _gcd(long long a,long long b){
    long long c;
    while(b!=0){c=a%b;a=b;b=c;}
    return a;
    
}
long long _lcm(long long a,long long b){long long c=_gcd(a,b);a/=c;return a*b;}

int main(void){
    int X,A;
    scanf("%d%d",&X,&A);
    (X<A)?printf("0"):printf("10");
    return 0;
    
}
    


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

n = int(input())
a = [int(x) for x in input().split()]

a_j = []
a_i = []

for i in range(n):
    a_j.append((i + 1) - a[i])
    a_i.append((i + 1) + a[i])

from collections import Counter

c1 = Counter(a_i)
c2 = Counter(a_j)
ans = 0
for c in c1.keys():
    ans += c1[c]*c2[c]
print(ans)


Measured memory_bytes: 167468
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static int cmp(const void *a, const void *b);

int main(int argc, char *argv[])
{
    int i, j, N, L;
    char str[120][120];
    scanf("%d %d\n", &N, &L);
    for ( i = 0; i < N; i++ ){
        fgets(str[i], 120, stdin);
    }
    qsort(str, N, 120, cmp);
    for ( i = 0; i < N; i++ ){
        for ( j = 0; j < L; j++ ){
            printf("%c", str[i][j]);
        }
    }
    printf("\n");
    return 0;
}

static int cmp(const void *a, const void *b)
{
    return strcmp( (char *)a, (char *)b );
}

Measured memory_bytes: 252
#include <bits/stdc++.h>
const int MOD=1e9+7;
using namespace std;

long long n, maxw, w[105], v[105], dp[105][100005] = {0};
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> maxw;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < maxw; j++)
            if(j == 0 || dp[i][j] > 0)
            {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                if(j + w[i] <= maxw)
                    dp[i + 1][j + w[i]] = dp[i][j] + v[i];
            }
    long long ans = 0;
    for(int j = 0; j <= maxw; j++)
        ans = max(ans, dp[n][j]);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 78208
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin>>c[i][j];
    }
  }
  
  for (int i = 0; i < 2; i++) {
    if(c[i][0]-c[i+1][0]!=c[i][1]-c[i+1][1]||c[i][1]-c[i+1][1]!=c[i][2]-c[i+1][2]){cout<<"No"<<endl;return 0;}
  }
  for (int i = 0; i < 2; i++) {
    if(c[0][i]-c[0][i+1]!=c[1][i]-c[1][i+1]||c[1][i]-c[1][i+1]!=c[2][i]-c[2][i+1]){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
  return 0;
}


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


Measured memory_bytes: 1564
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll count=0;
	ll n;
	cin>>n;
	ll a[n];
	for (ll i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for (ll i = 0; i < n-2; ++i)
	{ 
		for (ll j = i+1; j <n-1 ; ++j)
		{
			if (a[i]!=a[j])
				for (ll k = j+1; k < n; ++k)
				{
					if (a[i]+a[j]>a[k] && a[j]!=a[k] && a[k]!=a[i])
					{
						// cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
						count++;
					}
				}
		}
	}
	cout<<count;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
long long n;
vector < int > solve(long long n){
	if(n == 1){
		return vector < int > ();
	}
	if(n & 1){
		auto res = solve(n - 1);
		res.insert(res.begin() , res.size());
		return res;
	}
	else{
		auto res = solve(n >> 1);
		res.push_back(res.size());
		return res;
	}
}
int main(){
	cin >> n;
	auto ans = solve(n + 1);
	printf("%d\n" , int(ans.size()) * 2);
	for(int x : ans){
		cout << x + 1 << " ";
	}
	for(int i = 0 ; i < ans.size() ; ++i){
		cout << i + 1 << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut b = vec![];
    for x in a {
        let i = bs(&b, &x);
        if i == b.len() {
            b.push(x);
        } else {
            b[i] = x;
        }
    }
    println!("{}", b.len());
}

#[allow(dead_code)]
fn bs<T: Ord>(arr: &[T], x: &T) -> usize {
    let mut ok = arr.len() as i64;
    let mut ng = -1i64;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if &arr[mid as usize] < x {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok as usize
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> pr;
    rep(i, 0, n) {
        int a;
        cin >> a;
        pr.push_back(make_pair(a, i + 1));
    }
    sort(all(pr));
    for (auto i : pr) {
        cout << i.second << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	char c;
	cin >> c;

	if(c == 'A') cout << 'T' << endl;
	else  if(c == 'C') cout << 'G' << endl;
	else  if(c == 'G') cout << 'C' << endl;
	else cout << 'A' << endl;
}

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

int main(){
    //電源タップ
    int A, B;
    int plug = 1;
    int counter = 0;
    bool is_good = true;
    cin >> A >> B;
    
    while(is_good){
        if(plug >= B){
            is_good = false;
        }
        else{
            plug += A - 1;
            counter += 1;
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w, k;
char s[30][31];
int ans;

int main() {
	scanf("%d%d%d", &h, &w, &k);
	inc(i, h) { scanf("%s", s[i]); }
	
	inc(ii, h) {
	inc(jj, w) {
		int b[30][30];
		inc(i, h) {
		inc(j, w) {
			b[i][j] = s[i][j] - '0';
		}
		}
		
		int score = 0;
		b[ii][jj] = -1;
		int counter = 0;
		bool flag;
		do {
			inc(j, w) { int bot = h - 1;
			dec(i, h) {
				if(b[i][j] == -1) { continue; }
				int temp = b[i][j];
				b[i][j] = -1;
				b[bot][j] = temp;
				bot--;
			}
			}
			
			flag = false;
			inc(i, h) { int len = 1, pre = -2;
			inc(j, w) {
				if(b[i][j] == pre) { len++; } else { len = 1; pre = b[i][j]; }
				if(b[i][j] != -1 && len == k) {
					incII(jjj, j - (k - 1), j) {
						score += (1 << counter) * b[i][jjj];
						b[i][jjj] = -1;
					}
					flag = true;
				}
				if(b[i][j] != -1 && len >  k) {
					score += (1 << counter) * b[i][j];
					b[i][j] = -1;
				}
			}
			}
			
			counter++;
		} while(flag);
		
		setmax(ans, score);
	}
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 128
from itertools import permutations
N = int(input())

P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

Pe = permutations(range(1,N+1),N)
a = b = 0

for i,p in enumerate(Pe):
    if P == p: a = i
    if Q == p: b = i
print(abs(a-b))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LLINF 1<<63-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define MOD 1000000007
#define NUM 100001
void swap(int* x,int* y){
  int tmp=*x;*x=*y;*y=tmp;
}
int cmp(const void *x,const void *y){
  return *(int*)x-*(int*)y;
}

typedef struct{char S[11];int P;int flag;int num;}P;
/*int Scmp(const void *x,const void *y){
  return ((P*)y)->P-((P*)x)->P;
}*/
int Scmp2(const void *x,const void *y){
  return ((P*)x)->flag-((P*)y)->flag;
}
int Scmp(const void* x, const void* y) {
    const char *x_char=((P*)x)->S;
    const char *y_char=((P*)y)->S;
    int n=strcmp(x_char,y_char);
    if(n==0)n=((P*)y)->P-((P*)x)->P;
    return n;
}

int main() {
  int i,N,ans=0;
  scanf("%d",&N);
  P res[N];
  for(i=0;i<N;i++)scanf("%s%d",res[i].S,&res[i].P);
  for(i=0;i<N;i++)res[i].flag=i+1;
  qsort(res,N,sizeof(P),Scmp);
  for(i=0;i<N;i++)printf("%d\n",res[i].flag);
  /*for(i=0;i<N;i++)res[i].num=i+1;
  qsort(res,N,sizeof(P),Scmp2);
  for(i=0;i<N;i++)printf("%d\n",res[i].num);*/
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  if((a+b)%2 == 1){
    cout << (a+b)/2 +1 << endl;
  }else{
    cout << (a+b)/2 << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const {
    return mint(-x);
  }
  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 {
    return mint(*this) += a;
  }
  mint operator-(const mint a) const {
    return mint(*this) -= a;
  }
  mint operator*(const mint a) const {
    return mint(*this) *= 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 {
    return mint(*this) /= a;
  }
};
istream &operator>>(istream &is, const mint &a) {
  return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
  return os << a.x;
}

mint dp[3001][3001];

void solve(long long A, long long B, long long C, long long D) {
  dp[B][A] = 1;
  FOR(x, A + 1, C + 1) {
    dp[B][x] = dp[B][x - 1] * B;
  }
  FOR(y, B + 1, D + 1) {
    dp[y][A] = dp[y - 1][A] * A;
  }
  FOR(y, B + 1, D + 1) {
    FOR(x, A + 1, C + 1) {
      dp[y][x] = dp[y][x - 1] * y + dp[y - 1][x] * x - dp[y - 1][x - 1] * (x - 1) * (y - 1);
    }
  }
  cout << dp[D][C] << endl;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long D;
  scanf("%lld", &D);
  solve(A, B, C, D);
  return 0;
}


Measured memory_bytes: 74112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,r;
    cin>>s;
    int moves=0;
    int i=1;
    int f=0;
    while(s.size()>2&&i<s.size())
    {
         f=0;
        if((i+1)<s.size())
        {
            if(s[i-1]!=s[i+1])
            {
                f=1;
                s.erase(i,1);
                moves++;
            }
    
        }
        if(!f)
            i++;
        else
            i=max(1,i-1);
 
    }
    if(moves%2)
        printf("First");
    else
        printf("Second");
    return 0;
}

Measured memory_bytes: 512
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.rstrip() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N = makeInt(input_string[0])
    S = makeStringMatrix(input_string[1:])
    #print(S)
    C_S_has_ab = []
    for s_index, s in enumerate(S):
        C_S_has_ab.append(0)
        for i in range(len(s)-1):
            if s[i] + s[i+1] == 'AB':
                C_S_has_ab[s_index] += 1
    #print(C_S_has_ab)
    _sum = 0
    _sum += sum(C_S_has_ab) 
    c_head_has_b = 0
    c_tail_has_a = 0
    c_head_tail_has_a_and_b = 0
    for s in S:
        """
        if s[0] == 'B':
            c_head_has_b += 1
        if s[-1] == 'A':
            c_tail_has_a += 1
        if s[0] == 'B' and s[-1] == 'A':
            c_head_tail_has_a_and_b += 1
        """
        if(s[0] == 'B' and s[-1] == 'A'):
            c_head_tail_has_a_and_b += 1
        elif(s[-1] == 'A'):
            c_tail_has_a += 1
        elif(s[0] == 'B'):
            c_head_has_b += 1
    #print(c_head_has_b, c_tail_has_a, c_head_tail_has_a_and_b)
    if c_head_tail_has_a_and_b > 0:
        count_combi_a_b = max(0, c_head_tail_has_a_and_b-1) + min(c_head_has_b, c_tail_has_a)
        if c_head_has_b > 0 or c_tail_has_a > 0:
            count_combi_a_b += 1
    else:
        count_combi_a_b = min(c_head_has_b, c_tail_has_a)
    _sum += count_combi_a_b
    #print(_sum)
    return _sum


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Char
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


------------------
-- #   Read   # --
------------------

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

data J = J {ac :: Int, wa :: Int, tle :: Int, re :: Int}

instance Show J where
    show j = "AC x " ++ show (ac j) ++
        "\nWA x " ++ show (wa j) ++
        "\nTLE x " ++ show (tle j) ++
        "\nRE x " ++ show (re j)

emp = J 0 0 0 0

acum j "AC" = j{ac=(ac j + 1)} 
acum j "WA" = j{wa=(wa j + 1)} 
acum j "TLE" = j{tle=(tle j + 1)} 
acum j "RE" = j{re=(re j + 1)} 

main :: IO ()
main = do
    n <- readLn
    ss <- V.replicateM n getLine
    print $ V.foldr (flip acum) emp ss


Measured memory_bytes: 27932
#include <cstdio>
#include <cctype>

int read() {
	int x=0; char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=x*10+c-'0', c=getchar();
	return x;
}
const int LIM=100;
int A[LIM], B[LIM], C[LIM];
int main() {
	int n=read();
	for(int i=1; i<=n; i++) A[i]=read();
	for(int i=1; i<=n; i++) B[i]=read();
	for(int i=1; i<n; i++) C[i]=read();
	int sum=0;
	for(int i=1; i<=n; i++) {
		sum+=B[A[i]];
		if(i==1) continue;
		if(A[i]==A[i-1]+1) sum+=C[A[i]-1];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128