akhauriyash/Code-Regression huggingface dataset:
/******************************************
* AUTHOR : kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

#include <bits/stdc++.h>
using namespace std;

#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

typedef long long int ll;

const ll MOD = 1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

long double prob(long double arr[], int n, int ind, int cnt, vector<vector<long double>>& dp){
	if(ind>=n){
		if(cnt > n/2)
			return 1;
		else
			return 0;
	}
	if(dp[ind][cnt] != -1)
		return dp[ind][cnt];

	long double l = arr[ind] * prob(arr, n, ind+1, cnt+1, dp);
	long double r = (1-arr[ind]) * prob(arr, n, ind+1, cnt, dp);
	return dp[ind][cnt] = l+r;
}

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

	int n;
	cin>>n;
	long double arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];

	cout<<fixed<<setprecision(10);
	vector<vector<long double>>dp(n, vector<long double>(n+1, -1));
	cout<<prob(arr, n, 0, 0, dp);

	return 0;
}

Measured memory_bytes: 141440
import sys

n = int(input())

nodes = [[-1, -1, -1] for _ in range(n)]

depths = [None for _ in range(n)]

heights = [None for _ in range(n)]

for _ in range(n):
    nid, left, right = list(map(int, sys.stdin.readline().split()))
    nodes[nid][1] = left
    nodes[nid][2] = right

    if left != -1: nodes[left][0] = nid
    if right != -1: nodes[right][0] = nid

def set_depths_heights(nid, p):
    if nid == -1:
        return -1
    depths[nid] = p
    heights[nid] = max(
                    set_depths_heights(nodes[nid][1], p + 1),
                    set_depths_heights(nodes[nid][2], p + 1)) + 1
    return heights[nid]

for nid in range(n):
    if nodes[nid][0] == -1:
        set_depths_heights(nid, 0)

for nid, node in enumerate(nodes):
    pid = node[0]
    sibling = -1 if pid == -1 else (nodes[pid][1] if nodes[pid][1] != nid else nodes[pid][2])
    degree = (0 if node[1] == -1 else 1) + (0 if node[2] == -1 else 1)
    depth = depths[nid]
    height = heights[nid]
    n_type = 'root' if pid == -1 else 'leaf' if height == 0 else 'internal node'

    print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(nid, pid, sibling, degree, depth, height, n_type))



Measured memory_bytes: 5620
#include <iostream>
using namespace std;
int main(void){
    int n, i, a[101], diff_0_1, diff_1_2, diff_2_3, diff_3_4;
    
    while(1){
        cin >> n;
        if(n == 0) break;
        for(i=0; i<n+1; i++){
            cin >> a[i];
        }
    
        diff_0_1 = a[1] - a[0];
        diff_1_2 = a[2] - a[1];
        diff_2_3 = a[3] - a[2];
        diff_3_4 = a[4] - a[3];
        
        if(diff_0_1 == diff_1_2 && diff_1_2 == diff_2_3 && diff_2_3 == diff_3_4){
            int diff = diff_0_1;
            for(i=4; i<n+1; i++){
                if(a[i+1]-a[i] != diff){
                    cout << a[i+1] << endl;
                    break;
                }
            }
        }
        else if(diff_0_1 == diff_1_2 && diff_1_2 == diff_2_3){
            cout << a[4] << endl; 
        }
        else if(diff_0_1 == diff_1_2 && diff_1_2 == (diff_2_3 + diff_3_4)){
            cout << a[3] << endl;
        }
        else if(diff_0_1 == (diff_1_2 + diff_2_3) && diff_0_1 == diff_3_4){
            cout << a[2] << endl;
        }
        else if((diff_0_1 + diff_1_2) == diff_2_3 && diff_2_3 == diff_3_4){
            cout << a[1] << endl;
        }
        else if(diff_1_2 == diff_2_3 && diff_2_3 == diff_3_4){
            cout << a[0] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3072
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define e endl
#define MOD 998244353
int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b)<<e;


}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int N, K;
int d, A;

int main() {
    cin >> N >> K;
    vector<int> okashi(N, 0);
    //cout << "size" << okashi.size() << endl;
    FOR(i, 0, K) {
        cin >> d;
        FOR(j, 0, d) {
            cin >> A;
            okashi[A-1]++;
        }
    }
    auto count = count_if(okashi.begin(), okashi.end(), [](int x) { return x == 0; });
    cout << count << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	s=s+s.substr(0,s.size()-1);
	if(s.find(t)!=string::npos){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
vector<int>digit(int a)
{
    vector<int>x;
    while(a>0)
    {
        x.pb(a%10);
        a/=10;
    }
    reverse(x.begin(),x.end());
    return x;
}

signed main()
{
 string s;
 cin>>s;
 int c=0;
 int x=s.size();
 if(x%2!=0)
 {
     cout<<"No"<<endl;
     return 0;
 }
 else
 {
     c=x/2;
 }
 int k=0;
 for(int i=0;i<s.size();i+=2)
 {
     if(s[i]=='h'&&s[i+1]=='i')
      k++;
      else
      {
          cout<<"No"<<endl;
          return 0;
      }
 }
 cout<<"Yes"<<endl;
}






Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, A;
    cin >> H >> A;

    if (H%A == 0) {
        cout << H/A << endl;
    } else {
        cout << H/A+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
try:
    A, B = map(int, input().split())
    B_ = [i for i in range(B+1)] 
    A_ = [j for j in range(A)]
    res = list(set(B_)-set(A_))
    cnt = 0
    for re in res:
        if str(re) == str(re)[::-1]:
            cnt += 1
    print(cnt)
except EOFError:
    pass

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

void f(int n, vector<int> &v){
	if(n==1) return;
	for(int i=2; i<=n; i++){
		if(n%i==0) {
			v.push_back(i);
			f(n/i,v);
			break;
		}
	}
	
}

bool hantei(long x){
	
	int i=2;
	while(1){
		if (x==1) return 0;
		if (i==x) return 1;
		if (x % i == 0) return 0;
		else {
			if(x < i*i) return 1;
			else i++;
		}
	}
}

int main() {
	vector<int> v;
	int n;
	cin >> n;
	if(!hantei(n))f(n,v);
	else v.push_back(n);
	cout << n << ':';
	for(auto i:v) cout << ' ' << i; 
	cout << endl;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int N,i,a=0,b=0,c=0,d=0;
    cin>>N;
    string s;
    for(i=0;i<N;i++)
    {
       cin>>s;
       if(s=="AC")
       a++;
       if(s=="WA")
       b++;
       if(s=="TLE")
       c++;
       if(s=="RE")
       d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
map<int64_t, int> prime_factor(int64_t n)
{
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}
int main()
{
    ll n;
    cin >> n;
    map<int64_t, int> count = prime_factor(n);
    ll ans = 0;
    if (primejudge(n))
    {
        putout(1);
        return 0;
    }
    loop(i, 1000003)
    {
        ll now = i + 1;
        if (primejudge(now))
        {
            ll c = count[now];
          n/=pow(now,c);
            if (c > 0)
            {
                ll w = 1;
                while (c > 0)
                {
                    if (c >= w)
                    {
                        ans++;
                        c -= w;
                        w++;
                        continue;
                    }
                    else
                        break;
                }
            }
        }
    }
  if(primejudge(n))ans++;
    putout(ans);
    return 0;
}


Measured memory_bytes: 9016
#include <stdio.h>
#include <limits.h>

int main(void)
{
    int a, max1, max2, max3, temp;

    max1 = max2 = max3 = INT_MIN;
    while(~scanf("%d", &a)) {
        if(a > max3) {
            max3 = a;

            /* 排序 */
            if(max3 > max1) {
                temp = max3;
                max3 = max2;
                max2= max1;
                max1 = temp;
            } else if(max3 > max2) {
                temp = max3;
                max3 = max2;
                max2 = temp;
            }
        }
    }

    printf("%d\n%d\n%d\n", max1, max2, max3);

    return 0;
}



