akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<int> q(n);
    for (int i = 0; i < n; ++i) {
        cin >> q[i];
    }
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        v[i] = i + 1;
    }
    int a = -1, b = -1;
    int j = 0;
    do
    {
        if (v == p) {
            a = j;
        }
        if (v == q) {
            b = j;
        }
        ++j;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5)+ 1;
const int max_m = 83 * (1e5) + 1;
const ll INF = 10241024;
long double INFD = 100100100;

//_________template______________

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T1, class T2> inline void Abs(T1 &a){a > 0 ? a : -a;}

template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }

  return C;
}

vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }

  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
string s;
void input(){
  IN(s);
}
int dp[100100][13];
void solve(){
  input();
  reverse(All(s));
  int n = s.size();
  dp[0][0] = 1;
  int mul = 1;
  rep(i,n){
      rep(j,13){
        rep(k,10){
          if(s[i] == '?' || s[i] - '0' == k)
          {
          update(dp[i+1][(k*mul + j) %13], dp[i][j]);
          }
        }
      }
    mul *= 10;mul %= 13;
  }

  OUT(dp[n][5]);
}

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




Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
template<typename tn> void read(tn &a){
    tn x=0,f=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
    a=x*f;
}
int n,ans;
char c;
int main(){
	read(n);
	c=getchar();
	while(n--){
		char x=getchar();
		if(x!=c) ans++;
		c=x; 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
use std::cmp;
use std::collections::BinaryHeap;

const INF: i64 = std::i64::MAX;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let m: usize = sc.read();
    let k: usize = sc.read();
    let bread: Vec<i64> = sc.vec(n);
    let jam_kind: Vec<usize> = sc.vec::<usize>(n).into_iter().map(|k| k - 1).collect();
    let jam_value: Vec<i64> = sc.vec(n);

    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let u = sc.read::<usize>() - 1;
        let v = sc.read::<usize>() - 1;
        let t = sc.read::<i64>();
        graph[v].push((u, t));
        graph[u].push((v, t));
    }

    let dist = dijkstra(&graph);
    let bread_dist = bread_dijkstra(&graph, &bread, &dist);
    let mut ans = vec![-INF; k];
    for i in 0..n {
        let bread_dist = bread_dist[i];
        let dist = dist[i];
        let jam_kind = jam_kind[i];
        let jam_value = jam_value[i];
        ans[jam_kind] = cmp::max(ans[jam_kind], jam_value - dist - bread_dist);
    }

    for ans in ans.into_iter() {
        println!("{}", ans);
    }
}

fn dijkstra(graph: &Vec<Vec<(usize, i64)>>) -> Vec<i64> {
    let n = graph.len();
    let mut dist = vec![INF; n];
    dist[0] = 0;
    let mut q = BinaryHeap::new();
    q.push((0, 0));

    let mut vis = vec![false; n];
    while let Some((_, v)) = q.pop() {
        if vis[v] {
            continue;
        }
        vis[v] = true;
        for &(next, weight) in graph[v].iter() {
            if dist[next] > dist[v] + weight {
                dist[next] = dist[v] + weight;
                q.push((-dist[next], next));
            }
        }
    }
    dist
}

fn bread_dijkstra(
    graph: &Vec<Vec<(usize, i64)>>,
    bread: &Vec<i64>,
    prev_dist: &Vec<i64>,
) -> Vec<i64> {
    let n = graph.len();
    let mut dist = vec![INF; n];
    let mut q = BinaryHeap::new();
    for i in 0..n {
        dist[i] = prev_dist[i] - bread[i];
        q.push((-dist[i], i));
    }

    let mut vis = vec![false; n];
    while let Some((_, v)) = q.pop() {
        if vis[v] {
            continue;
        }
        vis[v] = true;

        for &(next, weight) in graph[v].iter() {
            if dist[next] > dist[v] + weight {
                dist[next] = dist[v] + weight;
                q.push((-dist[next], next));
            }
        }
    }
    dist
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;


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

    cout << min((b / a), c) << endl;


}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<string>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = 998244353;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