Measured memory_bytes: 2592
def main():
    n, a, b = map(int, input().split())
    mod = 10**9+7

    nn = n
    ans1 = 1
    while a > 0:
        ans1 = (ans1 * n * pow(a, mod-2, mod)) % mod
        n -= 1
        a -= 1

    ans2 = 1
    n = nn
    while b > 0:
        ans2 = (ans2 * n * pow(b, mod-2, mod)) % mod
        n -= 1
        b -= 1

    print((pow(2, nn)-ans1-ans2-1) % mod)


main()

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

using namespace std;

int main() {
    int n;
    cin>>n;
    long double probs[n+1];
    for (int i=1; i<=n; i++)
        cin>>probs[i];
    long double dp[n+1][n+1] = {0.0};

    dp[1][0] = 1.0-probs[1];
    dp[1][1] = probs[1];

    for (int i=2; i<=n; i++) {
        dp[i][0] = dp[i-1][0]*(1.0-probs[i]);
        for (int j=1; j<=i; j++) {
            dp[i][j] = dp[i-1][j]*(1.0-probs[i]) + dp[i-1][j-1]*probs[i];
        }
    }

    long double res = 0.0;
    for (int j=n; j>n/2; j--) {
        res += dp[n][j];
    }

    cout<<setprecision(12)<<res<<endl;
    return 0;
}

Measured memory_bytes: 140928
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> red(h, string(w, '.')), blue(h, string(w, '.'));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            char c; cin >> c;
            if (c == '#') {
                red[i][j] = blue[i][j] = '#';
            }
            else if ((j < w-1 && i % 2 == 0) || j == 0) {
                red[i][j] = '#';
                blue[i][j] = '.';
            }
            else {
                red[i][j] = '.';
                blue[i][j] = '#';
            }
        }
    }
    for (auto r:red) cout << r << endl;
    cout << endl;
    for (auto b:blue) cout << b << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		int N = scan.nextInt();
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		int Max = 0;
		for (int i = 1; i < N; i++) {
			Max = Math.max(A[i] - A[i-1], Max);
		}
		Max = Math.max( K - (A[N-1] - A[0]), Max);

		System.out.println(K - Max);
	}
}


Measured memory_bytes: 80664
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int x,y;

main(){
    cin>>x>>y;
    cout<<(x%y==0?-1:x*MOD)<<endl;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc147_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var s = CIn.Read().ToCharArray();
      var sl = s.Length;

      var ans = 0;

      for (var i = 0; i < sl / 2; i++)
      {
        if (s[i] != s[sl - 1 - i]) ans++;
      }

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}

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

int main()
{
    string str;
    cin >> str;
    int l = str.length();
    int res = 0;
    for (int i = 0; i<l; i++){
        if (str[i] != str[l-1-i]) {
            res++;
        }
    }
    res = (res + 1) /2;
    cout << res;
}

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

int main(void){
    int a,n,i,min=1000000,max=-1000000;
    long int sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum+=a;
        if(min >a) min=a;
        if(max <a) max=a;
    }
    printf("%d %d %ld\n",min, max, sum);
    return 0;
}