ll N, M, K, C[maxn], res;
ll power(ll a, ll b) {
	ll res = 1;
	for (; b; a = a * a % mod, b >>= 1) if (b & 1) res = res * a % mod;
	return res;
}
void init() {
	C[0] = 1;
	for (ll i = 1; i <= N - 1; i++) 
		C[i] = C[i - 1] * ((N - 1) - i + 1) % mod * power(i, mod - 2) % mod;
}

int main() {
	
	// freopen("in.in", "r", stdin);
	scanf("%lld%lld%lld", &N, &M, &K);
	init();
	for (ll t = N - K; t <= N; t++) 
		res = (res + C[t - 1] * M % mod * power(M - 1, t - 1) % mod) % mod;
	printf("%lld\n", res);

	return 0;
}		


Measured memory_bytes: 4752
S = list(str(input()))
agct = {'A', 'C', 'G', 'T'}

ans = 0
tmp_ans = 0
flg = 0
for s in S:
    # contain acgt
    if s in agct:
        if flg == 0:
            flg = 1
        tmp_ans += 1
    else:
        if flg == 1:
            flg = 0
            if ans < tmp_ans:
                ans = tmp_ans
            tmp_ans = 0
else:
    if flg == 1:
        if ans < tmp_ans:
            ans = tmp_ans
        tmp_ans = 0

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<=s.size()/2+1;++i){
        if(s[i]!=s[s.size()-1-i]){
            if(s[i]=='x')s.insert(s.end()-i,'x');
            else if(s[s.size()-1-i]=='x')s.insert(s.begin()+i,'x');
            else {
                cout<<-1<<endl;
                return 0;
            }
            ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math/big"
)

func main(){
	var N int64
	fmt.Scan(&N)

	// (N-1)(1 + N-1)/2
	// (N^2 - N)/2
	var i, e = big.NewInt(N), big.NewInt(2)
	i.Exp(i, e, nil)
	i.Sub(i, big.NewInt(N))
	i.Div(i, big.NewInt(2))
	fmt.Println(i)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <cmath>
#include <set>

using namespace std;

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

Measured memory_bytes: 256
def calc_temp(x,T):
    return T - x * 0.006

N = int(input())
T,A = map(int,input().split())
H_list = list(map(int,input().split()))

near_temp = 1000

for i in range(N):
    if abs(A - calc_temp(H_list[i],T)) <= abs(A - near_temp):
        near_temp = calc_temp(H_list[i],T)
        num = i+1

print(num)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
int main()
{

    long long int num,val=0;
    map<string,long long int>mp;
    vector<long long int>vec;
    string word;
    cin>>num;
    for(int i=0;i<num;i++)
    {
           cin>>word;
           sort(word.begin(),word.end());
           mp[word]++;
    }
    for(auto it:mp)
        vec.push_back(it.second);
    for(int y=0;y<vec.size();y++)
        val+=vec[y]*(vec[y]-1)*0.5;
    cout<<val<<endl;
    return 0;
}



Measured memory_bytes: 12280
#include <stdio.h>

int main()
{
	int i, N, K, A[200001], max = 0;
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) {
		scanf("%d\n", &(A[i]));
		if (A[i] > max) max = A[i];
	}

	int l = 1, r = max, m, tmp, count;
	while (l < r) {
		m = (l + r) / 2;
		for (i = 1, count = 0; i <= N; i++) {
			count += (A[i] - 1) / m;
			if (count > K) break;
		}
		if (count > K) l = m + 1;
		else r = m;
	}

	printf("%d\n", l);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2460
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());

    if (A <= 8 && B <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }

  }
}