Measured memory_bytes: 2084
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

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

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%MOD;
        a=a*a%MOD;
        x>>=1;
    }
    return res;
}
string s;
int g(int i){
    if(i<0) return 0;
    if(i==0) return 1;
    if(i==1&&s[1]==s[0]) return 1;

}
int main(){
    ll n,m,d;
    cin>>n>>m>>d;
    if(d==0){
        printf("%.10f\n",(double)(m-1)/(double)n);
    }else{
        printf("%.10f\n",(double)(2*(n-d)*(m-1))/(double)(n*n));
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb(a)            push_back(a)
#define ll               long long
#define ld               long double
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
long double eps=10e-9;

int main()
{
    ld w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<(w*h)/2<<" "<<(x+x==w&&y+y==h)<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;

ull n, k, a[100005] = {0}, b[100005] = {0}, t = 0;
ull memo[70] = {0};

ull solve(ull x);

int main() {
  cin >> n >> k;
  for(ull i = 0; i < n; ++i) cin >> a[i] >> b[i];
  memo[0] = 1;
  for(ull i = 1; i < 64; ++i) memo[i] = 2 * memo[i - 1];
  if(k == 0) {
    for(ull i = 0; i < n; ++i) {
      if(a[i] == 0) t += b[i];
    }
    cout << t << endl;
    return 0;
  }
  while(memo[t] <= k) ++t;
  --t;
  cout << solve(t) << endl;
  return 0;
}

// decided x ~ t
ull solve(ull x) {
  if(x > t) return 0;
  ull ans = 0, now = 0;
  for(ull i = 0; i < n; ++i)
    if((k | a[i]) == k) now += b[i];
  for(ull i = 0; i < n; ++i) {
    if(k >= memo[x] && memo[x] > a[i])
      ans += b[i];
    else if(k >= memo[x] && a[i] >= memo[x])
      a[i] -= memo[x];
  }
  if(k >= memo[x]) k -= memo[x];
  ans = max(ans, now);
  now = solve(x - 1);
  return max(ans, now);
}

Measured memory_bytes: 1792
import copy
N = int(input())
X = list(map(int,input().split()))

B = []
l = N // 2
r = (N//2)+1
Y = copy.copy(X)
Y.sort()
chu = Y[N//2-1]
tyu = Y[N//2]

for i in range(N):
    if X[i]<=chu:
        B.append(tyu)
    else:
        B.append(chu)

for i in range(len(B)):
    print(B[i])


Measured memory_bytes: 25656
#include <bits/stdc++.h>
using namespace std;
#define M0D 1000000007

int main(){

  int ans=0;
  string S;
  cin >> S;
  for(int i=0; i<S.size()/2; i++) if(S[i]!=S[S.size()-i-1]) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
while True:
  H, W = map(int, input().split())
  for i in range(H):
    for j in range(W):
      if i == 0 or i == H - 1 or j == 0 or j == W - 1:
        print("#", end ="")
      else:
        print(".", end ="")
    print()
  if H == 0 and W == 0:
    break

  print()


Measured memory_bytes: 7000
#include <stdio.h>
int main(void){
  int n,y;
  scanf("%d %d",&n,&y);
  int i,j,k;
  for(i=0;i<=n;i++){
    for(j=0;j<=n-i;j++){
      for(k=0;k<=n-i-j;k++){
        if(10000*i+5000*j+1000*k==y&&i+j+k==n) {
          printf("%d %d %d",i,j,k);
          return 0;
        }
      }
    }
  }
  printf("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool flag = false;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec[i][j];
    }
  }
  
  for(int i=0; i<N-2; i++){
    if(vec[i][0] == vec[i][1] && vec[i+1][0] == vec[i+1][1] && vec[i+2][0] == vec[i+2][1]){
      flag = true;
    }
  }
  
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
while True:
    table = input().split()
    a=int(table[0])
    op=table[1]
    b=int(table[2])
    if op=='?':
        break
    if op=='+':
        print(a+b)
    if op=='-':
        print(a-b)
    if op=='/':
        print(a//b)
    if op=='*':
        print(a*b)


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())


using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin>>n;
    ll ans = 0;
    for1(i, n-1){
        ans += (n - 1) / i;
    }
    cout<<ans<<endl;
}



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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;rep(tcs,1,tt+1)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n)cin>>a[i];
    sort(all(a));
    ll cnt=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]<a[j]&&a[j]<a[k]){
                    if(a[k]<a[i]+a[j])
                        cnt++;
                }
            }
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
from collections import defaultdict
from bisect import bisect
def inpl(): return list(map(int, input().split()))

def primes(N):
    sieve = [True]*(N+1)
    sieve[:2] = [False, False]
    for i in range(4, N+1, 2):
        sieve[i] = False

    for i in range(3, N+1, 2):
        if sieve:
            for j in range(2*i, N+1, i):
                sieve[j] = False
    P = []
    for i in range(N+1):
        if sieve[i]:
            P.append(i)
    return P

N, M = inpl()
P = primes(10**6)
searched = defaultdict(int)

Q = [1]

if N==1:
    print(M)
    exit()

if M%N == 0:
    ans = M//N
else:
    ans = 1
while Q:
    a = Q.pop()
    for p in P:
        c = a*p
        d = M - c*N
        if d < 0:
            break
        
        if d%c == 0:
            if not searched[c]:
                searched[c] = True
                ans = max(ans, c)
                Q.append(c)
print(ans)

Measured memory_bytes: 54876
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct p
{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1,tail,n;

void enqueue(P x)
  {
    Q[tail]=x;
    if(tail==LEN+1)
      tail=0;
    else 
      tail++;
  }
  

P dequeue()
{
  P x;
  x=Q[head];
  if(head==LEN+1)
    head=0;
  else 
    head++;
  
  return x;
}





main()
{
  int i,q;
  int sum=0;
  scanf("%d %d",&n,&q);
  
  for(i=1;i<=n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
}
  tail=i;

  while(head != tail)
    {
      if(Q[head].t>q)
	{
	  sum+=q;
	  Q[head].t-=q;
	  enqueue(dequeue(Q[head]));
	}
      else 
	{
	  sum+=Q[head].t;
	  printf("%s %d\n",Q[head].name,sum);
	  dequeue(Q[head]);
	}
    }
   return 0;
}  
  

  

Measured memory_bytes: 10756
import math
l, r = map(int, input().split())

if r - l > 2017:
    print("0")
else:
    c = 2019
    for i in range(r-l):
        a = (l + i) % 2019
        for j in range(r-l-i):
            b = (l + i + j + 1) % 2019
            if (a * b) % 2019 < c:
                c = (a * b) % 2019
    print(c)
            










                                        




    




        


    







        



Measured memory_bytes: 3060
S = list(input())

curr = S[0]
count = 0
for i in range(1, len(S)):
    if curr == S[i]:
        if curr == '0':
            S[i] = '1'
        else:
            S[i] = '0'
        count = count + 1
    curr = S[i]

print(count)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
inline ll read()
{
    ll x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
ll n,k,a[N],b[N];
bool check(ll x)
{
	ll t=k;
	for(int i=1;i<=n;i++){
		t-=max(0ll, a[i]-x/b[i]);
		if(t<0) return 0;
	}
	return 1;
}
int main()
{
	n=read(); k=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	sort(a+1, a+n+1); sort(b+1, b+n+1, greater<ll>());
	ll l=0,r=1e12,mid,ans=r;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid)) r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

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


using Graph = vector<vector<int>>; // グラフ

int main() {
  int n, m;
  cin >> n >> m;
  Graph G(n);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--, b--;
    if(a == 0 || b == 0 || a == n-1 || b == n-1){
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }
  if(G[0].size() == 0 || G[n-1].size() == 0){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  for(auto i : G[0]){
    for(auto j : G[i]){
      if(j == n-1){
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12016
import java.util.Scanner;

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

        int count = 0;

        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i)=='1'){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23764
#ifdef _WIN32
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#define DEBUGBREAK() ::DebugBreak()
#else
#define DEBUGBREAK() static_cast<void>(0)
#endif

#include <iostream>
#include <sstream>
#include <iomanip>
#include <valarray>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <array>
#include <functional>
#include <stack>
#include <bitset>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int64_t dx4[4] = { 0, -1, 1, 0 };
const int64_t dy4[4] = { -1, 0, 0, 1 };
const int64_t dx5[5] = { 0, -1, 0, 1, 0 };
const int64_t dy5[5] = { -1, 0, 0, 0, 1 };
const int64_t dx8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int64_t dy8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int64_t dx9[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
const int64_t dy9[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

#define REP(i, K) for (int64_t i = 0; i < K; ++i)
#define REPYX() for (int64_t y = 0; y < H; ++y) for (int64_t x = 0; x < W; ++x)
#define REPX() REP(x, W)
#define REPY() REP(y, H)
#define INSIDE(x_, y_) (0 <= (x_) && 0 <= (y_) && (x_) < W && (y_) < H)
#define INSIDE_MARGIN(x_, y_, m_) ((m_) <= (x_) && (m_) <= (y_) && (x_) < W - (m_) && (y_) < H - (m_))
#define ALL(v) (v).begin(), (v).end()

int get_assert_level() {
    const char* s = getenv("ASSERT_LEVEL");
    if (s) { return atoi(s); }
    return 0;
}
static int g_assert_level = get_assert_level();

#define LV_1() if (g_assert_level >= 1)
#define LV_2() if (g_assert_level >= 2)
#define LV_3() if (g_assert_level >= 3)
#define ASSERT_1(expr) do { const bool b = bool(expr); if (g_assert_level >= 1 && !b) { std::cerr << "[ASSERT 1] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_2(expr) do { const bool b = bool(expr); if (g_assert_level >= 2 && !b) { std::cerr << "[ASSERT 2] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_3(expr) do { const bool b = bool(expr); if (g_assert_level >= 3 && !b) { std::cerr << "[ASSERT 3] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)

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

    int N, K;
    cin >> N >> K;

    vector<int> Ps(N);
    REP(i, N) cin >> Ps[i];
    sort(ALL(Ps));

    const int sum = accumulate(Ps.begin(), Ps.begin() + K, 0);
    cout << sum << endl;

    return 0;
}



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

using namespace std;

int main(int argc, char const *argv[]) {
  int n,k,ans=0;
  cin >> n >> k;
  int* bou = new int[n];
  for (int i = 0; i < n; i++) {
    cin >>bou[i];
  }
  sort(bou,bou+n);

  for (int i = 0; i < k; i++) {
    ans += bou[n-1-i];
  }
  cout << ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int num = Integer.parseInt(sc.next());
  int[] array = new int[num];
  String ans = "YES";
  for (int i = 0; i < num; i++){
  array[i] = Integer.parseInt(sc.next());
  }
  Arrays.sort(array);
  for (int i = 1; i <num; i++){
  	if(array[i-1] == array[i]){
    ans = "NO";
    }
  }
  System.out.println(ans);
}
}

Measured memory_bytes: 51012
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


#define rep(i,r,l) for(int i = r; i < l; i++)
#define elif else if
#define ll long long

int nextint(void){ll int n;scanf("%lld",&n);return n;}
void printint(ll int d){printf("%lld\n",d);}


int main(void){ 

    ll d,n;
    int count=0;

    scanf("%lld %lld",&n,&d);

    ll x ,y;
    rep(i,0,n){
        scanf("%lld %lld",&x,&y);
        if(x*x+y*y<=d*d)count++;
    }
    printint(count);

    return 0;
}



Measured memory_bytes: 1736
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define lint long long
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
#define N 200010
using namespace std;
int a[N];
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
inline int gabs(int x) { return x<0?-x:x; }
int main()
{
	int n=inn();
	for(int i=1;i<=n;i++) a[i]=inn();
	sort(a+1,a+n+1);int k=a[n]/2,ans=a[1];
	for(int i=2;i<n;i++)
		if(a[n]&1)
		{
			if(min(gabs(ans-k),gabs(ans-k-1))>min(gabs(a[i]-k),gabs(a[i]-k-1))) ans=a[i];
		}
		else if(gabs(ans-k)>gabs(a[i]-k)) ans=a[i];
	return swap(ans,a[n]),!printf("%d %d\n",ans,a[n]);
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=10000;
int dp[maxn][maxn];
int main()
{
	char s[maxn],t[maxn],a[maxn];
	cin>>s+1>>t+1;
	for(int i=1;i<=strlen(s+1);i++)
	{
		for(int j=1;j<=strlen(t+1);j++)
		{
			if(s[i]==t[j])
			dp[i][j]=dp[i-1][j-1]+1;
			else
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int l,r,k=0;
	for(l=strlen(s+1),r=strlen(t+1);l>=1&&r>=1;)
	{
		if(s[l]==t[r])
		{
			a[k++]=s[l];
			l--;
			r--;
		}
		else if(dp[l][r]==dp[l-1][r])
		{
			l--;
		}
		else
		{
			r--;
		}
	}
	for(int i=strlen(a)-1;i>=0;i--)
	cout<<a[i];
	return 0;
}

Measured memory_bytes: 50808
//https://beta.atcoder.jp/contests/abc081/tasks/abc081_a
#include<iostream>
#include<string>

using namespace std;

int main(){
    int cnt = 0;
    string s;
    
    cin >> s;
    
    if(s[0] == '1') cnt++;
    if(s[1] == '1') cnt++;
    if(s[2] == '1') cnt++;

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	cout << (a-1) * (b-1) << endl;
	return 0;
}

Measured memory_bytes: 384
c,t,d[4010][4010];char s[4010];i;main(j){gets(s);for(**d=1;s[i/2];i++)for(j=c+=s[i]?t+=2,s[i]-48:0;j>i+c-t&&~j;j--)d[i+1][j]=(d[i][j]+d[i][j-1])%998244353;printf("%d",d[i][c]);}

Measured memory_bytes: 60416
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    string s;
    int n;
    cin >> s;
    n = s.size();
    rep(i, n) {
        if(s[i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    string t = s.substr(0, n / 2);
    rep(i, t.size()) {
        if(t[i] != t[t.size() - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> left(n);
    vector<int> right(n);
    REP(i, n - 1) {
        cin >> left[i] >> right[i];
        left[i]--;
        right[i]--;
    }
    vector<long long> depth(n);
    REP(i, n - 1){
        int a = left[i];
        int b = right[i];
        depth[a] = depth[i] + 1LL;
        depth[b] = depth[i] + 1LL;
    }
    vector<long long> cnt(n, 1);
    for(int i = n - 2; i >= 0; i--) {
        int a = left[i];
        int b = right[i];
        cnt[i] = cnt[a] + cnt[b];
    }
    vector<long long> dp1(n, 0);
    vector<long long> dp2(n, 0);
    for(int i = n - 2; i >= 0; i--) {
        int a = left[i];
        int b = right[i];
        long long d = depth[i];
        dp1[i] = min(2LL + min(dp2[a] - d * (cnt[a] - 1) + dp1[b], dp1[a] + dp2[b] - d * (cnt[b] - 1)), d + 2LL + dp1[a] + dp1[b]);
        dp2[i] = d + 2LL + dp2[a] + dp2[b];
        // printf("%d: %d %d d = %d\n", i, dp1[i], dp2[i], depth[i]);
    }
    cout << min(dp1[0], dp2[0]) << endl;
    return 0;
}

Measured memory_bytes: 20600
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<int> A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N;
  cin >> K;
  A.resize(N);
  rep(i, 0, N - 1) { cin >> A[i]; };
}
void solve() {
  int ans = 0;
  for (auto x : A) {
    ans += min(x * 2, (K - x) * 2);
  }
  cout << ans << endl;

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n=int(input())
    *a,=map(int,input().split())
    *b,=map(int,input().split())
    *c,=map(int,input().split())
    t=sum(b)
    for i in range(len(a)-1):
        if a[i]+1==a[i+1]:
            t+=c[a[i]-1]
    print(t)

            
if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

struct shop {
    ll a,b;
    shop(ll a, ll b):a(a),b(b){}
    bool operator<(const shop &s){
        return s.a*(b+1)<a*(s.b+1);
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,t; cin>>n>>t;
    vector<shop> s;
    vll zero;
    rep(i,n){
        ll a,b; cin>>a>>b;
        if (a==0) zero.pb(b+1);
        else s.pb(shop(a,b));
    }
    sort(all(s));
    sort(all(zero));
    vll dp(31,t+1);
    dp[0] = 0;
    rep(i,s.size())RFOR(j,30,1){
        if ((dp[j-1]+1)*(s[i].a+1)+s[i].b>t) continue;
        chmin(dp[j], (dp[j-1]+1)*(s[i].a+1)+s[i].b);
    }
    int ans=0;
    rep(i,30)if(dp[i]<=t){
        ll extra=t-dp[i];
        int idx=0;
        while(idx<zero.size() && extra>=zero[idx]) extra-=zero[idx++];
        chmax(ans,i+idx);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a, p, q, r;
  cin >> a;
  p = a / 100;
  q = ( a - 100 * p ) / 10;
  r = a - 100 * p - 10 * q;
  cout << p + q + r << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define double long double
#define f first
#define ss second
#define mp make_pair
#define pb push_back

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).

#define mod 1000000007
#define INF 1000000000
#define setitr set <int, greater <int> > :: iterator
#define RE(i,n) for(int i=1; i<=n; i++)
#define REP(i,j,n) for(int i=j; i<=n; i++)
#define REB(i,j,n) for(int i=j; i>=n; i--)
#define FO(i,n) for(int i=n; i>0; i--)

const int N = 2e5+5;
vii graph(N);
ll t[4*N], tin[N], tout[N], tx=0;
ll order[N], cnt[N]={0};

void dfs(int v, int p)
{
    order[tx++] = v;
    tin[v] = tx-1;
    REP(i,0,graph[v].size()-1)
    {
        int u = graph[v][i];
        if(u==p) continue;
        dfs(u,v);
    }
    tout[v] = tx-1;
}

void build(ll a[], int v, int tl, int tr)
{
    if(tl==tr)
        t[v] = a[tl];
    else
    {
        int tm = (tl+tr)/2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = t[2*v] + t[2*v+1];
    }
}

void update(int v, int tl, int tr, int l, int r, int add)
{
    if(l>r) return;
    if(tl==l && tr==r)
        t[v]+=add;
    else
    {
        int tm = (tl+tr)/2;
        update(v*2, tl, tm, l, min(tm,r), add);
        update(2*v+1, tm+1, tr, max(l,tm+1),r, add);
    }
}

ll get(int v, int tl, int tr, int pos)
{
    if(tl==tr)
        return t[v];
    int tm = (tl+tr)/2;
    if(pos<=tm)
        return t[v] + get(2*v, tl, tm, pos);
    else
        return t[v] + get(2*v+1, tm+1, tr, pos);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int n,i,j,q,k,m;
    cin >> n >> q;
    RE(i,n-1)
    {
        cin >> j >> k;
        graph[j].pb(k);
        graph[k].pb(j);
    }
    dfs(1,-1);
    build(cnt, 1, 0, n-1);
    //RE(i,n) cout << order[i-1] << " "; cout << "\n";
    //RE(i,n) cout << tin[i] << " " << tout[i] << "\n";
    while(q--)
    {
        int a, b;
        cin >> a >> b;
        update(1, 0, n-1, tin[a], tout[a], b);
    }
    ll ans[N];
    RE(i,n)
    {
        ans[order[i-1]] = get(1, 0, n-1, i-1);
    }
    RE(i,n) cout << ans[i] <<  " "; cout << "\n";
    return 0;
}


Measured memory_bytes: 35072
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+1) for _ in range(n)]
for i in range(n):
    for j in range(w+1):
        if j >= wv[i][0]:
            dp[i][j] = max(dp[i-1][j], wv[i][1] + dp[i-1][j-wv[i][0]])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])

Measured memory_bytes: 120172