Measured memory_bytes: 21716
($N,$C)=split$",<>;
@D=map[split$",<>],1..$C;
for(<>){
	$j=$i;
	for$x(split){
		for(0..$C-1){
			$_[$j][$_]+=$D[$x-1][$_]
		}
		++$j==3&&($j=0)
	}
	++$i==3&&($i=0)
}
$y=1e18;
for$i(0..$C-1){
	for$j(0..$C-1){next if$i==$j;
		for$k(0..$C-1){next if$i==$k||$j==$k;
			$x=$_[0][$i]+$_[1][$j]+$_[2][$k];
			$y=$x if$x<$y
		}
	}
}
print$y


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

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

int main()
{
    int N;
    ll cnt[5] = {0};
    ll sum = 0;
    string tmp = "MARCH";
    cin >> N;
    vector <string> s(N);
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        for (int j = 0; j < tmp.size(); j++) {
            if (s[i][0] == tmp[j]) cnt[j]++;
        }
    }
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            for (int k = j+1; k < 5; k++) {
                sum += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << sum << endl;
        

    return 0;
}



Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
int H,W;
char mat[1005][1005];
int mod=1e9+7;
void func(){
	vector<vector<int>> dp(1005,vector<int>(1005,0));
	dp[0][0]=1;
	for(int i=1;i<H;i++)
	{
		if(mat[i][0]=='#')dp[i][0]=0;
		else{
			dp[i][0]=dp[i-1][0];
		}
	}
	for(int j=1;j<W;j++){
		if(mat[0][j]=='#')dp[0][j]=0;
		else{
			dp[0][j]=dp[0][j-1];
		}
	}
	
	for(int i=1;i<H;i++){
		for(int j=1;j<W;j++){
			if(mat[i][j]=='#')dp[i][j]=0;
			else 
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[H-1][W-1]%mod<<endl;
}
int main(){
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>mat[i][j];
		}
	}
	/*for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cout<<mat[i][j]<<" ";
		}
		cout<<endl;
	}*/

	func();
	return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    ll ans = 0;
    rep(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    for(int i = 0;i < N;i++){
        for(int j = i + 1;j<N;j++){
            auto lb = upper_bound(L.begin()+j+1,L.end(),L[j]-L[i]);
            auto r = lower_bound(L.begin()+j+1,L.end(),L[j]+L[i]);
            ans += r - lb;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int a[3][n];
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
    sort(a[i], a[i] + n);
  }

  long long int ans = 0;
  for(int j = 0; j < n; j++) {
    int i = lower_bound(a[0], a[0] + n, a[1][j]) - a[0];
    int k = upper_bound(a[2], a[2] + n, a[1][j]) - a[2];
    ans += (long long int) i * (n - k);
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 1408
import java.util.Scanner;

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

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int min = Math.min(a * n, b);
        System.out.println(min);
    }
}


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

using namespace std;

using LL = long long;

// 701  = zy


void solver() {
    
    LL N; cin >> N;

    string ans = "";

    while(N >= 1){
        char add = ((N - 1 + 26) % 26) + 'a';
        N = ((N-1LL)/26);
        ans += add;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << '\n';
}

int main() {

    ios_base :: sync_with_stdio(0); cin.tie(NULL);

    int t = 1;
    //cin >> t;
    
    while(t--)
        solver();

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v) {os << " [" << i++ << "]" << x; if (i % 10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp) {os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string s;
  std::cin >> s;

  if(s.find("AC") != std::string::npos) {
    print("Yes");
  } else {
    print("No");
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	int counter = 0;
	for (int i = 1; i < n - 1; i++) {
		vector<int> tmp(3);
		tmp[0] = p[i - 1];
		tmp[1] = p[i];
		tmp[2] = p[i + 1];
		sort(tmp.begin(), tmp.end());
		if (tmp[1] == p[i]) counter++;
	}
	cout << counter << endl;
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    if(N/10==9||N%10==9){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "math"
)


func foo(h float64) int {
  sum := 0.0
  i := 0.0
  for {
    sum += math.Pow(2, i)
    if sum >= h {
      break
    }
    i += 1
  }
  return int(sum)
}

func main() {
  var h float64
  fmt.Scan(&h)
  fmt.Println(foo(h))
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) {
        cout << ":(" << endl;
    }
    else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
<?php
	while( true ) {
		list( $m, $f, $r ) = explode( ' ', trim( fgets( STDIN ) ) );
		if( -1 == $m && -1 == $f && -1 == $r ) { break; }
		
		$sum = $m + $f;
		if( -1 == $m || -1 == $f ) {
			print "F".PHP_EOL;
		} else if( 80 <= $sum ) {
			print "A".PHP_EOL;
		} else if( 65 <= $sum && $sum < 80 ) {
			print "B".PHP_EOL;
		} else if( 50 <= $sum && $sum < 65 ) {
			print "C".PHP_EOL;
		} else if( 30 <= $sum && $sum < 50 ) {
			if( 50 <= $r ) {
				print "C".PHP_EOL;
			} else {
				print "D".PHP_EOL;
			}
		} else {
			print "F".PHP_EOL;
		}
	}
	return;
?>

Measured memory_bytes: 6584
import numpy as np
N, M = list(map(int, input().split()))
PYs = []
for _ in range(M):
    PYs.append(list(map(int, input().split())))
PYs = np.asarray(PYs)
indx = np.argsort(PYs[:,1])
ans = [" " for _ in range(M)]
city = [1 for _ in range(N)]
for i in indx:
    ans[i] = str(PYs[i, 0]).zfill(6) + str(city[PYs[i, 0]-1]).zfill(6)
    city[PYs[i, 0]-1] += 1
for a in ans:
    print(a)


Measured memory_bytes: 37884
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200005];
	scanf("%s", s);
	int n = strlen(s);
	int i;
	int p = 2019;
	int m[200005];
	int k = 10;
	m[n - 1] = s[n - 1] - '0';
	for (i = n - 2; i >= 0; i--)
	{
		m[i] = ((s[i] - '0') * k + m[i + 1]) % p;
		//printf("%d:%d, %d\n",i,m[i],k);
		k = 10 * k % p;
		
	}
	long long int cnt[2020];
	for (i = 0; i < 2020; i++)
		cnt[i] = 0;
	for (i = 0; i < n; i++)
		cnt[m[i]]++;
	cnt[0]++;
	long long int ans = 0;
	for (i = 0; i < 2020; i++){
		ans += cnt[i] * (cnt[i] - 1) / 2;
		//if(cnt[i]>0)printf("cnt:%d,%d\n",i,cnt[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2608
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    ans = -1

else:
    if k % 7 == 0:
        L = k * 9 // 7
    
    else:
        L = k * 9
        
    amari = 10 % L
        
    for i in range(1,10**6+1):
        if amari == 1:
            ans = i
            break
        
        amari = (amari * 10) % L
        
print(ans)

Measured memory_bytes: 9168
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};




int main(){
  ll x; cin >> x;
  if(x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3580
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

ans = []
for i in range(h - 1):
    for j in range(w):
        if a[i][j] % 2 == 1:
            a[i][j] -= 1
            a[i + 1][j] += 1
            ans.append([i + 1, j + 1, i + 2, j + 1])
for i in range(w - 1):
    if a[-1][i] % 2 == 1:
        a[-1][i] -= 1
        a[-1][i + 1] += 1
        ans.append([h, i + 1, h, i + 2])
print(len(ans))
for ln in ans:
    print(' '.join(map(str, ln)))

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

using namespace std;

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

void division(string const &raw, string &left, string &right) {
  
  int const N = raw.size();
  int retain = 0;
  REP(pos, 1, N) {
    if(raw[pos] == '(') retain++;
    else if(raw[pos] == ')') retain--;
    else if(retain == 0) {
      //assert(raw[pos] == ',');
      left  = raw.substr(1, pos-1);
      right = raw.substr(pos+1, N-pos-2);
      break;
    }
  }
  
}

string solve(char op, string const &s, string const &t) {
  if(s.empty() || t.empty()) {
    if(op == 'i') return min(s, t);
    else return max(s, t);
  }
  
  string sL, sR, tL, tR;
  division(s, sL, sR);
  division(t, tL, tR);
  
  return '(' + solve(op, sL, tL) + ',' + solve(op, sR, tR) + ')';
}

int main() {
  
  char op; string s, t;
  while(cin >> op >> s >> t) {
    cout << solve(op, s, t) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
typedef long long ll;

int main()
{
    ll cokkie[2];
    ll k;
    ll i, j;

    scanf("%lld %lld %lld", &cokkie[0], &cokkie[1], &k);

    for (i = 0; i < k; i++) {
        if (cokkie[i % 2] & 1) {
            cokkie[i % 2]--;
        }

        cokkie[(i + 1) % 2] += cokkie[i % 2] / 2;
        cokkie[i % 2] /= 2;
    }

    printf("%lld %lld\n", cokkie[0], cokkie[1]);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::vector<i64> A;
  tools::read(A, N);

  i64 i = 0;
  for (; A[i] != 1; ++i);

  std::cout << tools::ceil(i, K - 1) + tools::ceil(N - tools::ceil(i, K - 1) * (K - 1) - 1, K - 1) << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll bit[200010], num;
ll N, Q, s[200010], t[200010], X[200010], q[200010];
vector<ll> flg[200010];
priority_queue<ll, vector<ll>, greater<ll>> que;

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> N >> Q;
	for (int i = 1; i <= N; i++)
	{
		cin >> s[i] >> t[i] >> X[i];
	}
	for (int i = 0; i < Q; i++)
	{
		cin >> q[i];
	}
	for (int i = 1; i <= N; i++)
	{
		ll lb = -1, ub = Q, u, v;
		while (lb + 1 < ub)
		{
			ll mid = (lb + ub) / 2;
			if (q[mid] < s[i] - X[i])
			{
				lb = mid;
			}
			else
			{
				ub = mid;
			}
		}
		u = ub;
		lb = -1, ub = Q;
		while (lb + 1 < ub)
		{
			ll mid = (lb + ub) / 2;
			if (q[mid] > t[i] - X[i] - 1)
			{
				ub = mid;
			}
			else
			{
				lb = mid;
			}
		}
		v = lb + 1;
		if (u == v) continue;
		flg[u].push_back(X[i]);
		flg[v].push_back(X[i]);
	}
	for (int i = 0; i < Q; i++)
	{
		for (int j = 0; j < flg[i].size(); j++)
		{
			que.push(flg[i][j]);
		}
		if (que.size() == 0)
		{
			cout << -1 << endl;
		}
		else if (que.size() == 1)
		{
			cout << que.top() << endl;
		}
		else
		{
			ll fst = que.top(); que.pop();
			ll scd = que.top(); que.pop();
			while (true)
			{
				if (fst != scd)
				{
					que.push(fst);
					que.push(scd);
					break;
				}
				else if (que.size() <= 1)
				{
					break;
				}
				else
				{
					fst = que.top(); que.pop();
					scd = que.top(); que.pop();
				}
			}
			if (que.size() == 0)
			{
				cout << -1 << endl;
			}
			else
			{
				cout << que.top() << endl;
			}
		}
	}
	int www;
	cin >> www;
}


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

vector<ll> split(string s, string c) {
    vector<ll> ret;
    for (int i = 0, n; i <= s.length(); i = n + 1) {
        n = s.find_first_of(c, i);
        if (n == string::npos) n = s.length();
        string tmp = s.substr(i, n - i);
        ret.push_back(stoll(tmp));
    }
    return ret;
}

string S;
ll ans = 0;

void dfs(string s, int i) {
    if (i + 1 == S.length()) {
        if (s[s.length() - 1] == '@') return;
        if (regex_search(s, regex("\\@\\@"))) return;
        vector<ll> nums = split(s, "@");
        ans += accumulate(nums.begin(), nums.end(), 0LL);
        return;
    }
    dfs(s + S.substr(i + 1, 1), i + 1);
    dfs(s + "@" + S.substr(i + 1, 1), i + 1);
}

int main() {
    cin >> S;
    int maxp = S.size() & 1 ? (S.size() - 2) / 2 + 1 : (S.size() - 2) / 2;

    dfs(S.substr(0, 1), 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    uint N, K;
    cin >> N >> K;
    vector<int> p(N, 0);
    for (auto &x: p) cin >> x;
    sort(p.begin(), p.end());
    int cost = 0;
    for (uint i=0; i<K; i++) {
        cost += p[i];
    }
    cout << cost << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <stdlib.h>
#include <time.h> 
#include <assert.h>

#define nmax 500010
#define eps 1e-8
#define MOD 998244353

#define P1 25671
#define P2 191
#define MOD1 666013
#define MOD2 1000000007
#define B_SIZE 315

#define SZ(x) ((int)(x.size()))

#define fst first
#define snd second
#define pb push_back
#define mp make_pair

using namespace std;

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

typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int n;
int dp[5][nmax];
int pr[5][nmax];

int main()
{
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) 
		scanf("%d %d %d", &pr[0][i], &pr[1][i], &pr[2][i]);

	for (int i = 1; i <= n; i++)
		for (int j = 0; j < 3; j++)
			for (int k = 0; k < 3; k++)
				if (j != k) dp[j][i] = max(dp[j][i], dp[k][i - 1] + pr[j][i]);

	printf("%d", max(dp[0][n], max(dp[1][n], dp[2][n])));

	return 0;
}

Measured memory_bytes: 11008
N = int(input())
alp = [chr(ord('a') + i) for i in range(26)]
result = []
def Base10_to_alp(n):
    quot = int(n / 26)
    surplus = n % 26
    quot -= 1 if surplus == 0 else 0
    surplus = 26 if surplus == 0 else surplus
    result.append(surplus)
    if 26 < quot:
        Base10_to_alp(quot)
    elif 26 < n:
        result.append(quot)
    return "".join([alp[i - 1] for i in reversed(result)])
print(Base10_to_alp(N))

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin>>s;
  ll n=s.size();

  ll now=0;
  ll ans=0;
  REP(i,n){
    if(s[i]=='R')
      now++;
    else{
      ans=max(ans,now);
      now=0;
    }
  }

  ans=max(ans,now);
  cout<<ans<<endl;
}



Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator 

int ar[51];
void solve() {
    int n, k; cin>>n>>k;
    for(int i=0;i<n;i++) cin>>ar[i];
    sort(ar, ar+n);
    int res=0;
    for(int i=n-1;i>=n-k;i--) {
        res += ar[i];
    }
    cout<<res<<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int A[100];
void print(int A[], int n)
{
	for (int i = 0; i < n-1; ++i)
	{
		cout<<A[i]<<" ";
	}
	cout<<A[n-1]<<endl;
}

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>A[i];
	}
	print(A,n);
	for (int i = 1; i < n; ++i)
	{
		int v = A[i];
		int j = i-1;
		while(j >= 0 && A[j] > v)
		{
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		print(A, n);
	}

	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll d(N);
        rep(i, 0, N) cin >> d[i];
        ll ans = 0;
        rep(i, 0, N) {
                rep(j, i+1, N) {
                        ans += d[i] * d[j];
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

bool is_palindrome(string s, int start, int end){
    f(i, start, end/2){
        if(s.at(i) != s.at(end-i-1)){
            return false;
        }
    }
    return true;
}

int main(){
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    int l = s.length();
    if(is_palindrome(s, 0, l) and is_palindrome(s, 0, (l-1)/2) and is_palindrome(s, (l+3)/2, l)){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  int n; cin>>n;
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int ans=0;
  rep(i,n-1){
    ans+=p[i];
  }
  ans+=p[n-1]/2;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

struct UnionFind {  
  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2
  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {                 // xとyの木を併合
    int rx = root(x);                        //xの根をrx
    int ry = root(y);                        //yの根をry
    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする
    par[ry] = rx; 
    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない
  }
 
  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
  
  int size(int x){                           //xが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};
 
vector<pair<ll,P>> edges;
vector<ll> a(mx);
ll n,d;

ll dist(int x,int y){ return d*abs(x-y)+a[x]+a[y]; }

void dfs(int l, int r){
  if(l+1>=r){ return; }
  ll mini=longinf, idx=-1;
  int m=(l+r)/2;
  for(int i=l; i<m; i++){ if(dist(i,m)<mini)mini=dist(i,m),idx=i; }
  for(int i=m; i<r; i++){ edges.push_back({dist(idx,i),{idx,i}}); }

  mini=longinf; idx=-1;
  for(int i=m; i<r; i++){ if(dist(i,l)<mini)mini=dist(i,l),idx=i; }
  for(int i=l; i<m; i++){ edges.push_back({dist(idx,i),{idx,i}}); }
  
  dfs(l,m);
  dfs(m,r);
}

int main(){
  cin >> n >> d;
  rep(i,n){ cin>>a[i]; }
  
  dfs(0,n);
  sort(edges.begin(),edges.end());
  
  UnionFind uf(n);
  ll ans=0;
  for(auto e:edges){
    int u=e.S.F,v=e.S.S; ll c=e.F;
    if(!uf.check(u,v)){ uf.unite(u,v); ans+=c;}
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 69472
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  string s;
  cin >> s;
  bool out = false;
  int ans;
  for(int i = 1;i < s.size() / 2;i ++){
    for(int j = 0;j < i;j ++){
      //cout << s[j] << " " << s[i + j] << '\n';
      if(s[j] != s[i + j]){
	out = true;
	//	break;
      }
    }
    // cout << '\n';
    if(!out){
      ans = i;
    }
    out = false;
  }
  cout << ans * 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
L=[list(input()) for _ in range(H)]
L=[l for l in L if "#" in l]
#リストの中のリストで#を含まないリストは取り除く
LL=list(zip(*L))
#同じサブインデックスをもつ要素からなる配列を作る
LL=[l for l in LL if "#" in l]
L=list(zip(*LL))
for l in L:
  print("".join(l))

Measured memory_bytes: 3316
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class WarshallFloyd():
    def __init__(self, e, n):
        self.E = e
        self.N = n

    def search(self):
        n = self.N
        nl = list(range(n))
        d = [[inf] * n for _ in nl]
        for i in range(n):
            d[i][i] = 0
        for k,v in self.E.items():
            dk = d[k]
            for b,c in v:
                # consider multiple edges
                if dk[b] > c:
                    dk[b] = c
        for i in nl:
            di = d[i]
            for j in nl:
                if i == j:
                    continue
                dj = d[j]
                for k in nl:
                    if i != k and j != k and dj[k] > dj[i] + di[k]:
                        dj[k] = dj[i] + di[k]
        return d


def main():
    rr = []

    def f(n,m):
        le = collections.defaultdict(list)
        se = collections.defaultdict(list)
        for _ in range(m):
            l = LS()
            a,b,t = map(int, l[:-1])
            a -= 1
            b -= 1
            if l[-1] == 'S':
                se[a].append((b,t))
                se[b].append((a,t))
            else:
                le[a].append((b,t))
                le[b].append((a,t))
        q = I()
        qa = LI_()
        lw = WarshallFloyd(le, n)
        sw = WarshallFloyd(se, n)
        ld = lw.search()
        sd = sw.search()
        dp = [inf] * n
        dp[qa[0]] = 0
        # print('ld')
        # print('\n'.join('\t'.join(map(lambda x: '-' if x == inf else str(x), c)) for c in ld))
        # print('sd')
        # print('\n'.join('\t'.join(map(lambda x: '-' if x == inf else str(x), c)) for c in sd))
        for i in range(q-1):
            c = qa[i]
            ne = qa[i+1]
            lp = [inf] * n
            np = [inf] * n
            for j in range(n):
                np[j] = dp[j] + ld[c][ne]
                dj = dp[j] + ld[c][j]
                sdj = sd[j]
                for k in range(n):
                    if lp[k] > dj + sdj[k]:
                        lp[k] = dj + sdj[k]
            for j in range(n):
                if np[j] > lp[j] + ld[j][ne]:
                    np[j] = lp[j] + ld[j][ne]
            # print('cne', c, ne)
            # print('dp', dp)
            # print('lp', lp)
            dp = np

        # print('edp', dp)
        return min(dp)

    while 1:
        n,m = LI()
        if n == 0 and m == 0:
            break
        rr.append(f(n,m))
        # print('rr', rr[-1])

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 12484
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<functional>
#include<bits/stdc++.h>
#include<map>
#include<utility>

#define vec2c vector<vector<char>>
#define vec2i vector<vector<int>>
#define vecc vector<char>
#define vecs vector<string>
#define veci vector<int>
#define vecd vector<double>
#define vecl vector<long>
#define vecll vector<long long>
#define rep(i, n) for(int i=0; i < (int)(n); i++)
#define rrep(i, n) for(int i=(int)(n); i>=0;i--)
#define rep1e(i, n) for(int i=1; i <= (int)(n); i++)
#define rep1ne(i, n) for(int i=1; i < (int)(n); i++)

#define MAX 100010

using namespace std;

unsigned digit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

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

int main() {

	string S;
	cin >> S;

	rep(i, 3) {
		if (S[i] == S[i+1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 256